本文整理匯總了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] ) );
}
示例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]));
}
示例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 );
}
示例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));
}
示例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 ) );
}
示例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());
}
示例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() );
}
示例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 );
}
示例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());
}
示例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 ) );
}
示例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 ) );
}
示例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 ) );
}
示例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 ) );
}
示例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));
}
示例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 ) );
}