本文整理汇总了Java中gnu.trove.map.TIntObjectMap.keySet方法的典型用法代码示例。如果您正苦于以下问题:Java TIntObjectMap.keySet方法的具体用法?Java TIntObjectMap.keySet怎么用?Java TIntObjectMap.keySet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnu.trove.map.TIntObjectMap
的用法示例。
在下文中一共展示了TIntObjectMap.keySet方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testKeySetHashCode
import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testKeySetHashCode() {
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() );
assertEquals( keyset.hashCode(), keyset.hashCode() );
TIntSet other = new TIntHashSet( keys );
other.add( 1138 );
assertTrue( keyset.hashCode() != other.hashCode() );
}
示例2: testKeySetContainsAllCollection
import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testKeySetContainsAllCollection() {
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] );
}
assertTrue( keyset.containsAll( test_collection ) ) ;
test_collection.remove( Integer.valueOf( keys[5] ) );
assertTrue( "should contain all. keyset: " + keyset + ", " + test_collection,
keyset.containsAll( test_collection ) );
test_collection.add( Integer.valueOf( 1138 ) );
assertFalse( "should not contain all. keyset: " + keyset + ", " + test_collection,
keyset.containsAll( test_collection ) );
}
示例3: testKeySetContainsAllTCollection
import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testKeySetContainsAllTCollection() {
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() );
TIntCollection test_collection = new TIntHashSet();
for ( int i = 0; i < element_count; i++ ) {
test_collection.add( keys[i] );
}
assertTrue( keyset.containsAll( test_collection ) ) ;
assertTrue( keyset.equals( keyset ) );
test_collection.remove( Integer.valueOf( keys[5] ) );
assertTrue( "should contain all. keyset: " + keyset + ", " + test_collection,
keyset.containsAll( test_collection ) );
test_collection.add( 1138 );
assertFalse( "should not contain all. keyset: " + keyset + ", " + test_collection,
keyset.containsAll( test_collection ) );
}
示例4: testKeySetContainsAllArray
import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testKeySetContainsAllArray() {
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() );
assertTrue( "should contain all. keyset: " + keyset + ", " + Arrays.toString( keys ),
keyset.containsAll( keys ) );
int[] other_array = new int[ keys.length + 1 ];
System.arraycopy( keys, 0, other_array, 0, keys.length );
other_array[other_array.length - 1] = 1138;
assertFalse( "should not contain all. keyset: " + keyset + ", " + Arrays.toString( other_array ),
keyset.containsAll( other_array ) );
}
示例5: testKeySetRetainAllTCollection
import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testKeySetRetainAllTCollection() {
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() );
assertFalse( "keyset: " + keyset + ", should be unmodified.",
keyset.retainAll( keyset ) );
TIntCollection other = new TIntArrayList( keyset );
assertFalse( "keyset: " + keyset + ", should be unmodified. other: " +
other, keyset.retainAll( other ) );
other.remove( keys[5] );
assertTrue( "keyset: " + keyset + ", should be modified. other: " +
other, keyset.retainAll( other ) );
assertFalse( keyset.contains( keys[5] ) );
assertFalse( map.containsKey( keys[5] ) );
assertFalse( map.containsValue( vals[5] ) );
assertTrue( "keyset: " + keyset + ", should contain all in other: " +
other, keyset.containsAll( other ) );
}
示例6: testKeySetRetainAllArray
import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testKeySetRetainAllArray() {
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() );
assertFalse( "keyset: " + keyset + ", should be unmodified. array: " +
Arrays.toString( keys ), keyset.retainAll( keys ) );
int[] other = new int[element_count - 1];
for ( int i = 0; i < element_count; i++ ) {
if ( i < 5 ) {
other[i] = i + 1;
}
if ( i > 5 ) {
other[i - 1] = i + 1;
}
}
assertTrue( "keyset: " + keyset + ", should be modified. array: " +
Arrays.toString( other ), keyset.retainAll( other ) );
}
示例7: testKeySetRemoveAllCollection
import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testKeySetRemoveAllCollection() {
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() );
TIntCollection keyset = map.keySet();
for ( int i = 0; i < keyset.size(); i++ ) {
assertTrue( keyset.contains( keys[i] ) );
}
assertFalse( keyset.isEmpty() );
List<Integer> java_list = new ArrayList<Integer>();
assertFalse( "collection: " + keyset + ", should contain all in list: " +
java_list, keyset.removeAll( java_list ) );
java_list.add( keys[5] );
assertTrue( "collection: " + keyset + ", should contain all in list: " +
java_list, keyset.removeAll( java_list ) );
assertFalse( keyset.contains( keys[5] ) );
assertFalse( map.containsKey( keys[5] ) );
assertFalse( map.containsValue( vals[5] ) );
java_list = new ArrayList<Integer>();
for ( int key : keys ) {
java_list.add( key );
}
assertTrue( "collection: " + keyset + ", should contain all in list: " +
java_list, keyset.removeAll( java_list ) );
assertTrue( keyset.isEmpty() );
}
示例8: testKeySetEqual
import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testKeySetEqual() {
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() );
TIntSet other = new TIntHashSet();
other.addAll( keys );
assertTrue( "sets incorrectly not equal: " + keyset + ", " + other,
keyset.equals( other ) );
int[] mismatched = {72, 49, 53, 1024, 999};
TIntSet unequal = new TIntHashSet();
unequal.addAll( mismatched );
assertFalse( "sets incorrectly equal: " + keyset + ", " + unequal,
keyset.equals( unequal ) );
// Change length, different code branch
unequal.add( 1 );
assertFalse( "sets incorrectly equal: " + keyset + ", " + unequal,
keyset.equals( unequal ) );
//noinspection ObjectEqualsNull
assertFalse( keyset.equals( null ) );
}
示例9: testKeySetRetainAllCollection
import gnu.trove.map.TIntObjectMap; //导入方法依赖的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 );
}
示例10: testKeySetRemoveAllTCollection
import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testKeySetRemoveAllTCollection() {
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() );
TIntCollection keyset = map.keySet();
for ( int i = 0; i < keyset.size(); i++ ) {
assertTrue( keyset.contains( keys[i] ) );
}
assertFalse( keyset.isEmpty() );
TIntCollection other = new TIntArrayList();
assertFalse( "collection: " + keyset + ", should be unmodified.",
keyset.removeAll( other ) );
other = new TIntArrayList( keyset );
other.remove( keys[5] );
assertTrue( "collection: " + keyset + ", should be modified. other: " +
other, keyset.removeAll( other ) );
assertEquals( 1, keyset.size() );
for ( int i = 0; i < element_count; i++ ) {
if ( i == 5 ) {
assertTrue( keyset.contains( keys[i] ) );
assertTrue( map.containsKey( keys[i] ) );
assertTrue( map.containsValue( vals[i] ) );
} else {
assertFalse( keyset.contains( keys[i] ) );
assertFalse( map.containsKey( keys[i] ) );
assertFalse( map.containsValue( vals[i] ) );
}
}
assertFalse( "collection: " + keyset + ", should be unmodified. other: " +
other, keyset.removeAll( other ) );
assertTrue( "collection: " + keyset + ", should be modified. other: " +
other, keyset.removeAll( keyset ) );
assertTrue( keyset.isEmpty() );
}
示例11: testKeySetRemoveAllArray
import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testKeySetRemoveAllArray() {
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() );
TIntCollection keyset = map.keySet();
for ( int i = 0; i < keyset.size(); i++ ) {
assertTrue( keyset.contains( keys[i] ) );
}
assertFalse( keyset.isEmpty() );
int[] other = {1138};
assertFalse( "collection: " + keyset + ", should be unmodified. array: " +
Arrays.toString( vals ), keyset.removeAll( other ) );
other = new int[element_count - 1];
for ( int i = 0; i < element_count; i++ ) {
if ( i < 5 ) {
other[i] = i + 1;
}
if ( i > 5 ) {
other[i - 1] = i + 1;
}
}
assertTrue( "collection: " + keyset + ", should be modified. array: " +
Arrays.toString( other ), keyset.removeAll( other ) );
assertEquals( 1, keyset.size() );
for ( int i = 0; i < element_count; i++ ) {
if ( i == 5 ) {
assertTrue( keyset.contains( keys[i] ) );
assertTrue( map.containsKey( keys[i] ) );
assertTrue( map.containsValue( vals[i] ) );
} else {
assertFalse( keyset.contains( keys[i] ) );
assertFalse( map.containsKey( keys[i] ) );
assertFalse( map.containsValue( vals[i] ) );
}
}
}