com.helger.commons.collection.impl.CommonsHashSet Java Examples
The following examples show how to use
com.helger.commons.collection.impl.CommonsHashSet.
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: 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 #2
Source File: EqualsHelperTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testIterable () { final Iterable <String> aCont = new MockIterable ("a", "b", "c"); assertTrue (EqualsHelper.equalsCollection (aCont, aCont)); assertTrue (EqualsHelper.equalsCollection (aCont, new MockIterable ("a", "b", "c"))); assertTrue (EqualsHelper.equalsCollection (new MockIterable (), new MockIterable ())); assertFalse (EqualsHelper.equalsCollection (aCont, new MockIterable ())); assertFalse (EqualsHelper.equalsCollection (new MockIterable (), aCont)); assertFalse (EqualsHelper.equalsCollection (aCont, new MockIterable ("a", "b"))); assertFalse (EqualsHelper.equalsCollection (aCont, new MockIterable ("A", "b", "c"))); assertFalse (EqualsHelper.equalsCollection (aCont, new MockIterable ("a", "B", "c"))); assertFalse (EqualsHelper.equalsCollection (aCont, new MockIterable ("a", "b", "C"))); assertFalse (EqualsHelper.equalsCollection (aCont, new MockIterable ("a", "b", "c", "d"))); assertFalse (EqualsHelper.equalsCollection (aCont, new CommonsHashSet <> ("a", "b", "c"))); assertFalse (EqualsHelper.equalsCollection (aCont, ArrayHelper.newArray ("a", "b", "c"))); }
Example #3
Source File: EqualsHelperTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testArray () { final String [] aArray = ArrayHelper.newArray ("a", "b", "c"); assertTrue (EqualsHelper.equalsCollection (aArray, aArray)); assertTrue (EqualsHelper.equalsCollection (aArray, ArrayHelper.newArray ("a", "b", "c"))); assertTrue (EqualsHelper.equalsCollection (new String [0], new String [] {})); assertFalse (EqualsHelper.equalsCollection (aArray, new String [0])); assertFalse (EqualsHelper.equalsCollection (new String [0], aArray)); assertFalse (EqualsHelper.equalsCollection (aArray, ArrayHelper.newArray ("a", "b"))); assertFalse (EqualsHelper.equalsCollection (aArray, ArrayHelper.newArray ("A", "b", "c"))); assertFalse (EqualsHelper.equalsCollection (aArray, ArrayHelper.newArray ("a", "B", "c"))); assertFalse (EqualsHelper.equalsCollection (aArray, ArrayHelper.newArray ("a", "b", "C"))); assertFalse (EqualsHelper.equalsCollection (aArray, ArrayHelper.newArray ("a", "b", "c", "d"))); assertFalse (EqualsHelper.equalsCollection (aArray, new CommonsArrayList <> ("a", "b", "c"))); assertFalse (EqualsHelper.equalsCollection (aArray, new CommonsHashSet <> ("a", "b", "c"))); }
Example #4
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 #5
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 #6
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 #7
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 #8
Source File: MapBasedNamespaceContext.java From ph-commons with Apache License 2.0 | 6 votes |
@Nonnull private MapBasedNamespaceContext _addMapping (@Nonnull final String sPrefix, @Nonnull final String sNamespaceURI, final boolean bAllowOverwrite) { ValueEnforcer.notNull (sPrefix, "Prefix"); ValueEnforcer.notNull (sNamespaceURI, "NamespaceURI"); if (!bAllowOverwrite && m_aPrefix2NS.containsKey (sPrefix)) throw new IllegalArgumentException ("The prefix '" + sPrefix + "' is already registered to '" + m_aPrefix2NS.get (sPrefix) + "'!"); if (sPrefix.equals (XMLConstants.DEFAULT_NS_PREFIX)) m_sDefaultNamespaceURI = sNamespaceURI; m_aPrefix2NS.put (sPrefix, sNamespaceURI); m_aNS2Prefix.computeIfAbsent (sNamespaceURI, x -> new CommonsHashSet <> ()).add (sPrefix); return this; }
Example #9
Source File: NonBlockingStackTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testCtor () { NonBlockingStack <String> st = new NonBlockingStack <> (); assertTrue (st.isEmpty ()); assertFalse (st.iterator ().hasNext ()); st = new NonBlockingStack <> ("s", "t"); assertEquals (2, st.size ()); assertEquals ("s", st.firstElement ()); assertTrue (st.iterator ().hasNext ()); st = new NonBlockingStack <> ((String []) null); assertTrue (st.isEmpty ()); assertFalse (st.iterator ().hasNext ()); st = new NonBlockingStack <> (new CommonsArrayList <> ("s", "t")); assertEquals (2, st.size ()); assertEquals ("s", st.firstElement ()); assertTrue (st.iterator ().hasNext ()); st = new NonBlockingStack <> (new CommonsHashSet <String> ()); assertTrue (st.isEmpty ()); assertFalse (st.iterator ().hasNext ()); st = new NonBlockingStack <> (new NonBlockingStack <> ("s", "t")); assertEquals (2, st.size ()); assertEquals ("s", st.firstElement ()); assertTrue (st.iterator ().hasNext ()); }
Example #10
Source File: CollectionHelperTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testGetDifference () { final ICommonsList <String> l1 = newList ("Hello", "Welt", "from", "Vienna"); final ICommonsList <String> l2 = newList ("Welt", "from"); // Result should be "Hello" and "Vienna" final Set <String> ret = getDifference (l1, l2); assertNotNull (ret); assertEquals (2, ret.size ()); assertTrue (ret.contains ("Hello")); assertFalse (ret.contains ("Welt")); assertFalse (ret.contains ("from")); assertTrue (ret.contains ("Vienna")); assertEquals (4, getDifference (l1, new CommonsVector <String> ()).size ()); assertEquals (4, getDifference (l1, null).size ()); assertEquals (0, getDifference (new CommonsHashSet <String> (), l2).size ()); assertEquals (0, getDifference (null, l2).size ()); }
Example #11
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 #12
Source File: IntDoubleMapTest.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 Set <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 IntDoubleMap map = _makeMap (100, fillFactor); for (i = 0; i < vals.length; ++i) { assertEquals ("Inserting " + vals[i], IntDoubleMap.NO_VALUE, map.put (vals[i], vals[i]), DELTA); assertEquals (i + 1, map.size ()); assertEquals (vals[i], map.get (vals[i]), DELTA); } // now check the final state for (i = 0; i < vals.length; ++i) assertEquals (vals[i], map.get (vals[i]), DELTA); }
Example #13
Source File: IntFloatMapTest.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 Set <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 IntFloatMap map = _makeMap (100, fillFactor); for (i = 0; i < vals.length; ++i) { assertEquals ("Inserting " + vals[i], IntFloatMap.NO_VALUE, map.put (vals[i], vals[i]), DELTA); assertEquals (i + 1, map.size ()); assertEquals (vals[i], map.get (vals[i]), DELTA); } // now check the final state for (i = 0; i < vals.length; ++i) assertEquals (vals[i], map.get (vals[i]), DELTA); }
Example #14
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 #15
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 #16
Source File: EUBL22DocumentTypeTest.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 EUBL22DocumentType e : EUBL22DocumentType.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, EUBL22DocumentType.valueOf (e.name ())); assertTrue (aClasses.add (e.getImplementationClass ())); assertTrue (aFilenames.add (e.getAllXSDResources ().getFirst ().getPath ())); } }
Example #17
Source File: CSSPropertyEnum.java From ph-css with Apache License 2.0 | 5 votes |
public CSSPropertyEnum (@Nonnull final ECSSProperty eProp, @Nullable final ECSSVendorPrefix eVendorPrefix, @Nullable final ICSSPropertyCustomizer aCustomizer, @Nonnull @Nonempty final String... aEnumValues) { super (eProp, eVendorPrefix, aCustomizer); ValueEnforcer.notEmptyNoNullValue (aEnumValues, "EnumValues"); m_aEnumValues = new CommonsHashSet <> (aEnumValues.length); for (final String sPotentialValue : aEnumValues) { if (StringHelper.hasNoText (sPotentialValue)) throw new IllegalArgumentException ("At least one enumeration value is empty"); m_aEnumValues.add (sPotentialValue); } }
Example #18
Source File: CollectionHelperTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testIsEmptyCollection () { assertTrue (isEmpty ((Collection <?>) null)); assertTrue (isEmpty ((Map <?, ?>) null)); assertTrue (isEmpty (new CommonsArrayList <String> ())); assertTrue (isEmpty (new CommonsVector <String> ())); assertTrue (isEmpty (new CommonsHashSet <String> ())); assertTrue (isEmpty (new CommonsTreeSet <String> ())); assertTrue (isEmpty (new CommonsHashMap <String, String> ())); assertTrue (isEmpty (new CommonsLinkedHashMap <String, String> ())); assertFalse (isEmpty (newList ("Hallo"))); assertFalse (isEmpty (newMap ("Hallo", "Welt"))); }
Example #19
Source File: TypeConverterTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testShortArray () { final short [] aShorts = new short [] { 4, 5, 4 }; assertFalse (TypeConverter.convert (aShorts, List.class).isEmpty ()); assertFalse (TypeConverter.convert (aShorts, CommonsArrayList.class).isEmpty ()); assertFalse (TypeConverter.convert (aShorts, Set.class).isEmpty ()); assertFalse (TypeConverter.convert (aShorts, CommonsHashSet.class).isEmpty ()); assertFalse (TypeConverter.convert (aShorts, CommonsLinkedHashSet.class).isEmpty ()); assertEquals (3, TypeConverter.convert (aShorts, String [].class).length); }
Example #20
Source File: TypeConverterTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testLongArray () { final long [] aLongs = new long [] { 10, 111, 1212 }; assertFalse (TypeConverter.convert (aLongs, List.class).isEmpty ()); assertFalse (TypeConverter.convert (aLongs, CommonsArrayList.class).isEmpty ()); assertFalse (TypeConverter.convert (aLongs, Set.class).isEmpty ()); assertFalse (TypeConverter.convert (aLongs, CommonsHashSet.class).isEmpty ()); assertFalse (TypeConverter.convert (aLongs, CommonsLinkedHashSet.class).isEmpty ()); assertEquals (3, TypeConverter.convert (aLongs, String [].class).length); }
Example #21
Source File: CollectionHelperTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testFirstAndLast () { final ICommonsList <String> aList = newList ("s1", "s2", "s3"); final Set <String> aSet = new CommonsLinkedHashSet <> (aList); assertNull (removeFirstElement (new CommonsArrayList <String> ())); assertNull (removeFirstElement ((ICommonsList <String>) null)); assertEquals ("s1", getFirstElement (aList)); assertEquals ("s1", getFirstElement (aSet)); assertEquals ("s1", getFirstElement ((Iterable <String>) aSet)); assertEquals ("s1", removeFirstElement (aList)); assertNull (getFirstElement (new CommonsArrayList <String> ())); assertNull (getFirstElement (new CommonsHashSet <String> ())); assertNull (getFirstElement ((Iterable <String>) new CommonsHashSet <String> ())); assertNull (getFirstElement ((ICommonsList <String>) null)); assertNull (getFirstElement ((Set <String>) null)); assertNull (getFirstElement ((Iterable <String>) null)); assertNull (removeLastElement (new CommonsArrayList <> ())); assertNull (removeLastElement ((ICommonsList <String>) null)); assertEquals ("s3", getLastElement (aList)); assertEquals ("s3", getLastElement (aSet)); assertEquals ("s3", getLastElement ((Iterable <String>) aSet)); assertEquals ("s3", removeLastElement (aList)); assertNull (getLastElement (new CommonsArrayList <String> ())); assertNull (getLastElement (new CommonsHashSet <String> ())); assertNull (getLastElement ((Iterable <String>) new CommonsHashSet <String> ())); assertNull (getLastElement ((ICommonsList <String>) null)); assertNull (getLastElement ((Set <String>) null)); assertNull (getLastElement ((Iterable <String>) null)); }
Example #22
Source File: PrimitiveCollectionHelper.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @ReturnsMutableCopy public static CommonsHashSet <Integer> newPrimitiveSet (@Nullable final int... aValues) { final CommonsHashSet <Integer> ret = new CommonsHashSet <> (); if (aValues != null) for (final int aValue : aValues) ret.add (Integer.valueOf (aValue)); return ret; }
Example #23
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 #24
Source File: EqualsHelperTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testArrayComplex () { final ICommonsList <String> [] aArray = ArrayHelper.newArray (new CommonsArrayList <> ("a", "b"), new CommonsArrayList <> ("c", "d")); assertTrue (EqualsHelper.equalsCollection (aArray, aArray)); assertTrue (EqualsHelper.equalsCollection (aArray, ArrayHelper.newArray (new CommonsArrayList <> ("a", "b"), new CommonsArrayList <> ("c", "d")))); assertTrue (EqualsHelper.equalsCollection (new ICommonsList <?> [0], new ICommonsList <?> [] {})); assertFalse (EqualsHelper.equalsCollection (aArray, new ICommonsList <?> [0])); assertFalse (EqualsHelper.equalsCollection (new ICommonsList <?> [0], aArray)); assertFalse (EqualsHelper.equalsCollection (aArray, ArrayHelper.newArray (new CommonsArrayList <> ("a", "b")))); assertFalse (EqualsHelper.equalsCollection (aArray, ArrayHelper.newArray (new CommonsArrayList <> ("A", "b"), new CommonsArrayList <> ("c", "d")))); assertFalse (EqualsHelper.equalsCollection (aArray, ArrayHelper.newArray (new CommonsArrayList <> ("a", "b"), new CommonsArrayList <> ("c", "D")))); assertFalse (EqualsHelper.equalsCollection (aArray, ArrayHelper.newArray (new CommonsArrayList <> ("a", "b"), new CommonsArrayList <> ("c", "d"), new CommonsArrayList <> ("e", "f")))); assertFalse (EqualsHelper.equalsCollection (aArray, ArrayHelper.newArray (new CommonsArrayList <> ("a", "b"), (ICommonsList <String>) null))); assertFalse (EqualsHelper.equalsCollection (aArray, new CommonsArrayList <> ("a", "b", "c"))); assertFalse (EqualsHelper.equalsCollection (aArray, new CommonsHashSet <> ("a", "b", "c"))); assertFalse (EqualsHelper.equalsCollection (aArray, ArrayHelper.newArray ("a", "b", "c"))); assertFalse (EqualsHelper.equalsCollection (aArray, ArrayHelper.newArray ("a", null, "c"))); }
Example #25
Source File: SingleElementMap.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @ReturnsMutableCopy @CodingStyleguideUnaware public Set <Map.Entry <KEYTYPE, VALUETYPE>> entrySet () { final ICommonsSet <Map.Entry <KEYTYPE, VALUETYPE>> aSet = new CommonsHashSet <> (size ()); if (m_bHasElement) aSet.add (new MapEntry <> (m_aKey, m_aValue)); return aSet; }
Example #26
Source File: PrimitiveCollectionHelper.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @ReturnsMutableCopy public static CommonsHashSet <Long> newPrimitiveSet (@Nullable final long... aValues) { final CommonsHashSet <Long> ret = new CommonsHashSet <> (); if (aValues != null) for (final long aValue : aValues) ret.add (Long.valueOf (aValue)); return ret; }
Example #27
Source File: PrimitiveCollectionHelper.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @ReturnsMutableCopy public static CommonsHashSet <Short> newPrimitiveSet (@Nullable final short... aValues) { final CommonsHashSet <Short> ret = new CommonsHashSet <> (); if (aValues != null) for (final short aValue : aValues) ret.add (Short.valueOf (aValue)); return ret; }
Example #28
Source File: StringHelperTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testExplodeToOrderedSet () { ICommonsOrderedSet <String> ret = StringHelper.getExplodedToOrderedSet ("@", "a@b@@c"); assertEquals (new CommonsHashSet <> ("a", "b", "", "c"), ret); ret = StringHelper.getExplodedToOrderedSet ("uu", "auubuuuuuuc"); assertEquals (new CommonsHashSet <> ("a", "b", "", "", "c"), ret); ret = StringHelper.getExplodedToOrderedSet (".", "a.b...c"); assertEquals (new CommonsHashSet <> ("a", "b", "", "", "c"), ret); ret = StringHelper.getExplodedToOrderedSet ("o", "boo:and:foo"); assertEquals (new CommonsHashSet <> ("b", "", ":and:f", "", ""), ret); ret = StringHelper.getExplodedToOrderedSet ("@", "@a@b@@c"); assertEquals (new CommonsHashSet <> ("", "a", "b", "", "c"), ret); ret = StringHelper.getExplodedToOrderedSet ("@", "a@b@@c@"); assertEquals (new CommonsHashSet <> ("a", "b", "", "c", ""), ret); ret = StringHelper.getExplodedToOrderedSet ("@", "@a@b@@c@"); assertEquals (new CommonsHashSet <> ("", "a", "b", "", "c", ""), ret); assertTrue (StringHelper.getExplodedToOrderedSet ("@", null).isEmpty ()); try { StringHelper.getExplodedToOrderedSet (null, "@a@b@@c@"); fail (); } catch (final NullPointerException ex) {} }
Example #29
Source File: StringHelperTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testExplodeToSet () { ICommonsSet <String> ret = StringHelper.getExplodedToSet ("@", "a@b@@c"); assertEquals (new CommonsHashSet <> ("a", "b", "", "c"), ret); ret = StringHelper.getExplodedToSet ("uu", "auubuuuuuuc"); assertEquals (new CommonsHashSet <> ("a", "b", "", "", "c"), ret); ret = StringHelper.getExplodedToSet (".", "a.b...c"); assertEquals (new CommonsHashSet <> ("a", "b", "", "", "c"), ret); ret = StringHelper.getExplodedToSet ("o", "boo:and:foo"); assertEquals (new CommonsHashSet <> ("b", "", ":and:f", "", ""), ret); ret = StringHelper.getExplodedToSet ("@", "@a@b@@c"); assertEquals (new CommonsHashSet <> ("", "a", "b", "", "c"), ret); ret = StringHelper.getExplodedToSet ("@", "a@b@@c@"); assertEquals (new CommonsHashSet <> ("a", "b", "", "c", ""), ret); ret = StringHelper.getExplodedToSet ("@", "@a@b@@c@"); assertEquals (new CommonsHashSet <> ("", "a", "b", "", "c", ""), ret); assertTrue (StringHelper.getExplodedToSet ("@", null).isEmpty ()); try { StringHelper.getExplodedToSet (null, "@a@b@@c@"); fail (); } catch (final NullPointerException ex) {} }
Example #30
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); }