Java Code Examples for com.helger.commons.collection.impl.CommonsHashMap

The following examples show how to use com.helger.commons.collection.impl.CommonsHashMap. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void testBasic ()
{
  final MultiConfigurationValueProvider aMCSVP = new MultiConfigurationValueProvider ();

  // Lower priority
  final ICommonsMap <String, String> aMap1 = new CommonsHashMap <> ();
  aMap1.put ("key1", "value1");
  aMap1.put ("key2", "value2");
  aMCSVP.addConfigurationSource (new ConfigurationSourceFunction (110, aMap1::get));

  // Higher priority - should be returned
  final ICommonsMap <String, String> aMap2 = new CommonsHashMap <> ();
  aMap2.put ("key1", "value2");
  aMap2.put ("key3", "value3");
  aMCSVP.addConfigurationSource (new ConfigurationSourceFunction (111, aMap2::get));

  // Resolve
  assertEquals ("value2", aMCSVP.getConfigurationValue ("key1").getValue ());
  assertEquals ("value2", aMCSVP.getConfigurationValue ("key2").getValue ());
  assertEquals ("value3", aMCSVP.getConfigurationValue ("key3").getValue ());
  assertNull (aMCSVP.getConfigurationValue ("key4"));
}
 
Example 2
Source Project: ph-commons   Source File: XMLMapHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testReadBuildInfo ()
{
  final ICommonsMap <String, String> aMap = new CommonsHashMap <> ();
  final IReadableResource aRes = new ClassPathResource ("xml/buildinfo.xml");
  assertTrue (XMLMapHandler.readMap (aRes, aMap).isSuccess ());
  assertNull (XMLMapHandler.readMap (new ClassPathResource ("test1.txt")));
  assertTrue (aMap.containsKey ("buildinfo.version"));
  assertEquals ("1", aMap.get ("buildinfo.version"));

  assertTrue (XMLMapHandler.readMap (aRes).containsKey ("buildinfo.version"));
  assertEquals ("1", XMLMapHandler.readMap (aRes).get ("buildinfo.version"));

  assertTrue (XMLMapHandler.writeMap (aMap, new ByteArrayOutputStreamProvider ()).isSuccess ());
  assertTrue (XMLMapHandler.writeMap (aMap, new NonBlockingByteArrayOutputStream ()).isSuccess ());
}
 
Example 3
Source Project: ph-commons   Source File: JsonWriterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMap ()
{
  final ICommonsMap <String, Object> aMap = new CommonsHashMap <> ();
  aMap.put ("foo", "bar");
  assertEquals ("{\"foo\":\"bar\"}", JsonConverter.convertToJson (aMap).getAsJsonString ());

  final ICommonsNavigableMap <String, Object> aTreeMap = new CommonsTreeMap <> ();
  aTreeMap.put ("foo", "bar");
  aTreeMap.put ("foo2", Integer.valueOf (5));
  assertEquals ("{\"foo\":\"bar\",\"foo2\":5}", JsonConverter.convertToJson (aTreeMap).getAsJsonString ());

  final ICommonsOrderedMap <String, Object> aLinkedMap = new CommonsLinkedHashMap <> ();
  aLinkedMap.put ("foo", "bar");
  aLinkedMap.put ("foo2", Integer.valueOf (5));
  assertEquals ("{\"foo\":\"bar\",\"foo2\":5}", JsonConverter.convertToJson (aLinkedMap).getAsJsonString ());
  assertEquals ("{foo:\"bar\",foo2:5}",
                JsonConverter.convertToJson (aLinkedMap).getAsJsonString (new JsonWriterSettings ().setQuoteNames (false)));
}
 
Example 4
Source Project: ph-commons   Source File: JsonWriterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteAndReadMap ()
{
  final ICommonsMap <String, Object> aMap = new CommonsHashMap <> ();
  aMap.put ("foo", "bar");
  _testWriteAndRead (aMap);

  final ICommonsNavigableMap <String, Object> aTreeMap = new CommonsTreeMap <> ();
  aTreeMap.put ("foo", "bar");
  aTreeMap.put ("foo2", Integer.valueOf (5));
  _testWriteAndRead (aTreeMap);

  final ICommonsOrderedMap <String, Object> aLinkedMap = new CommonsLinkedHashMap <> ();
  aLinkedMap.put ("foo", "bar");
  aLinkedMap.put ("foo2", Integer.valueOf (5));
  _testWriteAndRead (aLinkedMap);
}
 
Example 5
Source Project: ph-commons   Source File: JsonConverterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMap ()
{
  final ICommonsMap <String, Object> aMap = new CommonsHashMap <> ();
  aMap.put ("foo", "bar");
  aMap.put ("foo2", Integer.valueOf (5));
  assertTrue (JsonConverter.convertToJson (aMap) instanceof JsonObject);

  final ICommonsNavigableMap <String, Object> aTreeMap = new CommonsTreeMap <> ();
  aTreeMap.put ("foo", "bar");
  aTreeMap.put ("foo2", Integer.valueOf (5));
  assertTrue (JsonConverter.convertToJson (aTreeMap) instanceof JsonObject);

  final ICommonsOrderedMap <String, Object> aLinkedMap = new CommonsLinkedHashMap <> ();
  aLinkedMap.put ("foo", "bar");
  aLinkedMap.put ("foo2", Integer.valueOf (5));
  assertTrue (JsonConverter.convertToJson (aLinkedMap) instanceof JsonObject);
}
 
Example 6
Source Project: ph-commons   Source File: EqualsHashcodeFuncTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMap ()
{
  final ICommonsMap <String, Object> aMap = new CommonsHashMap <> ();
  aMap.put ("foo", "bar");
  _testEqualsHashcode (aMap);

  final ICommonsMap <String, Object> aTreeMap = new CommonsTreeMap <> ();
  aTreeMap.put ("foo", "bar");
  aTreeMap.put ("foo2", Integer.valueOf (5));
  _testEqualsHashcode (aTreeMap);

  final ICommonsMap <String, Object> aLinkedMap = new CommonsLinkedHashMap <> ();
  aLinkedMap.put ("foo", "bar");
  aLinkedMap.put ("foo2", Integer.valueOf (5));
  _testEqualsHashcode (aLinkedMap);
}
 
Example 7
Source Project: ph-commons   Source File: BasicTreeItemWithID.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public final EChange internalAddChild (@Nonnull final KEYTYPE aDataID,
                                       @Nonnull final ITEMTYPE aChild,
                                       final boolean bAllowOverwrite)
{
  ValueEnforcer.notNull (aChild, "Child");

  // Ensure children are present
  if (m_aChildMap != null)
  {
    if (!bAllowOverwrite && m_aChildMap.containsKey (aDataID))
      return EChange.UNCHANGED;
  }
  else
  {
    m_aChildMap = new CommonsHashMap <> ();
    m_aChildren = new CommonsArrayList <> ();
  }

  m_aChildMap.put (aDataID, aChild);
  m_aChildren.add (aChild);
  m_aFactory.onAddItem (aChild);
  return EChange.CHANGED;
}
 
Example 8
Source Project: ph-commons   Source File: CollectionHelper.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
@SafeVarargs
public static <ELEMENTTYPE> CommonsHashMap <ELEMENTTYPE, ELEMENTTYPE> newMap (@Nullable final ELEMENTTYPE... aValues)
{
  if (ArrayHelper.isEmpty (aValues))
    return newMap (0);

  if ((aValues.length % 2) != 0)
    throw new IllegalArgumentException ("The passed array needs an even number of elements!");

  final CommonsHashMap <ELEMENTTYPE, ELEMENTTYPE> ret = newMap (aValues.length / 2);
  for (int i = 0; i < aValues.length; i += 2)
    ret.put (aValues[i], aValues[i + 1]);
  return ret;
}
 
Example 9
Source Project: ph-commons   Source File: CollectionHelper.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static <KEYTYPE, VALUETYPE> CommonsHashMap <KEYTYPE, VALUETYPE> newMap (@Nullable final KEYTYPE [] aKeys,
                                                                               @Nullable final VALUETYPE [] aValues)
{
  final int nKeys = ArrayHelper.getSize (aKeys);
  final int nValues = ArrayHelper.getSize (aValues);

  // Check for identical size
  if (nKeys != nValues)
    throw new IllegalArgumentException ("The passed arrays have different length (" +
                                        nKeys +
                                        " keys and " +
                                        nValues +
                                        " values)!");

  // Are both empty?
  if (nKeys == 0)
    return newMap (0);

  final CommonsHashMap <KEYTYPE, VALUETYPE> ret = newMap (nKeys);
  for (int i = 0; i < aKeys.length; ++i)
    ret.put (aKeys[i], aValues[i]);
  return ret;
}
 
Example 10
Source Project: ph-commons   Source File: StringHelperTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testReplaceMultipleMap ()
{
  final ICommonsMap <String, String> aMap = new CommonsHashMap <> ();
  aMap.put ("Hallo", "Hi");
  aMap.put ("Welt", "world");
  aMap.put ("!", "???");
  assertEquals ("Abc die Katze lief im Schnee", StringHelper.replaceMultiple ("Abc die Katze lief im Schnee", aMap));
  assertEquals ("Hi Katze", StringHelper.replaceMultiple ("Hallo Katze", aMap));
  assertEquals ("Moin world", StringHelper.replaceMultiple ("Moin Welt", aMap));
  assertEquals ("Moin welt", StringHelper.replaceMultiple ("Moin welt", aMap));
  assertEquals ("Hi", StringHelper.replaceMultiple ("Hallo", aMap));
  assertEquals ("Hi Hi", StringHelper.replaceMultiple ("Hallo Hallo", aMap));
  assertEquals ("HiHiHi", StringHelper.replaceMultiple ("HalloHalloHallo", aMap));
  assertEquals ("Hi world???", StringHelper.replaceMultiple ("Hallo Welt!", aMap));
  assertEquals ("Hi world???Hi world???", StringHelper.replaceMultiple ("Hallo Welt!Hallo Welt!", aMap));
}
 
Example 11
Source Project: ph-commons   Source File: EqualsHelperTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMap ()
{
  final StringMap aMap = new StringMap ("a", "b").add ("c", "d");
  assertTrue (EqualsHelper.equalsCollection (aMap, aMap));
  assertTrue (EqualsHelper.equalsCollection (aMap, CollectionHelper.makeUnmodifiable (aMap)));
  assertTrue (EqualsHelper.equalsCollection (aMap, Collections.synchronizedMap (aMap)));
  assertTrue (EqualsHelper.equalsCollection (aMap, new StringMap ("a", "b").add ("c", "d")));
  assertTrue (EqualsHelper.equalsCollection (new CommonsHashMap <Integer, Integer> (), new CommonsHashMap <Double, Float> ()));

  assertFalse (EqualsHelper.equalsCollection (aMap, new CommonsHashMap <Integer, Integer> ()));
  assertFalse (EqualsHelper.equalsCollection (new CommonsHashMap <Integer, Integer> (), aMap));
  assertFalse (EqualsHelper.equalsCollection (aMap, new StringMap ("a", "b")));
  assertFalse (EqualsHelper.equalsCollection (aMap, new StringMap ("A", "b").add ("c", "d")));
  assertFalse (EqualsHelper.equalsCollection (aMap, new StringMap ("a", "B").add ("c", "d")));
  assertFalse (EqualsHelper.equalsCollection (aMap, new StringMap ("a", "b").add ("C", "d")));
  assertFalse (EqualsHelper.equalsCollection (aMap, new StringMap ("a", "b").add ("c", "D")));
  assertFalse (EqualsHelper.equalsCollection (aMap, new StringMap ("a", "b").add ("c", "d").add ("e", "f")));
  assertFalse (EqualsHelper.equalsCollection (aMap, new CommonsArrayList <> ("a", "b", "c")));
  assertFalse (EqualsHelper.equalsCollection (aMap, new CommonsHashSet <> ("a", "b", "c")));
  assertFalse (EqualsHelper.equalsCollection (aMap, ArrayHelper.newArray ("a", "b", "c")));
}
 
Example 12
Source Project: ph-commons   Source File: WSClientConfigTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBasic ()
{
  final WSClientConfig aCfg = new WSClientConfig (URLHelper.getAsURL ("http://www.example.org"));
  final ICommonsMap <String, Object> aMap = new CommonsHashMap <> ();
  final BindingProvider aBP = new MockBP (aMap);
  aCfg.applyWSSettingsToBindingProvider (aBP);
  assertEquals (5, aMap.size ());
  assertEquals ("http://www.example.org", aMap.get (BindingProvider.ENDPOINT_ADDRESS_PROPERTY));
  // 2 versions
  assertEquals (Integer.valueOf (WSClientConfig.DEFAULT_CONNECTION_TIMEOUT_MS),
                aMap.get ("com.sun.xml.ws.connect.timeout"));
  assertEquals (Integer.valueOf (WSClientConfig.DEFAULT_CONNECTION_TIMEOUT_MS),
                aMap.get ("com.sun.xml.internal.ws.connect.timeout"));
  // 2 versions
  assertEquals (Integer.valueOf (WSClientConfig.DEFAULT_REQUEST_TIMEOUT_MS),
                aMap.get ("com.sun.xml.ws.request.timeout"));
  assertEquals (Integer.valueOf (WSClientConfig.DEFAULT_REQUEST_TIMEOUT_MS),
                aMap.get ("com.sun.xml.internal.ws.request.timeout"));
}
 
Example 13
Source Project: ph-schematron   Source File: Schematron2XSLTMojoFuncTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMavenPlugin () throws MojoExecutionException, MojoFailureException
{
  expect (project.getBasedir ()).andReturn (new File (".")).anyTimes ();
  replay (project);

  // Note: default values are not used here
  OUT.setSchematronDirectory (new File ("src/test/resources/schematron"));
  OUT.setSchematronPattern ("**/*.sch");
  OUT.setXsltDirectory (new File ("target/test/schematron-via-maven-plugin"));
  OUT.setXsltExtension (".xslt");

  final ICommonsMap <String, String> aParams = new CommonsHashMap <> ();
  aParams.put ("allow-foreign", "true");
  OUT.setParameters (aParams);

  OUT.execute ();

  verify (project);
}
 
Example 14
Source Project: ph-commons   Source File: MultiHashMapHashMapBased.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
@ReturnsMutableCopy
protected CommonsHashMap <KEYTYPE2, VALUETYPE> createNewInnerMap ()
{
  return new CommonsHashMap <> ();
}
 
Example 15
Source Project: ph-commons   Source File: MultiLinkedHashMapHashMapBased.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
@ReturnsMutableCopy
protected CommonsHashMap <KEYTYPE2, VALUETYPE> createNewInnerMap ()
{
  return new CommonsHashMap <> ();
}
 
Example 16
Source Project: ph-commons   Source File: MultiTreeMapHashMapBased.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
@ReturnsMutableCopy
protected CommonsHashMap <KEYTYPE2, VALUETYPE> createNewInnerMap ()
{
  return new CommonsHashMap <> ();
}
 
Example 17
Source Project: ph-commons   Source File: JAXBContextCacheKey.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Cache key using package and optional class loader
 *
 * @param aClasses
 *        Classes to be used. May not be <code>null</code>.
 * @param aProperties
 *        JAXB context properties. May be <code>null</code>.
 * @since v9.4.2
 */
public JAXBContextCacheKey (@Nonnull final ICommonsList <Class <?>> aClasses,
                            @Nullable final Map <String, ?> aProperties)
{
  ValueEnforcer.notEmptyNoNullValue (aClasses, "Classes");
  m_aPackage = null;
  m_aClassLoader = null;
  m_aClasses = new CommonsArrayList <> (aClasses, WeakReference::new);
  m_aProperties = new CommonsHashMap <> (aProperties);
  m_sEqualsHashCodeKey = StringHelper.getImplodedMapped (':', aClasses, Class::getName);
}
 
Example 18
Source Project: ph-commons   Source File: ConfigFile.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public ICommonsMap <String, Object> getAllEntries ()
{
  if (m_aSettings == null)
    return new CommonsHashMap <> ();
  return m_aSettings.getClone ();
}
 
Example 19
Source Project: ph-commons   Source File: IScope.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return The non-<code>null</code> map with all contained attributes that
 *         implement the {@link IScopeRenewalAware} interface. May be empty.
 */
@Nonnull
@ReturnsMutableCopy
default ICommonsMap <String, IScopeRenewalAware> getAllScopeRenewalAwareAttributes ()
{
  final ICommonsMap <String, IScopeRenewalAware> ret = new CommonsHashMap <> ();
  attrs ().forEach ( (n, v) -> {
    if (v instanceof IScopeRenewalAware)
      ret.put (n, (IScopeRenewalAware) v);
  });
  return ret;
}
 
Example 20
Source Project: ph-commons   Source File: AbstractXMLSerializer.java    License: Apache License 2.0 5 votes vote down vote up
public void addPrefixNamespaceMapping (@Nullable final String sPrefix, @Nonnull final String sNamespaceURI)
{
  if (LOGGER.isTraceEnabled ())
    LOGGER.trace ("Adding namespace mapping " + sPrefix + ":" + sNamespaceURI);

  // namespace prefix uniqueness check
  final String sExistingNamespaceURI = getNamespaceURIOfPrefix (sPrefix);
  if (sExistingNamespaceURI != null && !sExistingNamespaceURI.equals (sNamespaceURI))
    if (LOGGER.isWarnEnabled ())
      LOGGER.warn ("Overwriting namespace prefix '" +
                   sPrefix +
                   "' to use URL '" +
                   sNamespaceURI +
                   "' instead of '" +
                   sExistingNamespaceURI +
                   "'");

  if (StringHelper.hasNoText (sPrefix))
  {
    if (m_sDefaultNamespaceURI != null)
      if (LOGGER.isWarnEnabled ())
        LOGGER.warn ("Overwriting default namespace '" +
                     m_sDefaultNamespaceURI +
                     "' with namespace '" +
                     sNamespaceURI +
                     "'");
    m_sDefaultNamespaceURI = sNamespaceURI;
  }
  else
  {
    if (m_aURL2PrefixMap == null)
      m_aURL2PrefixMap = new CommonsHashMap <> ();
    m_aURL2PrefixMap.put (sNamespaceURI, sPrefix);
  }
}
 
Example 21
Source Project: ph-commons   Source File: XMLMapHandler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Read a mapping from the passed input stream.
 *
 * @param aIS
 *        The input stream to read from. May not be <code>null</code>.
 * @return <code>null</code> if reading the map failed
 */
@Nullable
@ReturnsMutableCopy
public static ICommonsMap <String, String> readMap (@Nonnull @WillClose final InputStream aIS)
{
  final ICommonsMap <String, String> ret = new CommonsHashMap <> ();
  if (readMap (aIS, ret).isFailure ())
    return null;
  return ret;
}
 
Example 22
Source Project: ph-commons   Source File: BasicTreeItemWithID.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
public final ITEMTYPE createChildItem (@Nullable final KEYTYPE aDataID,
                                       @Nullable final DATATYPE aData,
                                       final boolean bAllowOverwrite)
{
  if (!isValidDataID (aDataID))
    throw new IllegalArgumentException ("Illegal data ID provided");

  ITEMTYPE aItem = getChildItemOfDataID (aDataID);
  if (aItem != null)
  {
    // ID already exists
    if (!bAllowOverwrite)
      return null;

    // just change data of existing item
    aItem.setData (aData);
  }
  else
  {
    // create new item
    aItem = m_aFactory.create (_asT (this), aDataID);
    if (aItem == null)
      throw new IllegalStateException ("null item created!");
    aItem.setData (aData);
    if (m_aChildMap == null)
    {
      m_aChildMap = new CommonsHashMap <> ();
      m_aChildren = new CommonsArrayList <> ();
    }
    m_aChildMap.put (aDataID, aItem);
    m_aChildren.add (aItem);
  }
  return aItem;
}
 
Example 23
Source Project: ph-commons   Source File: SerializationConverterRegistry.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Iterate all registered serialization converters. For informational purposes
 * only.
 *
 * @param aCallback
 *        The callback invoked for all iterations.
 */
public void iterateAllRegisteredSerializationConverters (@Nonnull final ISerializationConverterCallback aCallback)
{
  // Create a static (non weak) copy of the map
  final Map <Class <?>, ISerializationConverter <?>> aCopy = m_aRWLock.readLockedGet ( () -> new CommonsHashMap <> (m_aMap));

  // And iterate the copy
  for (final Map.Entry <Class <?>, ISerializationConverter <?>> aEntry : aCopy.entrySet ())
    if (aCallback.call (aEntry.getKey (), aEntry.getValue ()).isBreak ())
      break;
}
 
Example 24
Source Project: ph-commons   Source File: LocaleHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get all possible locale names in the passed locale
 *
 * @param aContentLocale
 *        the locale ID in which the language list is required
 * @return The mapping from the input locale to the display text. The result
 *         map is not ordered.
 */
@Nonnull
@ReturnsMutableCopy
public static ICommonsMap <Locale, String> getAllLocaleDisplayNames (@Nonnull final Locale aContentLocale)
{
  ValueEnforcer.notNull (aContentLocale, "ContentLocale");

  return new CommonsHashMap <> (LocaleCache.getInstance ().getAllLocales (),
                                Function.identity (),
                                aLocale -> getLocaleDisplayName (aLocale, aContentLocale));
}
 
Example 25
Source Project: ph-commons   Source File: PropertiesHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static ICommonsMap <String, String> getAsStringMap (@Nonnull final Properties aProps)
{
  ValueEnforcer.notNull (aProps, "Props");

  final ICommonsMap <String, String> ret = new CommonsHashMap <> ();
  for (final Map.Entry <Object, Object> aEntry : aProps.entrySet ())
    ret.put ((String) aEntry.getKey (), (String) aEntry.getValue ());
  return ret;
}
 
Example 26
Source Project: ph-commons   Source File: TypeConverterRegistry.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Iterate all registered type converters. For informational purposes only.
 *
 * @param aCallback
 *        The callback invoked for all iterations.
 */
public void iterateAllRegisteredTypeConverters (@Nonnull final ITypeConverterCallback aCallback)
{
  // Create a copy of the map
  final Map <Class <?>, Map <Class <?>, ITypeConverter <?, ?>>> aCopy = m_aRWLock.readLockedGet ( () -> new CommonsHashMap <> (m_aConverter));

  // And iterate the copy
  outer: for (final Map.Entry <Class <?>, Map <Class <?>, ITypeConverter <?, ?>>> aSrcEntry : aCopy.entrySet ())
  {
    final Class <?> aSrcClass = aSrcEntry.getKey ();
    for (final Map.Entry <Class <?>, ITypeConverter <?, ?>> aDstEntry : aSrcEntry.getValue ().entrySet ())
      if (aCallback.call (aSrcClass, aDstEntry.getKey (), aDstEntry.getValue ()).isBreak ())
        break outer;
  }
}
 
Example 27
Source Project: ph-commons   Source File: CollectionHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static <SRCKEYTYPE, SRCVALUETYPE, DSTKEYTYPE, DSTVALUETYPE> CommonsHashMap <DSTKEYTYPE, DSTVALUETYPE> newMapMapped (@Nullable final Map <? extends SRCKEYTYPE, ? extends SRCVALUETYPE> aMap,
                                                                                                                           @Nonnull final Function <? super SRCKEYTYPE, ? extends DSTKEYTYPE> aKeyMapper,
                                                                                                                           @Nonnull final Function <? super SRCVALUETYPE, ? extends DSTVALUETYPE> aValueMapper)
{
  if (isEmpty (aMap))
    return newMap (0);
  return new CommonsHashMap <> (aMap, aKeyMapper, aValueMapper);
}
 
Example 28
Source Project: ph-commons   Source File: CollectionHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static <SRCTYPE, DSTKEYTYPE, DSTVALUETYPE> CommonsHashMap <DSTKEYTYPE, DSTVALUETYPE> newMapMapped (@Nullable final Collection <? extends SRCTYPE> aCollection,
                                                                                                          @Nonnull final Function <? super SRCTYPE, ? extends DSTKEYTYPE> aKeyMapper,
                                                                                                          @Nonnull final Function <? super SRCTYPE, ? extends DSTVALUETYPE> aValueMapper)
{
  if (isEmpty (aCollection))
    return newMap (0);
  return new CommonsHashMap <> (aCollection, aKeyMapper, aValueMapper);
}
 
Example 29
Source Project: ph-commons   Source File: CollectionHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static <KEYTYPE, VALUETYPE> CommonsHashMap <KEYTYPE, VALUETYPE> newMap (@Nullable final Map <KEYTYPE, VALUETYPE> aMap,
                                                                               @Nonnull final Predicate <? super Map.Entry <? extends KEYTYPE, ? extends VALUETYPE>> aFilter)
{
  if (isEmpty (aMap))
    return newMap (0);
  final CommonsHashMap <KEYTYPE, VALUETYPE> ret = newMap (aMap.size ());
  ret.putAll (aMap, aFilter);
  return ret;
}
 
Example 30
Source Project: ph-commons   Source File: CollectionHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static <KEYTYPE, VALUETYPE> CommonsHashMap <KEYTYPE, VALUETYPE> newMap (@Nullable final KEYTYPE aKey,
                                                                               @Nullable final VALUETYPE aValue)
{
  final CommonsHashMap <KEYTYPE, VALUETYPE> ret = newMap (1);
  ret.put (aKey, aValue);
  return ret;
}