com.helger.commons.collection.CollectionHelper Java Examples
The following examples show how to use
com.helger.commons.collection.CollectionHelper.
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: IAggregatorTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testUseLast () { final IAggregator <String, String> a1 = CollectionHelper::getLastElement; assertEquals (a1, a1); assertNotEquals (a1, null); assertNotEquals (a1, "any other"); assertEquals (a1.hashCode (), a1.hashCode ()); assertNotEquals (a1.hashCode (), 0); assertNotEquals (a1.hashCode (), "any other".hashCode ()); assertNotNull (a1.toString ()); final ICommonsList <String> l = new CommonsArrayList <> ("a", null, "b", "", "c"); assertEquals ("c", a1.apply (l)); assertNull (a1.apply (new CommonsArrayList <String> ())); assertNull (a1.apply ((Collection <String>) null)); }
Example #2
Source File: EqualsHelperTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testEqualsTypeSpecific () { final StringBuffer aSB1 = new StringBuffer ("Hi"); CommonsAssert.assertEquals (aSB1, new StringBuffer ("Hi")); CommonsAssert.assertNotEquals (aSB1, new StringBuffer ("Hallo")); CommonsAssert.assertEquals (aSB1, new StringBuffer ("Hi")); CommonsAssert.assertNotEquals (aSB1, new StringBuffer ("Hallo")); CommonsAssert.assertNotEquals (aSB1, null); CommonsAssert.assertEquals (new CommonsArrayList <> ("a", "b", "c"), new CommonsArrayList <> ("a", "b", "c")); CommonsAssert.assertEquals (StackHelper.newStack ("a", "b", "c"), StackHelper.newStack ("a", "b", "c")); CommonsAssert.assertEquals (new CommonsArrayList <> ("a", "b", "c").iterator (), new CommonsArrayList <> ("a", "b", "c").iterator ()); CommonsAssert.assertEquals (IteratorHelper.getEnumeration ("a", "b", "c"), IteratorHelper.getEnumeration ("a", "b", "c")); CommonsAssert.assertNotEquals (CollectionHelper.makeUnmodifiable (new CommonsArrayList <> ("a", "b", "c")), new CommonsArrayList <> ("a", "b", "c")); }
Example #3
Source File: PSSchema.java From ph-schematron with Apache License 2.0 | 6 votes |
@Override public String toString () { return new ToStringGenerator (this).appendIfNotNull ("resource", m_aResource) .appendIfNotNull ("id", m_sID) .appendIfNotNull ("rich", m_aRich) .appendIfNotNull ("schemaVersion", m_sSchemaVersion) .appendIfNotNull ("defaultPhase", m_sDefaultPhase) .appendIfNotNull ("queryBinding", m_sQueryBinding) .appendIfNotNull ("title", m_aTitle) .appendIf ("includes", m_aIncludes, CollectionHelper::isNotEmpty) .appendIf ("nss", m_aNSs, CollectionHelper::isNotEmpty) .appendIf ("startps", m_aStartPs, CollectionHelper::isNotEmpty) .appendIf ("lets", m_aLets, CollectionHelper::isNotEmpty) .appendIf ("phases", m_aPhases, CollectionHelper::isNotEmpty) .appendIf ("patterns", m_aPatterns, CollectionHelper::isNotEmpty) .appendIf ("endps", m_aEndPs, CollectionHelper::isNotEmpty) .appendIfNotNull ("diagnostics", m_aDiagnostics) .appendIf ("foreignAttrs", m_aForeignAttrs, CollectionHelper::isNotEmpty) .appendIf ("foreignElements", m_aForeignElements, CollectionHelper::isNotEmpty) .getToString (); }
Example #4
Source File: IAggregatorTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testUseFirst () { final IAggregator <String, String> a1 = CollectionHelper::getFirstElement; assertEquals (a1, a1); assertNotEquals (a1, null); assertNotEquals (a1, "any other"); assertEquals (a1.hashCode (), a1.hashCode ()); assertNotEquals (a1.hashCode (), 0); assertNotEquals (a1.hashCode (), "any other".hashCode ()); assertNotNull (a1.toString ()); final ICommonsList <String> l = new CommonsArrayList <> ("a", null, "b", "", "c"); assertEquals ("a", a1.apply (l)); assertNull (a1.apply (new CommonsArrayList <String> ())); assertNull (a1.apply ((Collection <String>) null)); }
Example #5
Source File: EqualsHelperTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testList () { final ICommonsList <String> aCont = new CommonsArrayList <> ("a", "b", "c"); assertTrue (EqualsHelper.equalsCollection (aCont, aCont)); assertTrue (EqualsHelper.equalsCollection (aCont, CollectionHelper.makeUnmodifiable (aCont))); assertTrue (EqualsHelper.equalsCollection (aCont, Collections.synchronizedList (aCont))); assertTrue (EqualsHelper.equalsCollection (aCont, new CommonsArrayList <> (aCont))); assertTrue (EqualsHelper.equalsCollection (aCont, new CommonsLinkedList <> (aCont))); assertTrue (EqualsHelper.equalsCollection (aCont, new CommonsVector <> (aCont))); assertTrue (EqualsHelper.equalsCollection (aCont, new NonBlockingStack <> (aCont))); assertTrue (EqualsHelper.equalsCollection (new CommonsArrayList <String> (), new CommonsLinkedList <String> ())); assertTrue (EqualsHelper.equalsCollection (new NonBlockingStack <String> (), new CommonsVector <String> ())); assertTrue (EqualsHelper.equalsCollection (new NonBlockingStack <String> (), new Stack <String> ())); assertFalse (EqualsHelper.equalsCollection (aCont, new CommonsLinkedList <String> ())); assertFalse (EqualsHelper.equalsCollection (new CommonsLinkedList <String> (), aCont)); assertFalse (EqualsHelper.equalsCollection (aCont, new CommonsArrayList <String> ())); assertFalse (EqualsHelper.equalsCollection (aCont, new CommonsArrayList <> ("a", "b"))); assertFalse (EqualsHelper.equalsCollection (aCont, new CommonsArrayList <> ("A", "b", "c"))); assertFalse (EqualsHelper.equalsCollection (aCont, new CommonsArrayList <> ("a", "B", "c"))); assertFalse (EqualsHelper.equalsCollection (aCont, new CommonsArrayList <> ("a", "b", "C"))); assertFalse (EqualsHelper.equalsCollection (aCont, new CommonsArrayList <> ("a", "b", "c", "d"))); assertFalse (EqualsHelper.equalsCollection (aCont, new CommonsHashSet <> ("a", "b", "c"))); assertFalse (EqualsHelper.equalsCollection (aCont, ArrayHelper.newArray ("a", "b", "c"))); }
Example #6
Source File: EqualsHelperTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testSet () { final ICommonsSet <String> aCont = new CommonsHashSet <> ("a", "b", "c"); assertTrue (EqualsHelper.equalsCollection (aCont, aCont)); assertTrue (EqualsHelper.equalsCollection (aCont, CollectionHelper.makeUnmodifiable (aCont))); assertTrue (EqualsHelper.equalsCollection (aCont, Collections.synchronizedSet (aCont))); assertTrue (EqualsHelper.equalsCollection (aCont, new CommonsHashSet <> (aCont))); assertTrue (EqualsHelper.equalsCollection (aCont, new CommonsLinkedHashSet <> (aCont))); assertTrue (EqualsHelper.equalsCollection (aCont, new CommonsTreeSet <> (aCont))); assertTrue (EqualsHelper.equalsCollection (new CommonsHashSet <String> (), new CommonsLinkedHashSet <String> ())); assertTrue (EqualsHelper.equalsCollection (new CommonsTreeSet <String> (), new CommonsHashSet <String> ())); assertFalse (EqualsHelper.equalsCollection (aCont, new CommonsHashSet <String> ())); assertFalse (EqualsHelper.equalsCollection (new CommonsHashSet <String> (), aCont)); assertFalse (EqualsHelper.equalsCollection (aCont, new CommonsTreeSet <String> ())); assertFalse (EqualsHelper.equalsCollection (aCont, new CommonsHashSet <> ("a", "b"))); assertFalse (EqualsHelper.equalsCollection (aCont, new CommonsHashSet <> ("A", "b", "c"))); assertFalse (EqualsHelper.equalsCollection (aCont, new CommonsHashSet <> ("a", "B", "c"))); assertFalse (EqualsHelper.equalsCollection (aCont, new CommonsHashSet <> ("a", "b", "C"))); assertFalse (EqualsHelper.equalsCollection (aCont, new CommonsHashSet <> ("a", "b", "c", "d"))); assertFalse (EqualsHelper.equalsCollection (aCont, new CommonsArrayList <> ("a", "b", "c"))); assertFalse (EqualsHelper.equalsCollection (aCont, ArrayHelper.newArray ("a", "b", "c"))); }
Example #7
Source File: EqualsHelperTest.java From ph-commons with Apache License 2.0 | 6 votes |
@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 #8
Source File: IComparatorTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testCollatingOrder () { final String S1 = "abc"; final String S2 = "ABC"; final String S3 = "ab"; final String [] x = new String [] { S1, S2, S3 }; // Explicitly sort ascending List <String> l = CollectionHelper.getSorted (x, IComparator.getComparatorCollating (Locale.US)); assertArrayEquals (new String [] { S3, S1, S2 }, l.toArray ()); // Explicitly sort descending l = CollectionHelper.getSorted (x, IComparator.getComparatorCollating (Locale.US).reversed ()); assertArrayEquals (new String [] { S2, S1, S3 }, l.toArray ()); }
Example #9
Source File: MockUBLTRTestDocuments.java From ph-ubl with Apache License 2.0 | 6 votes |
@Nonnull @ReturnsMutableCopy public static List <String> getUBLTRTestDocuments (@Nonnull final EUBLTRDocumentType eType) { List <String> aFiles = null; switch (eType) { case CANCEL_USER_ACCOUNT: aFiles = CollectionHelper.makeUnmodifiable (PREFIX + "tr_useraccount/5_KULLANICI_SILME.xml", PREFIX + "tr_useraccount/9_FATURA_SAKLAMA_KULLANICI_SILME.xml"); break; case PROCESS_USER_ACCOUNT: aFiles = CollectionHelper.makeUnmodifiable (PREFIX + "tr_useraccount/4_KULLANICI_ACMA.xml", PREFIX + "tr_useraccount/8_FATURA_SAKLAMA_KULLANICI_ACMA.xml"); break; default: throw new IllegalArgumentException ("No test files available for type " + eType); } return CollectionHelper.newList (aFiles); }
Example #10
Source File: FilterIteratorTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testIteration5 () { // filtered elements at the beginning final List <String> aList = CollectionHelper.newList (null, null, "s1", "s2", "s3"); final FilterIterator <String> it = new FilterIterator <> (aList, Objects::nonNull); assertNotNull (it); assertEquals ("s1", it.next ()); assertEquals ("s2", it.next ()); assertEquals ("s3", it.next ()); CommonsTestHelper.testToStringImplementation (it); try { // can't call next if hasNext failed it.next (); fail (); } catch (final NoSuchElementException ex) {} }
Example #11
Source File: KeyStoreHelperTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testLoadPeppolTrustStorePilot () throws Exception { // Load trust store final KeyStore aTrustStore = KeyStoreHelper.loadKeyStoreDirect (EKeyStoreType.JKS, "keystores/truststore-peppol-pilot.jks", "peppol"); assertNotNull (aTrustStore); // Additionally the STS certificate is contained assertEquals (4, CollectionHelper.getSize (aTrustStore.aliases ())); // Ensure all name entries are contained assertNotNull (aTrustStore.getCertificate (TRUSTSTORE_PILOT_ALIAS_ROOT)); assertNotNull (aTrustStore.getCertificate (TRUSTSTORE_PILOT_ALIAS_AP)); assertNotNull (aTrustStore.getCertificate (TRUSTSTORE_PILOT_ALIAS_SMP)); final X509Certificate aCertAPOld = (X509Certificate) aTrustStore.getCertificate (TRUSTSTORE_PILOT_ALIAS_AP); final String sIssuerName = aCertAPOld.getIssuerX500Principal ().getName (); assertEquals ("CN=PEPPOL Root TEST CA,OU=FOR TEST PURPOSES ONLY,O=NATIONAL IT AND TELECOM AGENCY,C=DK", sIssuerName); final String sSubjectName = aCertAPOld.getSubjectX500Principal ().getName (); assertEquals ("CN=PEPPOL ACCESS POINT TEST CA,OU=FOR TEST PURPOSES ONLY,O=NATIONAL IT AND TELECOM AGENCY,C=DK", sSubjectName); }
Example #12
Source File: DefaultTreeWithGlobalUniqueIDTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testChildProvder () { final DefaultTreeWithGlobalUniqueID <String, String> aTestTree2 = new DefaultTreeWithGlobalUniqueID <> (); assertEquals (0, aTestTree2.getChildCount (null)); assertFalse (aTestTree2.hasChildren (null)); assertTrue (CollectionHelper.isEmpty (aTestTree2.getAllChildren (null))); final DefaultTreeItemWithID <String, String> x12 = aTestTree2.getRootItem ().createChildItem ("x1", "1"); x12.createChildItem ("x2", "a"); x12.createChildItem ("x3", "b"); x12.createChildItem ("x4", "c"); assertEquals (1, aTestTree2.getChildCount (null)); assertTrue (aTestTree2.hasChildren (null)); assertEquals (1, aTestTree2.getAllChildren (null).size ()); assertEquals (3, aTestTree2.getChildCount (x12)); assertTrue (aTestTree2.hasChildren (x12)); assertEquals (3, aTestTree2.getAllChildren (x12).size ()); }
Example #13
Source File: IComparatorTest.java From ph-commons with Apache License 2.0 | 6 votes |
/** * Test for constructors using a locale */ @Test public void testLocaleGerman () { final String S1 = "bbc"; final String S2 = "abc"; final String S3 = "äbc"; final String [] x = new String [] { S1, S2, S3 }; // default: sort ascending ICommonsList <String> l = CollectionHelper.getSorted (x, IComparator.getComparatorCollating (Locale.GERMAN)); assertArrayEquals (new String [] { S2, S3, S1 }, l.toArray ()); // sort ascending manually l = CollectionHelper.getSorted (x, IComparator.getComparatorCollating (Locale.GERMAN)); assertArrayEquals (new String [] { S2, S3, S1 }, l.toArray ()); // sort descending manually l = CollectionHelper.getSorted (x, IComparator.getComparatorCollating (Locale.GERMAN).reversed ()); assertArrayEquals (new String [] { S1, S3, S2 }, l.toArray ()); // null locale allowed IComparator.getComparatorCollating ((Locale) null); assertArrayEquals (new String [] { S1, S3, S2 }, l.toArray ()); }
Example #14
Source File: CommonsLinkedHashMap.java From ph-commons with Apache License 2.0 | 5 votes |
public <COLLTYPE> CommonsLinkedHashMap (@Nullable final Collection <? extends COLLTYPE> aValues, @Nonnull final Function <? super COLLTYPE, ? extends KEYTYPE> aKeyMapper, @Nonnull final Function <? super COLLTYPE, ? extends VALUETYPE> aValueMapper) { super (CollectionHelper.getSize (aValues)); putAllMapped (aValues, aKeyMapper, aValueMapper); }
Example #15
Source File: EqualsHelperTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testComplex () { final ICommonsMap <ICommonsList <String>, ICommonsSet <String>> aMap = new CommonsHashMap <> (); aMap.put (new CommonsArrayList <> ("a", "b", "c"), new CommonsHashSet <> ("a", "b", "c")); aMap.put (new CommonsArrayList <> ("a", "b", "d"), new CommonsHashSet <> ("a", "b", "d")); assertTrue (EqualsHelper.equalsCollection (aMap, CollectionHelper.newMap (aMap))); assertFalse (EqualsHelper.equalsCollection (aMap, ArrayHelper.newArray ("a", "b", "c", "d"))); assertFalse (EqualsHelper.equalsCollection (aMap, new CommonsArrayList <> ("a", "b", "c"))); assertFalse (EqualsHelper.equalsCollection (aMap, new CommonsHashSet <> ("a", "b", "c"))); final ICommonsMap <String, String> aMap1a = new CommonsHashMap <> (); aMap1a.put ("a", "b"); assertFalse (EqualsHelper.equalsCollection (aMap, aMap1a)); final ICommonsMap <ICommonsList <String>, String> aMap2 = new CommonsHashMap <> (); aMap2.put (new CommonsArrayList <> ("a", "b", "c"), "d"); aMap2.put (new CommonsArrayList <> ("a", "b", "d"), "e"); aMap2.put (new CommonsArrayList <> ("a", "b", "e"), null); aMap2.put (null, "g"); assertFalse (EqualsHelper.equalsCollection (aMap, aMap2)); assertFalse (EqualsHelper.equalsCollection (aMap2, aMap)); final ICommonsMap <String, ICommonsList <String>> aMap3 = new CommonsHashMap <> (); aMap3.put ("d", new CommonsArrayList <> ("a", "b", "c")); aMap3.put ("e", new CommonsArrayList <> ("a", "b", "d")); aMap3.put (null, new CommonsArrayList <> ("a", "b", "e")); aMap3.put ("g", null); assertFalse (EqualsHelper.equalsCollection (aMap, aMap3)); assertFalse (EqualsHelper.equalsCollection (aMap3, aMap)); }
Example #16
Source File: IterableIteratorTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testBasic () { assertSame (IterableIterator.createEmpty (), IterableIterator.createEmpty ()); IIterableIterator <String> iit = new IterableIterator <> (ArrayHelper.newArray ("Hallo", "Welt", "from", "Copenhagen")); assertNotNull (iit); assertNotNull (iit.iterator ()); assertTrue (iit.hasNext ()); assertEquals ("Hallo", iit.next ()); iit = new IterableIterator <> (CollectionHelper.newList ("Hallo", "Welt", "from", "Copenhagen")); iit.next (); iit.remove (); assertEquals (3, CollectionHelper.newList (new IterableIterator <> (new String [] { "a", "b", "c" })).size ()); assertEquals (3, CollectionHelper.newList (new IterableIterator <> (CollectionHelper.newList ("a", "b", "c"))) .size ()); assertEquals (3, CollectionHelper.newList (new IterableIterator <> (CollectionHelper.newList ("a", "b", "c") .iterator ())) .size ()); CommonsTestHelper.testToStringImplementation (iit); try { new IterableIterator <> ((Iterator <String>) null); fail (); } catch (final NullPointerException ex) {} }
Example #17
Source File: CommonsLinkedHashMap.java From ph-commons with Apache License 2.0 | 5 votes |
public <SRCKEYTYPE, SRCVALUETYPE> CommonsLinkedHashMap (@Nullable final Map <? extends SRCKEYTYPE, ? extends SRCVALUETYPE> aValues, @Nonnull final Function <? super SRCKEYTYPE, ? extends KEYTYPE> aKeyMapper, @Nonnull final Function <? super SRCVALUETYPE, ? extends VALUETYPE> aValueMapper) { super (CollectionHelper.getSize (aValues)); putAllMapped (aValues, aKeyMapper, aValueMapper); }
Example #18
Source File: CommonsHashMap.java From ph-commons with Apache License 2.0 | 5 votes |
public <SRCKEYTYPE, SRCVALUETYPE> CommonsHashMap (@Nullable final Map <? extends SRCKEYTYPE, ? extends SRCVALUETYPE> aValues, @Nonnull final Function <? super SRCKEYTYPE, ? extends KEYTYPE> aKeyMapper, @Nonnull final Function <? super SRCVALUETYPE, ? extends VALUETYPE> aValueMapper) { super (CollectionHelper.getSize (aValues)); putAllMapped (aValues, aKeyMapper, aValueMapper); }
Example #19
Source File: PSDiagnostic.java From ph-schematron with Apache License 2.0 | 5 votes |
@Override public String toString () { return new ToStringGenerator (this).appendIfNotNull ("id", m_sID) .appendIfNotNull ("rich", m_aRich) .appendIf ("content", m_aContent, CollectionHelper::isNotEmpty) .appendIf ("foreignAttrs", m_aForeignAttrs, CollectionHelper::isNotEmpty) .getToString (); }
Example #20
Source File: ICommonsOrderedMap.java From ph-commons with Apache License 2.0 | 5 votes |
@Override @Nonnull @ReturnsMutableCopy default ICommonsOrderedSet <KEYTYPE> copyOfKeySet (@Nullable final Predicate <? super KEYTYPE> aFilter) { if (aFilter == null) return copyOfKeySet (); return CollectionHelper.newOrderedSet (keySet (), aFilter); }
Example #21
Source File: ICommonsSortedMap.java From ph-commons with Apache License 2.0 | 5 votes |
@Override @Nonnull @ReturnsMutableCopy default ICommonsSortedSet <KEYTYPE> copyOfKeySet (@Nullable final Predicate <? super KEYTYPE> aFilter) { if (aFilter == null) return copyOfKeySet (); final CommonsTreeSet <KEYTYPE> ret = new CommonsTreeSet <> (); CollectionHelper.findAll (keySet (), aFilter, ret::add); return ret; }
Example #22
Source File: PSP.java From ph-schematron with Apache License 2.0 | 5 votes |
@Override public String toString () { return new ToStringGenerator (this).appendIfNotNull ("id", m_sID) .appendIfNotNull ("class", m_sClass) .appendIfNotNull ("icon", m_sIcon) .appendIf ("content", m_aContent, CollectionHelper::isNotEmpty) .appendIf ("foreignAttrs", m_aForeignAttrs, CollectionHelper::isNotEmpty) .getToString (); }
Example #23
Source File: QueueHelper.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @ReturnsMutableCopy public static <ELEMENTTYPE> PriorityQueue <ELEMENTTYPE> newQueue (@Nullable final Collection <? extends ELEMENTTYPE> aCont) { if (CollectionHelper.isEmpty (aCont)) return newQueue (0); return new PriorityQueue <> (aCont); }
Example #24
Source File: AbstractMapBasedWALDAO.java From ph-commons with Apache License 2.0 | 5 votes |
@IsLocked (ELockType.READ) public final <RETTYPE> void findAllMapped (@Nullable final Predicate <? super INTERFACETYPE> aFilter, @Nonnull final Function <? super INTERFACETYPE, ? extends RETTYPE> aMapper, @Nonnull final Consumer <? super RETTYPE> aConsumer) { // (Runnable) cast for Java 9 m_aRWLock.readLocked ((Runnable) () -> CollectionHelper.findAllMapped (m_aMap.values (), aFilter, aMapper, aConsumer)); }
Example #25
Source File: AbstractMapBasedWALDAO.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @ReturnsMutableCopy @IsLocked (ELockType.READ) public final ICommonsList <INTERFACETYPE> getAll (@Nullable final Predicate <? super INTERFACETYPE> aFilter) { if (aFilter == null) return getAll (); // Use new CommonsArrayList to get the return type to NOT use "? extends // INTERFACETYPE" final ICommonsList <INTERFACETYPE> ret = new CommonsArrayList <> (); // (Runnable) cast for Java 9 m_aRWLock.readLocked ((Runnable) () -> CollectionHelper.findAll (m_aMap.values (), aFilter, ret::add)); return ret; }
Example #26
Source File: PSValueOf.java From ph-schematron with Apache License 2.0 | 5 votes |
@Override public String toString () { return new ToStringGenerator (this).appendIfNotNull ("select", m_sSelect) .appendIf ("foreignAttrs", m_aForeignAttrs, CollectionHelper::isNotEmpty) .getToString (); }
Example #27
Source File: JsonWriterTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testComplex () { final ICommonsList <JsonObject> aObjs = new CommonsArrayList <> (); for (final ICommonsMap <String, String> aRow : new CommonsArrayList <> (CollectionHelper.newMap ("key", "value"))) { final JsonObject aObj = new JsonObject (); for (final Map.Entry <String, String> aEntry : aRow.entrySet ()) aObj.add (aEntry.getKey (), aEntry.getValue ()); aObjs.add (aObj); } assertEquals ("{\"aa\":[{\"key\":\"value\"}]}", JsonConverter.convertToJson (new JsonObject ().add ("aa", aObjs)).getAsJsonString ()); }
Example #28
Source File: ChildElementIteratorTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testGetRecursiveChildIter () { final Document doc = XMLFactory.newDocument (); // No children present assertFalse (new ChildElementIterator (doc).hasNext ()); // 1 child final Element eRoot = (Element) doc.appendChild (doc.createElement ("root")); assertEquals (1, CollectionHelper.newList (new ChildElementIterator (doc)).size ()); // 2 children eRoot.appendChild (doc.createElement ("Hallo")); eRoot.appendChild (doc.createTextNode (" - ")); eRoot.appendChild (doc.createElement ("Welt")); assertEquals (2, CollectionHelper.newList (new ChildElementIterator (eRoot)).size ()); assertEquals (1, CollectionHelper.newList (new ChildElementIterator (eRoot).withFilter (XMLHelper.filterElementWithTagName ("Hallo"))) .size ()); try { new ChildElementIterator (doc).remove (); fail (); } catch (final UnsupportedOperationException ex) {} assertEquals (0, CollectionHelper.getSize (new ChildElementIterator (null))); }
Example #29
Source File: MapBasedNamespaceContext.java From ph-commons with Apache License 2.0 | 5 votes |
@Override @Nullable public String getCustomPrefix (@Nonnull final String sNamespaceURI) { final ICommonsSet <String> aAllPrefixes = m_aNS2Prefix.get (sNamespaceURI); return CollectionHelper.getFirstElement (aAllPrefixes); }
Example #30
Source File: MainCreateJAXBBinding23.java From ph-ubl with Apache License 2.0 | 5 votes |
@Nonnull private static Iterable <File> _getFileList (final String sPath) { return CollectionHelper.getSorted (new FileSystemIterator (sPath).withFilter (IFileFilter.filenameEndsWith (".xsd")) .withFilter (IFileFilter.filenameMatchNoRegEx ("^CCTS.*", ".*xmldsig.*", ".*XAdES.*")), Comparator.comparing (File::getName)); }