com.helger.commons.collection.impl.ICommonsNavigableMap Java Examples

The following examples show how to use com.helger.commons.collection.impl.ICommonsNavigableMap. 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: PSXPathQueryBinding.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public ICommonsNavigableMap <String, String> getStringReplacementMap (@Nonnull final List <PSParam> aParams)
{
  final ICommonsNavigableMap <String, String> ret = new CommonsTreeMap <> (IComparator.getComparatorStringLongestFirst ());
  for (final PSParam aParam : aParams)
    ret.put (PARAM_VARIABLE_PREFIX + aParam.getName (), aParam.getValue ());
  return ret;
}
 
Example #5
Source File: IPSXPathVariables.java    From ph-schematron with Apache License 2.0 4 votes vote down vote up
/**
 * @return All contained variable key value pairs. Never <code>null</code>.
 */
@Nonnull
@ReturnsMutableCopy
ICommonsNavigableMap <String, String> getAll ();
 
Example #6
Source File: PSXPathVariables.java    From ph-schematron with Apache License 2.0 4 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
private static ICommonsNavigableMap <String, String> _createMap ()
{
  return new CommonsTreeMap <> (IComparator.getComparatorStringLongestFirst ());
}
 
Example #7
Source File: PSXPathVariables.java    From ph-schematron with Apache License 2.0 4 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public ICommonsNavigableMap <String, String> getAll ()
{
  return m_aMap.getClone ();
}
 
Example #8
Source File: MainCreateJAXBBinding20.java    From ph-ubl with Apache License 2.0 4 votes vote down vote up
private static void _generateExplicitEnumMapping (@Nonnull final IMicroDocument aDoc,
                                                  @Nonnull @Nonempty final String sFilename,
                                                  @Nonnull final IMicroElement eBindings)
{
  final ICommonsSet <String> aUsedNames = new CommonsHashSet <> ();
  final ICommonsNavigableMap <String, String> aValueToConstants = new CommonsTreeMap <> ();
  final IMicroElement eSimpleType = aDoc.getDocumentElement ().getFirstChildElement ();

  final IMicroElement eInnerBindings = eBindings.appendElement (JAXB_NS_URI, "bindings")
                                                .setAttribute ("node",
                                                               "xsd:simpleType[@name='" +
                                                                       eSimpleType.getAttributeValue ("name") +
                                                                       "']");
  final IMicroElement eTypesafeEnumClass = eInnerBindings.appendElement (JAXB_NS_URI, "typesafeEnumClass");

  final IMicroElement eRestriction = eSimpleType.getFirstChildElement ();
  for (final IMicroElement eEnumeration : eRestriction.getAllChildElements (XMLConstants.W3C_XML_SCHEMA_NS_URI,
                                                                            "enumeration"))
  {
    final IMicroElement eAnnotation = eEnumeration.getFirstChildElement (XMLConstants.W3C_XML_SCHEMA_NS_URI,
                                                                         "annotation");
    if (eAnnotation == null)
      throw new IllegalStateException ("annotation is missing");
    final IMicroElement eDocumentation = eAnnotation.getFirstChildElement (XMLConstants.W3C_XML_SCHEMA_NS_URI,
                                                                           "documentation");
    if (eDocumentation == null)
      throw new IllegalStateException ("documentation is missing");
    final IMicroElement eCodeName = eDocumentation.getFirstChildElement ("urn:un:unece:uncefact:documentation:2",
                                                                         "CodeName");
    if (eCodeName == null)
      throw new IllegalStateException ("CodeName is missing");

    final String sValue = eEnumeration.getAttributeValue ("value");
    // Create an upper case Java identifier, without duplicate "_"
    String sCodeName = RegExHelper.getAsIdentifier (eCodeName.getTextContent ().trim ().toUpperCase (Locale.US))
                                  .replaceAll ("_+", "_");

    if (!aUsedNames.add (sCodeName))
    {
      // Ensure uniqueness of the enum member name
      int nSuffix = 1;
      while (true)
      {
        final String sSuffixedCodeName = sCodeName + "_" + nSuffix;
        if (aUsedNames.add (sSuffixedCodeName))
        {
          sCodeName = sSuffixedCodeName;
          break;
        }
        ++nSuffix;
      }
    }

    eTypesafeEnumClass.appendElement (JAXB_NS_URI, "typesafeEnumMember")
                      .setAttribute ("value", sValue)
                      .setAttribute ("name", sCodeName);
    aValueToConstants.put (sValue, sCodeName);
  }

  // Write out the mapping file for easy later-on resolving
  XMLMapHandler.writeMap (aValueToConstants,
                          new FileSystemResource ("src/main/resources/schemas/" + sFilename + ".mapping"));
}
 
Example #9
Source File: IPSQueryBinding.java    From ph-schematron with Apache License 2.0 2 votes vote down vote up
/**
 * Convert the passed list of {@link PSParam} elements to a map suitable for
 * String replacement. This is needed to resolve placeholders in abstract
 * patterns. The default query binding e.g. adds a "$" in front of each
 * parameter name. The so created map is used to resolve abstract rule and
 * pattern data to real values.
 *
 * @param aParams
 *        Source list. May not be <code>null</code>.
 * @return Non-<code>null</code> String replacement map.
 */
@Nonnull
@ReturnsMutableCopy
ICommonsNavigableMap <String, String> getStringReplacementMap (@Nonnull List <PSParam> aParams);