当前位置: 首页>>代码示例>>Java>>正文


Java TIntObjectMap.put方法代码示例

本文整理汇总了Java中gnu.trove.map.TIntObjectMap.put方法的典型用法代码示例。如果您正苦于以下问题:Java TIntObjectMap.put方法的具体用法?Java TIntObjectMap.put怎么用?Java TIntObjectMap.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gnu.trove.map.TIntObjectMap的用法示例。


在下文中一共展示了TIntObjectMap.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testClear

import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testClear() {
    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() );

    map.clear();
    assertTrue( map.isEmpty() );
    assertEquals( 0, map.size() );

    assertNull( map.get( keys[5] ) );
}
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:20,代码来源:TPrimitiveObjectHashMapTest.java

示例2: testClear

import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testClear() {
    int element_count = 20;
    int[] keys = new int[element_count];
    String[] vals = new String[element_count];

    TIntObjectMap<String> raw_map = new TIntObjectHashMap<String>();
    for (int i = 0; i < element_count; i++) {
        keys[i] = i + 1;
        vals[i] = Integer.toString(i + 1);
        raw_map.put(keys[i], vals[i]);
    }
    Map<Integer, String> map = TDecorators.wrap(raw_map);
    assertEquals(element_count, map.size());

    map.clear();
    assertTrue(map.isEmpty());
    assertEquals(0, map.size());

    assertNull(map.get(keys[5]));
}
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:21,代码来源:TPrimitiveObjectMapDecoratorTest.java

示例3: testSerialize

import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked"})
public void testSerialize() throws Exception {
    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] );
    }

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream( baos );
    oos.writeObject( map );

    ByteArrayInputStream bias = new ByteArrayInputStream( baos.toByteArray() );
    ObjectInputStream ois = new ObjectInputStream( bias );

    TIntObjectMap<String> deserialized = (TIntObjectMap<String>) ois.readObject();

    assertEquals( map, deserialized );
}
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:25,代码来源:TPrimitiveObjectHashMapTest.java

示例4: testGet

import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testGet() {
    int element_count = 20;
    int[] keys = new int[element_count];
    String[] vals = new String[element_count];

    TIntObjectMap<String> raw_map = new TIntObjectHashMap<String>();
    for (int i = 0; i < element_count; i++) {
        keys[i] = i + 1;
        vals[i] = Integer.toString(i + 1);
        raw_map.put(keys[i], vals[i]);
    }
    Map<Integer, String> map = TDecorators.wrap(raw_map);

    assertEquals(vals[10], map.get(Integer.valueOf(keys[10])));
    assertNull(map.get(Integer.valueOf(1138)));

    Integer key = Integer.valueOf(1138);
    map.put(key, null);
    assertTrue(map.containsKey(key));
    assertNull(map.get(key));

    Long long_key = Long.valueOf(1138);
    //noinspection SuspiciousMethodCalls
    assertNull(map.get(long_key));
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:26,代码来源:TPrimitiveObjectMapDecoratorTest.java

示例5: testValueCollectionRetainAllTCollection

import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testValueCollectionRetainAllTCollection() {
    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() );

    Collection<String> collection = map.valueCollection();
    for ( int i = 0; i < collection.size(); i++ ) {
        assertTrue( collection.contains( vals[i] ) );
    }
    assertFalse( collection.isEmpty() );

    assertFalse( "collection: " + collection + ", should be unmodified.",
            collection.retainAll( collection ) );

    Collection<String> other = new ArrayList<String>( collection );
    assertFalse( "collection: " + collection + ", should be unmodified. other: " +
                 other, collection.retainAll( other ) );

    other.remove( vals[5] );
    assertTrue( "collection: " + collection + ", should be modified. other: " +
                other, collection.retainAll( other ) );
    assertFalse( collection.contains( vals[5] ) );
    assertFalse( map.containsKey( keys[5] ) );
    assertFalse( map.containsValue( vals[5] ) );
    assertTrue( "collection: " + collection + ", should contain all in other: " +
                other, collection.containsAll( other ) );
}
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:36,代码来源:TPrimitiveObjectHashMapTest.java

示例6: testValueCollectionRemoveAllCollection

import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testValueCollectionRemoveAllCollection() {
    int element_count = 20;
    int[] keys = new int[element_count];
    String[] vals = new String[element_count];

    TIntObjectMap<String> raw_map = new TIntObjectHashMap<String>();
    for (int i = 0; i < element_count; i++) {
        keys[i] = i + 1;
        vals[i] = Integer.toString(i + 1);
        raw_map.put(keys[i], vals[i]);
    }
    Map<Integer, String> map = TDecorators.wrap(raw_map);
    assertEquals(element_count, map.size());

    Collection<String> collection = map.values();
    for (int i = 0; i < collection.size(); i++) {
        assertTrue(collection.contains(vals[i]));
    }
    assertFalse(collection.isEmpty());

    List<String> java_list = new ArrayList<String>();
    assertFalse("collection: " + collection + ", should contain all in list: " +
            java_list, collection.removeAll(java_list));

    java_list.add(vals[5]);
    assertTrue("collection: " + collection + ", should contain all in list: " +
            java_list, collection.removeAll(java_list));
    assertFalse(collection.contains(vals[5]));
    assertFalse(map.containsKey(keys[5]));
    assertFalse(map.containsValue(vals[5]));

    java_list = new ArrayList<String>();
    java_list.addAll(Arrays.asList(vals));
    assertTrue("collection: " + collection + ", should contain all in list: " +
            java_list, collection.removeAll(java_list));
    assertTrue(collection.isEmpty());
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:38,代码来源:TPrimitiveObjectMapDecoratorTest.java

示例7: testValueCollectionRemoveAllCollection

import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testValueCollectionRemoveAllCollection() {
    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() );

    Collection<String> collection = map.valueCollection();
    for ( int i = 0; i < collection.size(); i++ ) {
        assertTrue( collection.contains( vals[i] ) );
    }
    assertFalse( collection.isEmpty() );

    List<String> java_list = new ArrayList<String>();
    assertFalse( "collection: " + collection + ", should contain all in list: " +
                 java_list, collection.removeAll( java_list ) );

    java_list.add( vals[5] );
    assertTrue( "collection: " + collection + ", should contain all in list: " +
                java_list, collection.removeAll( java_list ) );
    assertFalse( collection.contains( vals[5] ) );
    assertFalse( map.containsKey( keys[5] ) );
    assertFalse( map.containsValue( vals[5] ) );

    java_list = new ArrayList<String>();
    java_list.addAll( Arrays.asList( vals ) );
    assertTrue( "collection: " + collection + ", should contain all in list: " +
                java_list, collection.removeAll( java_list ) );
    assertTrue( collection.isEmpty() );
}
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:37,代码来源:TPrimitiveObjectHashMapTest.java

示例8: testTPrimitiveObjectHashMapSerialize

import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testTPrimitiveObjectHashMapSerialize() throws Exception {
    int[] keys = {1138, 42, 86, 99, 101, 727, 117};
    String[] vals = new String[keys.length];

    TIntObjectMap<String> original_map =
            new TIntObjectHashMap<String>( 200, 0.75f, Integer.MIN_VALUE );
    for ( int i = 0; i < keys.length; i++ ) {
        vals[i] = String.valueOf( keys[i] * 2 );
        original_map.put( keys[i], vals[i] );
    }

    THash original_hash = ( THash ) original_map;

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream( baos );
    oos.writeObject( original_map );

    ByteArrayInputStream bias = new ByteArrayInputStream( baos.toByteArray() );
    ObjectInputStream ois = new ObjectInputStream( bias );

    TIntObjectMap deserialized_map = ( TIntObjectMap ) ois.readObject();
    THash deserialized_hash = ( THash ) deserialized_map;

    assertEquals( original_map, deserialized_map );
    assertEquals( original_map.getNoEntryKey(), deserialized_map.getNoEntryKey() );
    assertEquals( original_hash._loadFactor, deserialized_hash._loadFactor );
}
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:28,代码来源:THashTest.java

示例9: testEquals

import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testEquals() {
    int element_count = 20;
    int[] keys = new int[element_count];
    String[] vals = new String[element_count];

    TIntObjectMap<String> raw_map =
            new TIntObjectHashMap<String>(element_count, 0.5f, Integer.MIN_VALUE);
    for (int i = 0; i < element_count; i++) {
        keys[i] = i + 1;
        vals[i] = Integer.toString(i + 1);
        raw_map.put(keys[i], vals[i]);
    }
    Map<Integer, String> map = TDecorators.wrap(raw_map);
    assertEquals(element_count, map.size());

    TIntObjectHashMap<String> raw_fully_specified =
            new TIntObjectHashMap<String>(20, 0.75f, Integer.MIN_VALUE);
    for (int i = 0; i < element_count; i++) {
        raw_fully_specified.put(keys[i], vals[i]);
    }
    Map<Integer, String> fully_specified = TDecorators.wrap(raw_fully_specified);
    assertEquals(map, fully_specified);

    assertFalse("shouldn't equal random object", map.equals(new Object()));

    assertSame(raw_map, ((TIntObjectMapDecorator) map).getMap());
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:28,代码来源:TPrimitiveObjectMapDecoratorTest.java

示例10: testPutIfAbsent

import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testPutIfAbsent() {
    TIntObjectMap<String> map = new TIntObjectHashMap<String>();

    map.put( 1, "One" );
    map.put( 2, "Two" );
    map.put( 3, "Three" );

    assertEquals( "One", map.putIfAbsent( 1, "Two" ) );
    assertEquals( "One", map.get( 1 ) );
    assertEquals( null, map.putIfAbsent( 9, "Nine") );
    assertEquals( "Nine", map.get( 9 ) );
}
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:13,代码来源:TPrimitiveObjectHashMapTest.java

示例11: 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:leventov,项目名称:trove-over-koloboke-compile,代码行数:35,代码来源:TPrimitiveObjectHashMapTest.java

示例12: testContainsValue

import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testContainsValue() {
    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] );
    }

    for ( int i = 0; i < element_count; i++ ) {
        assertTrue( "Value should be present: " + vals[i] + ", map: " + map,
                map.containsValue( vals[i] ) );
    }

    String val = "1138";
    assertFalse( "Key should not be present: " + val + ", map: " + map,
            map.containsValue( val ) );

    assertFalse( "Random object should not be present in map: " + map,
            map.containsValue( new Object() ) );

    // test with null value
    int key = 11010110;
    map.put( key, null );
    assertTrue( map.containsKey( key ) );
    assertTrue( map.containsValue( null ) );
    assertNull( map.get( key ) );
}
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:32,代码来源:TPrimitiveObjectHashMapTest.java

示例13: 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

示例14: testValueCollectionRetainAllCollection

import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testValueCollectionRetainAllCollection() {
    int element_count = 20;
    int[] keys = new int[element_count];
    String[] vals = new String[element_count];

    TIntObjectMap<String> raw_map = new TIntObjectHashMap<String>();
    for (int i = 0; i < element_count; i++) {
        keys[i] = i + 1;
        vals[i] = Integer.toString(i + 1);
        raw_map.put(keys[i], vals[i]);
    }
    Map<Integer, String> map = TDecorators.wrap(raw_map);
    assertEquals(element_count, map.size());

    Collection<String> collection = map.values();
    for (int i = 0; i < collection.size(); i++) {
        assertTrue(collection.contains(vals[i]));
    }
    assertFalse(collection.isEmpty());

    List<String> java_list = new ArrayList<String>();
    java_list.addAll(Arrays.asList(vals));
    assertFalse("collection: " + collection + ", should contain all in list: " +
            java_list, collection.retainAll(java_list));

    java_list.remove(5);
    assertTrue("collection: " + collection + ", should contain all in list: " +
            java_list, collection.retainAll(java_list));
    assertFalse(collection.contains(vals[5]));
    assertFalse(map.containsKey(keys[5]));
    assertFalse(map.containsValue(vals[5]));
    assertTrue("collection: " + collection + ", should contain all in list: " +
            java_list, collection.containsAll(java_list));
}
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:35,代码来源:TPrimitiveObjectMapDecoratorTest.java

示例15: testHashCode

import gnu.trove.map.TIntObjectMap; //导入方法依赖的package包/类
public void testHashCode() {
    int element_count = 20;
    int[] keys = new int[element_count];
    String[] vals = new String[element_count];
    int counter = 0;

    TIntObjectMap<String> map =
            new TIntObjectHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE );
    for ( int i = 0; i < element_count; i++, counter++ ) {
        keys[i] = counter + 1;
        vals[i] = Integer.toString( counter + 1 );
        map.put( keys[i], vals[i] );
    }
    assertEquals( element_count, map.size() );
    assertEquals( map.hashCode(), map.hashCode() );

    Map<String, TIntObjectMap<String>> string_tmap_map =
            new HashMap<String, TIntObjectMap<String>>();
    string_tmap_map.put( "first", map );
    string_tmap_map.put( "second", map );
    assertSame( map, string_tmap_map.get( "first" ) );
    assertSame( map, string_tmap_map.get( "second" ) );

    TIntObjectMap<String> map2 =
            new TIntObjectHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE );
    for ( int i = 0; i < element_count; i++, counter++ ) {
        keys[i] = counter + 1;
        vals[i] = Integer.toString( counter + 1 );
        map2.put( keys[i], vals[i] );
    }
    assertEquals( element_count, map2.size() );
    assertEquals( map2.hashCode(), map2.hashCode() );

    TIntObjectMap<String> map3 =
            new TIntObjectHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE );
    for ( int i = 0; i < element_count; i++, counter++ ) {
        keys[i] = counter + 1;
        vals[i] = Integer.toString( counter + 1 );
        map3.put( keys[i], vals[i] );
    }
    assertEquals( element_count, map3.size() );
    assertEquals( map3.hashCode(), map3.hashCode() );

    assertFalse( "hashcodes are unlikely equal.  map: " + map + " (" + map.hashCode() +
                 ")\nmap2: " + map2 + " (" + map2.hashCode() + ")",
            map.hashCode() == map2.hashCode() );
    assertFalse( "hashcodes are unlikely equal.  map: " + map + " (" + map.hashCode() +
                 ")\nmap3: " + map3 + " (" + map3.hashCode() + ")",
            map.hashCode() == map3.hashCode() );
    assertFalse( "hashcodes are unlikely equal.  map2: " + map2 + " (" + map2.hashCode() +
                 ")\nmap3: " + map3 + " (" + map3.hashCode() + ")",
            map2.hashCode() == map3.hashCode() );

    Map<TIntObjectMap<String>, String> tmap_string_map =
            new HashMap<TIntObjectMap<String>, String>();
    tmap_string_map.put( map, "map1" );
    tmap_string_map.put( map2, "map2" );
    tmap_string_map.put( map3, "map3" );
    assertEquals( "map1", tmap_string_map.get( map ) );
    assertEquals( "map2", tmap_string_map.get( map2 ) );
    assertEquals( "map3", tmap_string_map.get( map3 ) );
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:63,代码来源:TPrimitiveObjectHashMapTest.java


注:本文中的gnu.trove.map.TIntObjectMap.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。