com.helger.commons.collection.impl.ICommonsOrderedMap Java Examples
The following examples show how to use
com.helger.commons.collection.impl.ICommonsOrderedMap.
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: CollectionHelper.java From ph-commons with Apache License 2.0 | 6 votes |
/** * Get a map sorted by aIter's values. The comparison order is defined by the * passed comparator object. * * @param <KEYTYPE> * map key type * @param <VALUETYPE> * map value type * @param aMap * The map to sort. May not be <code>null</code>. * @param aValueComparator * The comparator to be used. May not be <code>null</code>. * @return the sorted map and never <code>null</code>. */ @Nonnull @ReturnsMutableCopy public static <KEYTYPE, VALUETYPE> ICommonsOrderedMap <KEYTYPE, VALUETYPE> getSortedByValue (@Nullable final Map <KEYTYPE, VALUETYPE> aMap, @Nonnull final Comparator <? super VALUETYPE> aValueComparator) { ValueEnforcer.notNull (aValueComparator, "ValueComparator"); if (isEmpty (aMap)) return newOrderedMap (0); // get sorted Map.Entry list by Entry.getValue () final ICommonsList <Map.Entry <KEYTYPE, VALUETYPE>> aList = newList (aMap.entrySet ()); aList.sort (Comparator.comparing (Map.Entry::getValue, aValueComparator)); return newOrderedMap (aList); }
Example #2
Source File: JsonWriterTest.java From ph-commons with Apache License 2.0 | 6 votes |
@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 #3
Source File: JsonWriterTest.java From ph-commons with Apache License 2.0 | 6 votes |
@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 #4
Source File: JsonConverterTest.java From ph-commons with Apache License 2.0 | 6 votes |
@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 #5
Source File: CollectionHelper.java From ph-commons with Apache License 2.0 | 6 votes |
/** * Get a map sorted by its keys. The comparison order is defined by the passed * comparator object. * * @param <KEYTYPE> * map key type * @param <VALUETYPE> * map value type * @param aMap * The map to sort. May not be <code>null</code>. * @param aKeyComparator * The comparator to be used. May not be <code>null</code>. * @return the sorted map and never <code>null</code>. */ @Nonnull @ReturnsMutableCopy public static <KEYTYPE, VALUETYPE> ICommonsOrderedMap <KEYTYPE, VALUETYPE> getSortedByKey (@Nullable final Map <KEYTYPE, VALUETYPE> aMap, @Nonnull final Comparator <? super KEYTYPE> aKeyComparator) { ValueEnforcer.notNull (aKeyComparator, "KeyComparator"); if (isEmpty (aMap)) return newOrderedMap (0); // get sorted Map.Entry list by Entry.getValue () final ICommonsList <Map.Entry <KEYTYPE, VALUETYPE>> aList = newList (aMap.entrySet ()); aList.sort (Comparator.comparing (Map.Entry::getKey, aKeyComparator)); return newOrderedMap (aList); }
Example #6
Source File: ConfigurationSourceJson.java From ph-commons with Apache License 2.0 | 6 votes |
@Nullable private static ICommonsOrderedMap <String, String> _load (@Nonnull final IReadableResource aRes, @Nonnull final Charset aCharset) { final JsonReader.Builder aBuilder = JsonReader.builder () .setSource (aRes, aCharset) .setCustomizeCallback (aParser -> aParser.setRequireStringQuotes (false) .setAllowSpecialCharsInStrings (true) .setAlwaysUseBigNumber (true) .setTrackPosition (true)) .setCustomExceptionCallback (ex -> LOGGER.error ("Failed to parse '" + aRes.getPath () + "' to JSON: " + ex.getMessage ())); final IJsonObject aProps = aBuilder.hasSource () ? aBuilder.readAsObject () : null; if (aProps == null) return null; final ICommonsOrderedMap <String, String> ret = new CommonsLinkedHashMap <> (); for (final Map.Entry <String, IJson> aEntry : aProps) _recursiveFlattenJson (aEntry.getKey (), aEntry.getValue (), ret); return ret; }
Example #7
Source File: CharsetHelper.java From ph-commons with Apache License 2.0 | 5 votes |
/** * @return An immutable collection of all available charsets from the standard * charset provider. */ @Nonnull @ReturnsMutableCopy public static ICommonsOrderedMap <String, Charset> getAllCharsets () { return new CommonsLinkedHashMap <> (s_aAllCharsets); }
Example #8
Source File: BenchmarkStringMultiReplace.java From ph-commons with Apache License 2.0 | 5 votes |
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 #9
Source File: MainReadAllCSSOnDisc.java From ph-css with Apache License 2.0 | 5 votes |
@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 #10
Source File: CollectionHelper.java From ph-commons with Apache License 2.0 | 5 votes |
/** * Get a map sorted by its values. Because no comparator is defined, the value * type needs to implement the {@link java.lang.Comparable} interface. * * @param <KEYTYPE> * map key type * @param <VALUETYPE> * map value type * @param aMap * The map to sort. May not be <code>null</code>. * @return the sorted map and never <code>null</code>. */ @Nonnull @ReturnsMutableCopy public static <KEYTYPE, VALUETYPE extends Comparable <? super VALUETYPE>> ICommonsOrderedMap <KEYTYPE, VALUETYPE> getSortedByValue (@Nullable final Map <KEYTYPE, VALUETYPE> aMap) { if (isEmpty (aMap)) return newOrderedMap (0); // get sorted entry list final ICommonsList <Map.Entry <KEYTYPE, VALUETYPE>> aList = newList (aMap.entrySet ()); aList.sort (Comparator.comparing (Map.Entry::getValue)); return newOrderedMap (aList); }
Example #11
Source File: PSPhase.java From ph-schematron with Apache License 2.0 | 5 votes |
@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 #12
Source File: CollectionHelper.java From ph-commons with Apache License 2.0 | 5 votes |
/** * Get a map sorted by aIter's keys. Because no comparator is defined, the key * type needs to implement the {@link java.lang.Comparable} interface. * * @param <KEYTYPE> * map key type * @param <VALUETYPE> * map value type * @param aMap * the map to sort * @return the sorted map and never <code>null</code>. */ @Nonnull @ReturnsMutableCopy public static <KEYTYPE extends Comparable <? super KEYTYPE>, VALUETYPE> ICommonsOrderedMap <KEYTYPE, VALUETYPE> getSortedByKey (@Nullable final Map <KEYTYPE, VALUETYPE> aMap) { if (isEmpty (aMap)) return newOrderedMap (0); // get sorted entry list final ICommonsList <Map.Entry <KEYTYPE, VALUETYPE>> aList = newList (aMap.entrySet ()); aList.sort (Comparator.comparing (Map.Entry::getKey)); return newOrderedMap (aList); }
Example #13
Source File: URLParameterList.java From ph-commons with Apache License 2.0 | 5 votes |
/** * @return A new multi map (map from String to List of String) with all * values. Order may be lost. Never <code>null</code>. */ @Nonnull @ReturnsMutableCopy public ICommonsOrderedMap <String, ICommonsList <String>> getAsMultiMap () { final ICommonsOrderedMap <String, ICommonsList <String>> ret = new CommonsLinkedHashMap <> (); forEach (aParam -> ret.computeIfAbsent (aParam.getName (), x -> new CommonsArrayList <> ()) .add (aParam.getValue ())); return ret; }
Example #14
Source File: IErrorList.java From ph-commons with Apache License 2.0 | 5 votes |
/** * @param aKeyExtractor * the key extractor by which the result is grouped. * @return A map with all items mapped from a key to its occurrences. * @param <T> * Return list key type */ @Nonnull @ReturnsMutableCopy default <T> ICommonsOrderedMap <T, ICommonsList <IError>> getGrouped (@Nonnull final Function <? super IError, T> aKeyExtractor) { final ICommonsOrderedMap <T, ICommonsList <IError>> ret = new CommonsLinkedHashMap <> (); // create a list for each key, and add the respective entry forEach (x -> ret.computeIfAbsent (aKeyExtractor.apply (x), k -> new CommonsArrayList <> ()).add (x)); return ret; }
Example #15
Source File: PSSchema.java From ph-schematron with Apache License 2.0 | 5 votes |
@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 #16
Source File: PSPattern.java From ph-schematron with Apache License 2.0 | 5 votes |
@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 #17
Source File: PSRule.java From ph-schematron with Apache License 2.0 | 5 votes |
@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 #18
Source File: JsonObject.java From ph-commons with Apache License 2.0 | 5 votes |
@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 #19
Source File: MicroElement.java From ph-commons with Apache License 2.0 | 5 votes |
@Nullable @ReturnsMutableCopy public ICommonsOrderedMap <IMicroQName, String> getAllQAttributes () { if (hasNoAttributes ()) return null; return new CommonsLinkedHashMap <> (m_aAttrs.values (), IMicroAttribute::getAttributeQName, IMicroAttribute::getAttributeValue); }
Example #20
Source File: DirectedGraph.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @ReturnsMutableCopy public ICommonsOrderedMap <String, IMutableDirectedGraphRelation> getAllRelations () { final ICommonsOrderedMap <String, IMutableDirectedGraphRelation> ret = new CommonsLinkedHashMap <> (); for (final IMutableDirectedGraphNode aNode : m_aNodes.values ()) aNode.forEachRelation (x -> ret.put (x.getID (), x)); return ret; }
Example #21
Source File: ConfigurationSourceJson.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull public ESuccess reload () { // Main load final ICommonsOrderedMap <String, String> aProps = _load (getResource (), m_aCharset); // Replace in write-lock m_aRWLock.writeLockedGet ( () -> m_aProps = aProps); return ESuccess.valueOf (aProps != null); }
Example #22
Source File: Graph.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @ReturnsMutableCopy public ICommonsOrderedMap <String, IMutableGraphRelation> getAllRelations () { final ICommonsOrderedMap <String, IMutableGraphRelation> ret = new CommonsLinkedHashMap <> (); for (final IMutableGraphNode aNode : m_aNodes.values ()) aNode.forEachRelation (x -> ret.put (x.getID (), x)); return ret; }
Example #23
Source File: XMLResourceBundle.java From ph-commons with Apache License 2.0 | 5 votes |
@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 #24
Source File: MapBasedXPathFunctionResolver.java From ph-commons with Apache License 2.0 | 5 votes |
/** * @return A mutable copy of all contained functions. Never <code>null</code> * but maybe empty. */ @Nonnull @ReturnsMutableCopy public ICommonsOrderedMap <XPathFunctionKey, XPathFunction> getAllFunctions () { return m_aMap.getClone (); }
Example #25
Source File: XMLHelper.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @ReturnsMutableCopy public static ICommonsOrderedMap <String, String> getAllAttributesAsMap (@Nullable final Element aSrcNode) { final ICommonsOrderedMap <String, String> ret = new CommonsLinkedHashMap <> (); // Cast needed for Oracle JDK 8 forAllAttributes (aSrcNode, (BiConsumer <? super String, ? super String>) ret::put); return ret; }
Example #26
Source File: AbstractSchematronXSLTBasedResource.java From ph-schematron with Apache License 2.0 | 4 votes |
@Nonnull @ReturnsMutableObject public final ICommonsOrderedMap <String, Object> parameters () { return m_aCustomParameters; }
Example #27
Source File: PSExtends.java From ph-schematron with Apache License 2.0 | 4 votes |
@Nonnull @ReturnsMutableCopy public ICommonsOrderedMap <String, String> getAllForeignAttributes () { return new CommonsLinkedHashMap <> (m_aForeignAttrs); }
Example #28
Source File: IPSHasForeignAttributes.java From ph-schematron with Apache License 2.0 | 4 votes |
@Nonnull @ReturnsMutableCopy ICommonsOrderedMap <String, String> getAllForeignAttributes ();
Example #29
Source File: PSPhase.java From ph-schematron with Apache License 2.0 | 4 votes |
@Nonnull @ReturnsMutableCopy public ICommonsOrderedMap <String, String> getAllForeignAttributes () { return new CommonsLinkedHashMap <> (m_aForeignAttrs); }
Example #30
Source File: PSP.java From ph-schematron with Apache License 2.0 | 4 votes |
@Nonnull @ReturnsMutableCopy public ICommonsOrderedMap <String, String> getAllForeignAttributes () { return new CommonsLinkedHashMap <> (m_aForeignAttrs); }