當前位置: 首頁>>代碼示例>>Java>>正文


Java TIntObjectMap.keySet方法代碼示例

本文整理匯總了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() );
}
 
開發者ID:palantir,項目名稱:trove-3.0.3,代碼行數:26,代碼來源:TPrimitiveObjectHashMapTest.java

示例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 ) );
}
 
開發者ID:palantir,項目名稱:trove-3.0.3,代碼行數:34,代碼來源:TPrimitiveObjectHashMapTest.java

示例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 ) );
}
 
開發者ID:palantir,項目名稱:trove-3.0.3,代碼行數:35,代碼來源:TPrimitiveObjectHashMapTest.java

示例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 ) );
}
 
開發者ID:palantir,項目名稱:trove-3.0.3,代碼行數:29,代碼來源:TPrimitiveObjectHashMapTest.java

示例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 ) );
}
 
開發者ID:palantir,項目名稱:trove-3.0.3,代碼行數:36,代碼來源:TPrimitiveObjectHashMapTest.java

示例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 ) );
}
 
開發者ID:palantir,項目名稱:trove-3.0.3,代碼行數:35,代碼來源:TPrimitiveObjectHashMapTest.java

示例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() );
}
 
開發者ID:palantir,項目名稱:trove-3.0.3,代碼行數:39,代碼來源:TPrimitiveObjectHashMapTest.java

示例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 ) );
}
 
開發者ID:palantir,項目名稱:trove-3.0.3,代碼行數:41,代碼來源:TPrimitiveObjectHashMapTest.java

示例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 );

}
 
開發者ID:palantir,項目名稱:trove-3.0.3,代碼行數:52,代碼來源:TPrimitiveObjectHashMapTest.java

示例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() );
}
 
開發者ID:palantir,項目名稱:trove-3.0.3,代碼行數:48,代碼來源:TPrimitiveObjectHashMapTest.java

示例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] ) );
        }
    }
}
 
開發者ID:palantir,項目名稱:trove-3.0.3,代碼行數:48,代碼來源:TPrimitiveObjectHashMapTest.java


注:本文中的gnu.trove.map.TIntObjectMap.keySet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。