本文整理匯總了Java中gnu.trove.set.TIntSet.retainAll方法的典型用法代碼示例。如果您正苦於以下問題:Java TIntSet.retainAll方法的具體用法?Java TIntSet.retainAll怎麽用?Java TIntSet.retainAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gnu.trove.set.TIntSet
的用法示例。
在下文中一共展示了TIntSet.retainAll方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testKeySetRetainAllCollection
import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testKeySetRetainAllCollection() {
int element_count = 20;
int[] keys = new int[element_count];
String[] vals = new String[element_count];
TIntObjectMap<String> map = new TIntObjectHashMap<String>();
for ( int i = 0; i < element_count; i++ ) {
keys[i] = i + 1;
vals[i] = Integer.toString( i + 1 );
map.put( keys[i], vals[i] );
}
assertEquals( element_count, map.size() );
TIntSet keyset = map.keySet();
for ( int i = 0; i < keyset.size(); i++ ) {
assertTrue( keyset.contains( keys[i] ) );
}
assertFalse( keyset.isEmpty() );
Collection<Integer> test_collection = new HashSet<Integer>();
for ( int i = 0; i < element_count; i++ ) {
test_collection.add( keys[i] );
}
keyset.retainAll( test_collection );
assertFalse( keyset.isEmpty() );
assertFalse( map.isEmpty() );
// Reset map
for ( int i = 0; i < element_count; i++ ) {
map.put( keys[i], vals[i] );
}
assertEquals( element_count, map.size() );
test_collection.remove( Integer.valueOf( keys[5] ) );
keyset.retainAll( test_collection );
assertEquals( element_count - 1, keyset.size() );
assertEquals( element_count - 1, map.size() );
assertFalse( keyset.contains( keys[5] ) );
assertFalse( map.containsKey( keys[5] ) );
// Reset map
for ( int i = 0; i < element_count; i++ ) {
map.put( keys[i], vals[i] );
}
assertEquals( element_count, map.size() );
test_collection.add( Integer.valueOf( 1138 ) );
keyset.retainAll( test_collection );
}
示例2: testKeySetRetainAllCollection
import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testKeySetRetainAllCollection() {
int element_count = 20;
int[] keys = new int[element_count];
String[] vals = new String[element_count];
TIntObjectMap<String> map = new TIntObjectHashMap<String>();
for ( int i = 0; i < element_count; i++ ) {
keys[i] = i + 1;
vals[i] = Integer.toString( i + 1 );
map.put( keys[i], vals[i] );
}
assertEquals( element_count, map.size() );
TIntSet keyset = map.keySet();
for ( int i = 0; i < keyset.size(); i++ ) {
assertTrue( keyset.contains( keys[i] ) );
}
assertFalse( keyset.isEmpty() );
Collection<Integer> test_collection = new HashSet<Integer>();
for ( int i = 0; i < element_count; i++ ) {
test_collection.add( keys[i] );
}
keyset.retainAll( test_collection );
assertFalse( keyset.isEmpty() );
assertFalse( map.isEmpty() );
// Reset map
for ( int i = 0; i < element_count; i++ ) {
map.put( keys[i], vals[i] );
}
assertEquals( element_count, map.size() );
test_collection.remove( Integer.valueOf( keys[5] ) );
keyset.retainAll( test_collection );
assertEquals( element_count - 1, keyset.size() );
assertEquals( element_count - 1, map.size() );
assertFalse( keyset.contains( keys[5] ) );
assertFalse( map.containsKey( keys[5] ) );
// Reset map
for ( int i = 0; i < element_count; i++ ) {
map.put( keys[i], vals[i] );
}
assertEquals( element_count, map.size() );
test_collection.add( Integer.valueOf( 1138 ) );
keyset.retainAll( test_collection );
}