com.helger.commons.collection.impl.ICommonsSet Java Examples
The following examples show how to use
com.helger.commons.collection.impl.ICommonsSet.
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: CombinationGeneratorTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testStringCombination2 () { final ICommonsList <String> aElements = new CommonsArrayList <> (A, B, B, C); final CombinationGenerator <String> x = new CombinationGenerator <> (aElements, 0); assertEquals (BigInteger.ONE, x.getTotalCombinations ()); assertEquals (BigInteger.ONE, x.getCombinationsLeft ()); final ICommonsList <ICommonsList <String>> aResultsWithDuplicates = new CommonsArrayList <> (); final ICommonsSet <ICommonsList <String>> aResultsWithoutDuplicates = new CommonsHashSet <> (); while (x.hasNext ()) { final ICommonsList <String> aResult = x.next (); aResultsWithDuplicates.add (aResult); aResultsWithoutDuplicates.add (aResult); } assertEquals (1, aResultsWithDuplicates.size ()); assertEquals (1, aResultsWithoutDuplicates.size ()); }
Example #2
Source File: IntIntMapTest.java From ph-commons with Apache License 2.0 | 6 votes |
private void _testPutRandom (final float fillFactor) { final Random aRandom = new Random (); final int SIZE = 100 * 1000; final ICommonsSet <Integer> set = new CommonsHashSet <> (SIZE); final int [] vals = new int [SIZE]; while (set.size () < SIZE) set.add (Integer.valueOf (aRandom.nextInt ())); int i = 0; for (final Integer v : set) vals[i++] = v.intValue (); final IntIntMap map = _makeMap (100, fillFactor); for (i = 0; i < vals.length; ++i) { assertEquals (0, map.put (vals[i], vals[i])); assertEquals (i + 1, map.size ()); assertEquals (vals[i], map.get (vals[i])); } // now check the final state for (i = 0; i < vals.length; ++i) assertEquals (vals[i], map.get (vals[i])); }
Example #3
Source File: EUBL23DocumentTypeTest.java From ph-ubl with Apache License 2.0 | 6 votes |
@Test public void testAll () { final ICommonsSet <Class <?>> aClasses = new CommonsHashSet <> (); final ICommonsSet <String> aFilenames = new CommonsHashSet <> (); for (final EUBL23DocumentType e : EUBL23DocumentType.values ()) { assertNotNull (e.getImplementationClass ()); assertTrue (StringHelper.hasText (e.getLocalName ())); assertTrue (StringHelper.hasText (e.getNamespaceURI ())); assertTrue (e.getAllXSDResources ().size () >= 1); for (final IReadableResource aRes : e.getAllXSDResources ()) assertTrue (e.name (), aRes.exists ()); assertNotNull (e.getSchema ()); assertSame (e.getSchema (), e.getSchema ()); assertSame (e, EUBL23DocumentType.valueOf (e.name ())); assertTrue (aClasses.add (e.getImplementationClass ())); assertTrue (aFilenames.add (e.getAllXSDResources ().getFirst ().getPath ())); } }
Example #4
Source File: IntObjectMapTest.java From ph-commons with Apache License 2.0 | 6 votes |
private void _testPutRandom (final float fillFactor) { final Random aRandom = new Random (); final int SIZE = 100 * 1000; final ICommonsSet <Integer> set = new CommonsHashSet <> (SIZE); final int [] vals = new int [SIZE]; while (set.size () < SIZE) set.add (Integer.valueOf (aRandom.nextInt ())); int i = 0; for (final Integer v : set) vals[i++] = v.intValue (); final IntObjectMap <String> map = _makeMap (100, fillFactor); for (i = 0; i < vals.length; ++i) { assertNull ("Inserting " + vals[i], map.put (vals[i], _make (vals[i]))); assertEquals (i + 1, map.size ()); assertEquals (_make (vals[i]), map.get (vals[i])); } // now check the final state for (i = 0; i < vals.length; ++i) assertEquals (_make (vals[i]), map.get (vals[i])); }
Example #5
Source File: CollectionHelper.java From ph-commons with Apache License 2.0 | 6 votes |
@Nonnull @ReturnsMutableCopy @SafeVarargs public static <ELEMENTTYPE> ICommonsSet <ELEMENTTYPE> getConcatenatedSet (@Nullable final Collection <? extends ELEMENTTYPE> aCont1, @Nullable final ELEMENTTYPE... aCont2) { final int nSize1 = getSize (aCont1); if (nSize1 == 0) return newSet (aCont2); final int nSize2 = ArrayHelper.getSize (aCont2); if (nSize2 == 0) return newSet (aCont1); final ICommonsSet <ELEMENTTYPE> ret = newSet (nSize1 + nSize2); ret.addAll (aCont1); Collections.addAll (ret, aCont2); return ret; }
Example #6
Source File: CombinationGeneratorFlexibleTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Ignore ("Simply wrong assumption") @Test public void testRedundancy () { final ICommonsList <String> aInputList = new CommonsArrayList <> ("a", "b", "c", "d", "e", "f", "g", "h"); // Build all permutations of the input list, using all available slots final ICommonsSet <ICommonsList <String>> aSimplePermutations = new CommonsHashSet <> (); CombinationGenerator.addAllPermutations (aInputList, aInputList.size (), aSimplePermutations); // Flexible combination generator final ICommonsSet <ICommonsList <String>> aFlexiblePermutations = CombinationGeneratorFlexible.getCombinations (aInputList, true); assertTrue (aFlexiblePermutations.size () >= aSimplePermutations.size ()); // Now the assumptions: I assume that all permutations from the flexible // generator are also contained in all permutations for (final ICommonsList <String> aList : aFlexiblePermutations) assertTrue (aList.toString (), aSimplePermutations.contains (aList)); }
Example #7
Source File: BasicTreeItemWithID.java From ph-commons with Apache License 2.0 | 5 votes |
@Nullable @ReturnsMutableCopy public final ICommonsSet <KEYTYPE> getAllChildDataIDs () { if (m_aChildMap == null) return null; return m_aChildMap.copyOfKeySet (); }
Example #8
Source File: MapBasedNamespaceContext.java From ph-commons with Apache License 2.0 | 5 votes |
/** * Copy constructor. * * @param aOther * Object to copy from. May be <code>null</code>. */ public MapBasedNamespaceContext (@Nullable final MapBasedNamespaceContext aOther) { if (aOther != null) { m_sDefaultNamespaceURI = aOther.m_sDefaultNamespaceURI; m_aPrefix2NS.putAll (aOther.m_aPrefix2NS); // putAll is not enough here for (final Map.Entry <String, ICommonsSet <String>> aEntry : aOther.m_aNS2Prefix.entrySet ()) m_aNS2Prefix.put (aEntry.getKey (), aEntry.getValue ().getClone ()); } }
Example #9
Source File: UTF7CharsetProviderSPITest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testIterator () { final Iterator <Charset> iterator = tested.charsets (); final ICommonsSet <Charset> found = new CommonsHashSet<> (); while (iterator.hasNext ()) found.add (iterator.next ()); assertEquals (3, found.size ()); final Charset charset1 = tested.charsetForName ("x-IMAP4-modified-UTF7"); final Charset charset2 = tested.charsetForName ("UTF-7"); final Charset charset3 = tested.charsetForName ("X-UTF-7-OPTIONAL"); assertTrue (found.contains (charset1)); assertTrue (found.contains (charset2)); assertTrue (found.contains (charset3)); }
Example #10
Source File: SystemProperties.java From ph-commons with Apache License 2.0 | 5 votes |
/** * @return A set with all defined property names. Never <code>null</code>. */ @Nonnull @ReturnsMutableCopy public static ICommonsSet <String> getAllPropertyNames () { return getAllProperties ().copyOfKeySet (); }
Example #11
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 #12
Source File: LanguageCacheTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testNoConcurrentModificationString () { final ICommonsSet <Locale> aLanguages = new CommonsHashSet <> (); for (final String sLanguage : LanguageCache.getInstance ().getAllLanguages ()) aLanguages.add (LanguageCache.getInstance ().getLanguage (sLanguage)); for (final Locale aLanguage : aLanguages) { assertNotNull (aLanguage); assertTrue (StringHelper.hasText (aLanguage.getLanguage ())); assertTrue (StringHelper.hasNoText (aLanguage.getCountry ())); assertTrue (StringHelper.hasNoText (aLanguage.getVariant ())); } }
Example #13
Source File: ThreadDescriptorList.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @Nonempty public String getAsString () { final StringBuilder aSB = new StringBuilder (); // Error always shown first! if (StringHelper.hasText (m_sError)) aSB.append ("ERROR retrieving all thread stack traces: ").append (m_sError).append ("\n\n"); // Total thread count aSB.append ("Total thread count: ").append (m_aList.size ()).append ('\n'); // Emit thread IDs grouped by state final ICommonsMap <State, ICommonsNavigableSet <Long>> aStateMap = _getStateMap (); for (final State eState : State.values ()) { final ICommonsSet <Long> aThreadIDs = aStateMap.get (eState); final int nSize = aThreadIDs.size (); aSB.append ("Thread state ").append (eState).append (" [").append (nSize).append (']'); if (nSize > 0) aSB.append (": ").append (aThreadIDs.toString ()); aSB.append ('\n'); } // Append all stack traces at the end for (final ThreadDescriptor aDescriptor : m_aList) aSB.append ('\n').append (aDescriptor.getAsString ()); return aSB.toString (); }
Example #14
Source File: MimeTypeInfo.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @Nonempty @ReturnsMutableCopy public ICommonsSet <IMimeType> getAllMimeTypes () { return m_aMimeTypes.getAllMapped (MimeTypeWithSource::getMimeType); }
Example #15
Source File: MimeTypeInfo.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @Nonempty @ReturnsMutableCopy public ICommonsSet <String> getAllMimeTypeStrings () { return m_aMimeTypes.getAllMapped (MimeTypeWithSource::getMimeTypeAsString); }
Example #16
Source File: MimeTypeInfo.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @Nonempty @ReturnsMutableCopy public ICommonsSet <MimeTypeWithSource> getAllMimeTypesWithSource () { return m_aMimeTypes.getClone (); }
Example #17
Source File: ThreadDescriptorList.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull public IMicroElement getAsMicroNode () { final IMicroElement eRet = new MicroElement ("threadlist"); if (StringHelper.hasText (m_sError)) eRet.appendElement ("error").appendText (m_sError); // Overall thread count eRet.setAttribute ("threadcount", m_aList.size ()); // Emit thread IDs grouped by state final ICommonsMap <State, ICommonsNavigableSet <Long>> aStateMap = _getStateMap (); for (final State eState : State.values ()) { final ICommonsSet <Long> aThreadIDs = aStateMap.get (eState); final int nSize = aThreadIDs.size (); final IMicroElement eThreadState = eRet.appendElement ("threadstate"); eThreadState.setAttribute ("id", eState.toString ()); eThreadState.setAttribute ("threadcount", nSize); if (nSize > 0) eThreadState.appendText (StringHelper.getImploded (',', aThreadIDs)); } // Append all stack traces at the end for (final ThreadDescriptor aDescriptor : m_aList) eRet.appendChild (aDescriptor.getAsMicroNode ()); return eRet; }
Example #18
Source File: CollectionHelperTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test @SuppressFBWarnings ("NP_NONNULL_PARAM_VIOLATION") public void testMakeUnmodifiableNotNull () { assertNotNull (makeUnmodifiableNotNull ((Collection <?>) null)); assertNotNull (makeUnmodifiableNotNull ((ICommonsList <?>) null)); assertNotNull (makeUnmodifiableNotNull ((Set <?>) null)); assertNotNull (makeUnmodifiableNotNull ((SortedSet <?>) null)); assertNotNull (makeUnmodifiableNotNull ((Map <?, ?>) null)); assertNotNull (makeUnmodifiableNotNull ((SortedMap <?, ?>) null)); final ICommonsCollection <String> c = newList ("s1", "s2"); assertNotNull (makeUnmodifiableNotNull (c)); assertNotSame (c, makeUnmodifiableNotNull (c)); final ICommonsList <String> l = newList ("s1", "s2"); assertNotNull (makeUnmodifiableNotNull (l)); assertNotSame (l, makeUnmodifiableNotNull (l)); final ICommonsSet <String> s = newSet ("s1", "s2"); assertNotNull (makeUnmodifiableNotNull (s)); assertNotSame (s, makeUnmodifiableNotNull (s)); final ICommonsSortedSet <String> ss = new CommonsTreeSet <> (s); assertNotNull (makeUnmodifiableNotNull (ss)); assertNotSame (ss, makeUnmodifiableNotNull (ss)); final ICommonsMap <String, String> m = newMap ("s1", "s2"); assertNotNull (makeUnmodifiableNotNull (m)); assertNotSame (m, makeUnmodifiableNotNull (m)); final ICommonsSortedMap <String, String> sm = new CommonsTreeMap <> (m); assertNotNull (makeUnmodifiableNotNull (sm)); assertNotSame (sm, makeUnmodifiableNotNull (sm)); }
Example #19
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 #20
Source File: MapBasedNamespaceContext.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull public EChange removeMapping (@Nullable final String sPrefix) { final String sNamespaceURI = m_aPrefix2NS.remove (sPrefix); if (sNamespaceURI == null) return EChange.UNCHANGED; // Remove from namespace 2 prefix map as well final ICommonsSet <String> aSet = m_aNS2Prefix.get (sNamespaceURI); if (aSet != null && aSet.removeObject (sPrefix).isChanged ()) return EChange.CHANGED; throw new IllegalStateException ("Internal inconsistency removing '" + sPrefix + "' and '" + sNamespaceURI + "'"); }
Example #21
Source File: MimeTypeInfoManager.java From ph-commons with Apache License 2.0 | 5 votes |
/** * Get all mime types that are associated to the extension of the specified * filename. * * @param sFilename * The filename to search. May neither be <code>null</code> nor empty. * @return Never <code>null</code> but maybe empty set if no mime type is * associated with the extension of the passed filename. */ @Nonnull @ReturnsMutableCopy public ICommonsSet <String> getAllMimeTypeStringsForFilename (@Nonnull @Nonempty final String sFilename) { ValueEnforcer.notEmpty (sFilename, "Filename"); final String sExtension = FilenameHelper.getExtension (sFilename); return getAllMimeTypeStringsForExtension (sExtension); }
Example #22
Source File: UBL22DocumentTypes.java From ph-ubl with Apache License 2.0 | 5 votes |
/** * @return A non-<code>null</code> set of all supported UBL 2.2 namespaces. */ @Nonnull @ReturnsMutableCopy public static ICommonsSet <String> getAllNamespaces () { return s_aNamespace2DocType.copyOfKeySet (); }
Example #23
Source File: XMLCharsetDeterminator.java From ph-commons with Apache License 2.0 | 5 votes |
/** * @return A mutable Set with all charsets that can be used for the charset * determination. Never <code>null</code>. */ @Nonnull @ReturnsMutableCopy public static ICommonsSet <Charset> getAllSupportedCharsets () { return XML_CHARSETS.getClone (); }
Example #24
Source File: CombinationGeneratorFlexible.java From ph-commons with Apache License 2.0 | 5 votes |
/** * Generate all combinations without duplicates. * * @param aElements * the elements to distribute to the specified slots (may be empty!) * @return a set of slot allocations representing all possible combinations */ @Nonnull @ReturnsMutableCopy public ICommonsSet <ICommonsList <DATATYPE>> getCombinations (@Nonnull final ICommonsList <DATATYPE> aElements) { ValueEnforcer.notNull (aElements, "Elements"); final ICommonsSet <ICommonsList <DATATYPE>> aAllResults = new CommonsHashSet <> (); iterateAllCombinations (aElements, aAllResults::add); return aAllResults; }
Example #25
Source File: CountryCacheTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testNoConcurrentModificationString () { final ICommonsSet <Locale> aCountries = new CommonsHashSet <> (); for (final String sCountry : CountryCache.getInstance ().getAllCountries ()) aCountries.add (CountryCache.getInstance ().getCountry (sCountry)); for (final Locale aCountry : aCountries) { assertNotNull (aCountry); assertTrue (StringHelper.hasNoText (aCountry.getLanguage ())); assertTrue (StringHelper.hasText (aCountry.getCountry ())); assertTrue (StringHelper.hasNoText (aCountry.getVariant ())); } }
Example #26
Source File: UBL23DocumentTypes.java From ph-ubl with Apache License 2.0 | 5 votes |
/** * @return A non-<code>null</code> set of all supported UBL 2.3 document * element local names. */ @Nonnull @ReturnsMutableCopy public static ICommonsSet <String> getAllLocalNames () { return s_aLocalName2DocType.copyOfKeySet (); }
Example #27
Source File: DirectedGraphNode.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @ReturnsMutableCopy public ICommonsSet <IMutableDirectedGraphNode> getAllToNodes () { final ICommonsSet <IMutableDirectedGraphNode> ret = new CommonsHashSet <> (); if (m_aOutgoing != null) CollectionHelper.findAllMapped (m_aOutgoing.values (), IMutableDirectedGraphRelation::getTo, ret::add); return ret; }
Example #28
Source File: DirectedGraphNode.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @ReturnsMutableCopy public ICommonsSet <IMutableDirectedGraphNode> getAllFromNodes () { final ICommonsSet <IMutableDirectedGraphNode> ret = new CommonsHashSet <> (); if (m_aIncoming != null) CollectionHelper.findAllMapped (m_aIncoming.values (), IMutableDirectedGraphRelation::getFrom, ret::add); return ret; }
Example #29
Source File: SystemProperties.java From ph-commons with Apache License 2.0 | 5 votes |
/** * @return A copy of the set with all property names for which warnings were * emitted. */ @Nonnull @ReturnsMutableCopy public static ICommonsSet <String> getAllWarnedPropertyNames () { // Convert from CopyOnWrite to regular HashSet return new CommonsHashSet <> (s_aWarnedPropertyNames); }
Example #30
Source File: MultiTreeMapTreeSetBasedTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testAll () { IMultiMapSetBased <String, String, ? extends ICommonsSet <String>> aMultiMap = new MultiTreeMapTreeSetBased <> (); testEmpty (aMultiMap); aMultiMap = new MultiTreeMapTreeSetBased <> (getKey1 (), getValue1 ()); testOne (aMultiMap); aMultiMap = new MultiTreeMapTreeSetBased <> (getKey1 (), getValueSetNavigable1 ()); testOne (aMultiMap); aMultiMap = new MultiTreeMapTreeSetBased <> (getMapSetNavigable1 ()); testOne (aMultiMap); }