本文整理汇总了Java中com.helger.commons.collection.impl.CommonsHashSet类的典型用法代码示例。如果您正苦于以下问题:Java CommonsHashSet类的具体用法?Java CommonsHashSet怎么用?Java CommonsHashSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommonsHashSet类属于com.helger.commons.collection.impl包,在下文中一共展示了CommonsHashSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: _testPutRandom
import com.helger.commons.collection.impl.CommonsHashSet; //导入依赖的package包/类
private void _testPutRandom (final float fillFactor)
{
final Random aRandom = RandomHelper.getRandom ();
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]));
}
示例2: _testPutRandom
import com.helger.commons.collection.impl.CommonsHashSet; //导入依赖的package包/类
private void _testPutRandom (final float fillFactor)
{
final Random aRandom = RandomHelper.getRandom ();
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);
}
示例3: _testPutRandom
import com.helger.commons.collection.impl.CommonsHashSet; //导入依赖的package包/类
private void _testPutRandom (final float fillFactor)
{
final Random aRandom = RandomHelper.getRandom ();
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);
}
示例4: _testPutRandom
import com.helger.commons.collection.impl.CommonsHashSet; //导入依赖的package包/类
private void _testPutRandom (final float fillFactor)
{
final Random aRandom = RandomHelper.getRandom ();
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]));
}
示例5: _addMapping
import com.helger.commons.collection.impl.CommonsHashSet; //导入依赖的package包/类
@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;
}
示例6: testStringCombination2
import com.helger.commons.collection.impl.CommonsHashSet; //导入依赖的package包/类
@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 ());
}
示例7: testRedundancy
import com.helger.commons.collection.impl.CommonsHashSet; //导入依赖的package包/类
@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));
}
示例8: testList
import com.helger.commons.collection.impl.CommonsHashSet; //导入依赖的package包/类
@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")));
}
示例9: testSet
import com.helger.commons.collection.impl.CommonsHashSet; //导入依赖的package包/类
@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")));
}
示例10: testMap
import com.helger.commons.collection.impl.CommonsHashSet; //导入依赖的package包/类
@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")));
}
示例11: testArray
import com.helger.commons.collection.impl.CommonsHashSet; //导入依赖的package包/类
@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")));
}
示例12: testIterable
import com.helger.commons.collection.impl.CommonsHashSet; //导入依赖的package包/类
@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")));
}
示例13: testCtor
import com.helger.commons.collection.impl.CommonsHashSet; //导入依赖的package包/类
@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 ());
}
示例14: testGetDifference
import com.helger.commons.collection.impl.CommonsHashSet; //导入依赖的package包/类
@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 (ret.size (), 2);
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 ());
}
示例15: testAll
import com.helger.commons.collection.impl.CommonsHashSet; //导入依赖的package包/类
@Test
public void testAll ()
{
// Ensure they are unique....
final boolean bOld = RandomHelper.isUseSecureRandom ();
RandomHelper.setUseSecureRandom (false);
try
{
final ICommonsSet <String> aAll = new CommonsHashSet <> ();
for (int i = 0; i < 1000; i++)
assertTrue (aAll.add (AuthTokenIDGenerator.generateNewTokenID ()));
}
finally
{
RandomHelper.setUseSecureRandom (bOld);
}
}