Java Code Examples for com.helger.commons.collection.impl.ICommonsOrderedMap#put()

The following examples show how to use com.helger.commons.collection.impl.ICommonsOrderedMap#put() . 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
Source File: JsonWriterTest.java    From ph-commons with 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 2
Source File: JsonWriterTest.java    From ph-commons with 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 3
Source File: JsonConverterTest.java    From ph-commons with 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 4
Source File: XMLResourceBundle.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static ICommonsOrderedMap <String, String> readFromPropertiesXML (@Nonnull @WillClose final InputStream aIS)
{
  final ICommonsOrderedMap <String, String> ret = new CommonsLinkedHashMap <> ();
  final IMicroDocument aDoc = MicroReader.readMicroXML (aIS);
  if (aDoc != null)
    for (final IMicroElement eChild : aDoc.getDocumentElement ().getAllChildElements ("entry"))
      ret.put (eChild.getAttributeValue ("key"), eChild.getTextContent ());
  return ret;
}
 
Example 5
Source File: JsonObject.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public ICommonsOrderedMap <String, IJson> getClonedValues ()
{
  final ICommonsOrderedMap <String, IJson> ret = new CommonsLinkedHashMap <> ();
  for (final Map.Entry <String, IJson> aEntry : m_aValues.entrySet ())
    ret.put (aEntry.getKey (), aEntry.getValue ().getClone ());
  return ret;
}
 
Example 6
Source File: BenchmarkStringMultiReplace.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
public void run ()
{
  final ICommonsOrderedMap <String, String> aMap = new CommonsLinkedHashMap <> ();
  for (int i = 0; i < RSRC.length; ++i)
    aMap.put (RSRC[i], RDST[i]);

  String s = "";
  for (int i = 0; i < m_nRuns; i++)
    s = StringHelper.replaceMultiple (SRC, aMap);
  if (!s.equals (DST))
    throw new IllegalStateException (s);
}
 
Example 7
Source File: PSPhase.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public ICommonsOrderedMap <String, String> getAllLetsAsMap ()
{
  final ICommonsOrderedMap <String, String> ret = new CommonsLinkedHashMap <> ();
  for (final Object aElement : m_aContent)
    if (aElement instanceof PSLet)
    {
      final PSLet aLet = (PSLet) aElement;
      ret.put (aLet.getName (), aLet.getValue ());
    }
  return ret;
}
 
Example 8
Source File: PSSchema.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public ICommonsOrderedMap <String, String> getAllLetsAsMap ()
{
  final ICommonsOrderedMap <String, String> ret = new CommonsLinkedHashMap <> ();
  for (final PSLet aLet : m_aLets)
    ret.put (aLet.getName (), aLet.getValue ());
  return ret;
}
 
Example 9
Source File: PSPattern.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public ICommonsOrderedMap <String, String> getAllLetsAsMap ()
{
  final ICommonsOrderedMap <String, String> ret = new CommonsLinkedHashMap <> ();
  for (final Object aContent : m_aContent)
    if (aContent instanceof PSLet)
    {
      final PSLet aLet = (PSLet) aContent;
      ret.put (aLet.getName (), aLet.getValue ());
    }
  return ret;
}
 
Example 10
Source File: PSRule.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public ICommonsOrderedMap <String, String> getAllLetsAsMap ()
{
  final ICommonsOrderedMap <String, String> ret = new CommonsLinkedHashMap <> ();
  for (final Object aContent : m_aContent)
    if (aContent instanceof PSLet)
    {
      final PSLet aLet = (PSLet) aContent;
      ret.put (aLet.getName (), aLet.getValue ());
    }
  return ret;
}
 
Example 11
Source File: MainReadAllCSSOnDisc.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@SuppressFBWarnings ("DMI_HARDCODED_ABSOLUTE_FILENAME")
public static void main (final String [] args)
{
  int nFilesOK = 0;
  int nFilesError = 0;
  final ICommonsOrderedMap <File, ParseException> aErrors = new CommonsLinkedHashMap<> ();
  final Wrapper <File> aCurrentFile = new Wrapper<> ();
  final ICSSParseExceptionCallback aHdl = ex -> aErrors.put (aCurrentFile.get (), ex);
  for (final File aFile : new FileSystemRecursiveIterator (new File ("/")).withFilter (IFileFilter.filenameEndsWith (".css")))
  {
    if (false)
      LOGGER.info (aFile.getAbsolutePath ());
    aCurrentFile.set (aFile);
    final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, StandardCharsets.UTF_8, ECSSVersion.CSS30, aHdl);
    if (aCSS == null)
    {
      nFilesError++;
      LOGGER.warn ("  " + aFile.getAbsolutePath () + " failed!");
    }
    else
      nFilesOK++;
  }

  LOGGER.info ("Done");
  for (final Map.Entry <File, ParseException> aEntry : aErrors.entrySet ())
    LOGGER.info ("  " + aEntry.getKey ().getAbsolutePath () + ":\n" + aEntry.getValue ().getMessage () + "\n");
  LOGGER.info ("OK: " + nFilesOK + "; Error: " + nFilesError);
}
 
Example 12
Source File: DateTimeTypeConverterRegistrarTest.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Test
public void testConvertIntoEachOther ()
{
  final ICommonsOrderedMap <Class <?>, Object> aValues = new CommonsLinkedHashMap <> ();
  aValues.put (Date.class, new Date ());
  aValues.put (Calendar.class, PDTFactory.createCalendar ());
  aValues.put (GregorianCalendar.class, PDTFactory.createGregorianCalendar ());
  aValues.put (ZonedDateTime.class, PDTFactory.getCurrentZonedDateTime ());
  aValues.put (OffsetDateTime.class, PDTFactory.getCurrentOffsetDateTime ());
  aValues.put (LocalDateTime.class, PDTFactory.getCurrentLocalDateTime ());
  aValues.put (LocalDate.class, PDTFactory.getCurrentLocalDate ());
  aValues.put (LocalTime.class, PDTFactory.getCurrentLocalTime ());
  aValues.put (YearMonth.class, PDTFactory.getCurrentYearMonth ());
  aValues.put (Year.class, PDTFactory.getCurrentYearObj ());
  aValues.put (Instant.class, PDTFactory.getCurrentInstant ());

  for (final Map.Entry <Class <?>, Object> aSrc : aValues.entrySet ())
  {
    // Convert to String and back
    final String s = TypeConverter.convert (aSrc.getValue (), String.class);
    assertNotNull (s);
    final Object aSrcValue2 = TypeConverter.convert (s, aSrc.getKey ());
    assertNotNull (aSrcValue2);
    assertEquals ("Difference after reading from: " + s, aSrc.getValue (), aSrcValue2);

    // COnvert to any other type
    for (final Class <?> aDst : aValues.keySet ())
      if (aSrc.getKey () != aDst)
      {
        final boolean bIsTime = aSrc.getKey () == LocalTime.class || aDst == LocalTime.class;
        if (bIsTime &&
            (aSrc.getKey () == LocalDate.class ||
             aDst == LocalDate.class ||
             aSrc.getKey () == YearMonth.class ||
             aDst == YearMonth.class ||
             aSrc.getKey () == Year.class ||
             aDst == Year.class))
        {
          // Not convertible
        }
        else
        {
          if (LOGGER.isDebugEnabled ())
            LOGGER.debug ("Converting from " + aSrc.getKey ().getName () + " to " + aDst.getName ());
          final Object aDstValue = TypeConverter.convert (aSrc.getValue (), aDst);
          assertNotNull (aDstValue);
        }
      }
  }
}