本文整理匯總了Java中gnu.trove.map.TObjectIntMap類的典型用法代碼示例。如果您正苦於以下問題:Java TObjectIntMap類的具體用法?Java TObjectIntMap怎麽用?Java TObjectIntMap使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TObjectIntMap類屬於gnu.trove.map包,在下文中一共展示了TObjectIntMap類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: injectListener
import gnu.trove.map.TObjectIntMap; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private void injectListener(int version) throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException {
Field protocolsField = Protocol.LOGIN.TO_SERVER.getClass().getDeclaredField("protocols");
protocolsField.setAccessible(true);
TIntObjectMap<?> protocols = (TIntObjectMap)protocolsField.get(Protocol.LOGIN.TO_SERVER);
Object protocolData = protocols.get(version);
Field packetMapField = protocolData.getClass().getDeclaredField("packetMap");
Field packetConstructorsField = protocolData.getClass().getDeclaredField("packetConstructors");
packetMapField.setAccessible(true);
packetConstructorsField.setAccessible(true);
TObjectIntMap packetMap = (TObjectIntMap)packetMapField.get(protocolData);
TIntObjectMap packetConstructors = (TIntObjectMap)packetConstructorsField.get(protocolData);
packetMap.remove(EncryptionResponse.class);
packetConstructors.remove(0x01);
packetMap.put( EncryptionResponsePacket.class, 0x01);
packetConstructors.put( 0x01, EncryptionResponsePacket.class.getDeclaredConstructor() );
packetMapField.set(protocolData, packetMap);
packetConstructorsField.set(protocolData, packetConstructors);
protocolsField.set(Protocol.LOGIN.TO_SERVER, protocols);
}
示例2: buildAccessors
import gnu.trove.map.TObjectIntMap; //導入依賴的package包/類
private static TObjectIntMap<String> buildAccessors(int accessFlags) {
TObjectIntMap<String> map = new TObjectIntHashMap<>();
map.put("public", Modifier.isPublic(accessFlags) ? 1 : 0);
map.put("protected", Modifier.isProtected(accessFlags) ? 1 : 0);
map.put("private", Modifier.isPrivate(accessFlags) ? 1 : 0);
map.put("final", Modifier.isFinal(accessFlags) ? 1 : 0);
map.put("interface", Modifier.isInterface(accessFlags) ? 1 : 0);
map.put("native", Modifier.isNative(accessFlags) ? 1 : 0);
map.put("static", Modifier.isStatic(accessFlags) ? 1 : 0);
map.put("strict", Modifier.isStrict(accessFlags) ? 1 : 0);
map.put("synchronized", Modifier.isSynchronized(accessFlags) ? 1 : 0);
map.put("transient", Modifier.isTransient(accessFlags) ? 1 : 0);
map.put("volatile", Modifier.isVolatile(accessFlags) ? 1 : 0);
map.put("abstract", Modifier.isAbstract(accessFlags) ? 1 : 0);
return map;
}
示例3: TObjectIntCustomHashMap
import gnu.trove.map.TObjectIntMap; //導入依賴的package包/類
/**
* Creates a new <code>TObjectIntCustomHashMap</code> that contains the entries
* in the map passed to it.
*
* @param map the <tt>TObjectIntMap</tt> to be copied.
*/
public TObjectIntCustomHashMap( HashingStrategy<? super K> strategy,
TObjectIntMap<? extends K> map ) {
this( strategy, map.size(), 0.5f, map.getNoEntryValue() );
if ( map instanceof TObjectIntCustomHashMap ) {
TObjectIntCustomHashMap hashmap = ( TObjectIntCustomHashMap ) map;
this._loadFactor = hashmap._loadFactor;
this.no_entry_value = hashmap.no_entry_value;
this.strategy = hashmap.strategy;
//noinspection RedundantCast
if ( this.no_entry_value != ( int ) 0 ) {
Arrays.fill( _values, this.no_entry_value );
}
setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) );
}
putAll( map );
}
示例4: testArray
import gnu.trove.map.TObjectIntMap; //導入依賴的package包/類
public void testArray() {
char[] foo = new char[] { 'a', 'b', 'c' };
char[] bar = new char[] { 'a', 'b', 'c' };
assertFalse( foo.hashCode() == bar.hashCode() );
//noinspection ArrayEquals
assertFalse( foo.equals( bar ) );
HashingStrategy<char[]> strategy = new ArrayHashingStrategy();
assertTrue( strategy.computeHashCode( foo ) ==
strategy.computeHashCode( bar ) );
assertTrue( strategy.equals( foo, bar ) );
TObjectIntMap<char[]> map = new TObjectIntCustomHashMap<char[]>( strategy );
map.put( foo, 12 );
assertTrue( map.containsKey( foo ) );
assertTrue( map.containsKey( bar ) );
assertEquals( 12, map.get( foo ) );
assertEquals( 12, map.get( bar ) );
Set<char[]> keys = map.keySet();
assertTrue( keys.contains( foo ) );
assertTrue( keys.contains( bar ) );
}
示例5: testAdjustToNoEntry
import gnu.trove.map.TObjectIntMap; //導入依賴的package包/類
public void testAdjustToNoEntry() {
TObjectIntMap<String> map = new TObjectIntHashMap<String>();
assertEquals( 0, map.getNoEntryValue() );
assertEquals( 0, map.get( "NotInThere" ) );
map.put( "Value", 1 );
assertEquals( 1, map.size() );
assertEquals( 1, map.get( "Value" ) );
assertTrue( map.containsKey( "Value" ) );
assertTrue( map.containsValue( 1 ) );
assertTrue( Arrays.equals( new int[] { 1 }, map.values() ) );
map.adjustValue( "Value", -1 );
assertEquals( 1, map.size() );
assertEquals( 0, map.get( "Value" ) );
assertTrue( map.containsKey( "Value" ) );
assertTrue( map.containsValue( 0 ) );
assertTrue( Arrays.equals( new int[] { 0 }, map.values() ) );
}
示例6: testContainsKey
import gnu.trove.map.TObjectIntMap; //導入依賴的package包/類
public void testContainsKey() {
int element_count = 20;
String[] keys = new String[element_count];
int[] vals = new int[element_count];
TObjectIntMap<String> map = new TObjectIntHashMap<String>();
for ( int i = 0; i < element_count; i++ ) {
keys[i] = Integer.toString( i + 1 );
vals[i] = i + 1;
map.put( keys[i], vals[i] );
}
for ( int i = 0; i < element_count; i++ ) {
assertTrue( "Key should be present: " + keys[i] + ", map: " + map,
map.containsKey( keys[i] ) );
}
String key = "1138";
assertFalse( "Key should not be present: " + key + ", map: " + map,
map.containsKey( key ) );
assertFalse( "Random object should not be present in map: " + map,
map.containsKey( new Object() ) );
}
示例7: testContainsValue
import gnu.trove.map.TObjectIntMap; //導入依賴的package包/類
public void testContainsValue() {
int element_count = 20;
String[] keys = new String[element_count];
int[] vals = new int[element_count];
TObjectIntMap<String> map = new TObjectIntHashMap<String>();
for ( int i = 0; i < element_count; i++ ) {
keys[i] = Integer.toString( i + 1 );
vals[i] = 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] ) );
}
int val = 1138;
assertFalse( "Key should not be present: " + val + ", map: " + map,
map.containsValue( val ) );
}
示例8: testPutAllMap
import gnu.trove.map.TObjectIntMap; //導入依賴的package包/類
public void testPutAllMap() {
int element_count = 20;
String[] keys = new String[element_count];
int[] vals = new int[element_count];
TObjectIntMap<String> control = new TObjectIntHashMap<String>();
for ( int i = 0; i < element_count; i++ ) {
keys[i] = Integer.toString( i + 1 );
vals[i] = i + 1;
control.put( keys[i], vals[i] );
}
TObjectIntMap<String> map = new TObjectIntHashMap<String>();
Map<String, Integer> source = new HashMap<String, Integer>();
for ( int i = 0; i < element_count; i++ ) {
source.put( keys[i], vals[i] );
}
map.putAll( source );
assertEquals( control, map );
}
示例9: testClear
import gnu.trove.map.TObjectIntMap; //導入依賴的package包/類
public void testClear() {
int element_count = 20;
String[] keys = new String[element_count];
int[] vals = new int[element_count];
TObjectIntMap<String> map = new TObjectIntHashMap<String>();
for ( int i = 0; i < element_count; i++ ) {
keys[i] = Integer.toString( i + 1 );
vals[i] = i + 1;
map.put( keys[i], vals[i] );
}
assertEquals( element_count, map.size() );
map.clear();
assertTrue( map.isEmpty() );
assertEquals( 0, map.size() );
assertEquals( map.getNoEntryValue(), map.get( keys[5] ) );
}
示例10: testIncrement
import gnu.trove.map.TObjectIntMap; //導入依賴的package包/類
public void testIncrement() {
int element_count = 20;
String[] keys = new String[element_count];
int[] vals = new int[element_count];
TObjectIntMap<String> map =
new TObjectIntHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE );
for ( int i = 0; i < element_count; i++ ) {
keys[i] = Integer.toString( i + 1 );
vals[i] = i + 1;
map.put( keys[i], vals[i] );
}
assertEquals( element_count, map.size() );
assertFalse( map.increment( "non-existant" ) );
assertTrue( map.increment( "1" ) );
assertEquals( 2, map.get( "1" ) );
}
示例11: testTransformValues
import gnu.trove.map.TObjectIntMap; //導入依賴的package包/類
public void testTransformValues() {
int element_count = 20;
String[] keys = new String[element_count];
int[] vals = new int[element_count];
TObjectIntMap<String> map =
new TObjectIntHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE );
for ( int i = 0; i < element_count; i++ ) {
keys[i] = Integer.toString( i + 1 );
vals[i] = i + 1;
map.put( keys[i], vals[i] );
}
assertEquals( element_count, map.size() );
map.transformValues( new TIntFunction() {
@Override
public int execute( int value ) {
return value * value;
}
} );
for ( int i = 0; i < element_count; i++ ) {
int expected = vals[i] * vals[i];
assertEquals( expected, map.get( keys[i] ) );
}
}
示例12: testValues
import gnu.trove.map.TObjectIntMap; //導入依賴的package包/類
public void testValues() {
int element_count = 20;
String[] keys = new String[element_count];
Integer[] vals = new Integer[element_count];
TObjectIntMap<String> raw_map =
new TObjectIntHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE );
Map<String,Integer> map = TDecorators.wrap( raw_map );
for ( int i = 0; i < element_count; i++ ) {
keys[i] = Integer.toString( i + 1 );
vals[i] = Integer.valueOf( i + 1 );
map.put( keys[i], vals[i] );
}
assertEquals( element_count, map.size() );
// No argument
Collection<Integer> values_collection = map.values();
assertEquals( element_count, values_collection.size() );
List<Integer> values_list = new ArrayList<Integer>( values_collection );
for ( int i = 0; i < element_count; i++ ) {
assertTrue( values_list.contains( vals[i] ) );
}
}
示例13: testSerialize
import gnu.trove.map.TObjectIntMap; //導入依賴的package包/類
@SuppressWarnings({"unchecked"})
public void testSerialize() throws Exception {
Integer[] keys = {1138, 42, 86, 99, 101, 727, 117};
int[] vals = new int[keys.length];
TObjectIntMap<Integer> map = new TObjectIntHashMap<Integer>();
for ( int i = 0; i < keys.length; i++ ) {
vals[i] = keys[i] * 2;
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 );
TObjectIntMap<Integer> deserialized = (TObjectIntMap<Integer>) ois.readObject();
assertEquals( map, deserialized );
}
示例14: testGetMap
import gnu.trove.map.TObjectIntMap; //導入依賴的package包/類
public void testGetMap() {
int element_count = 20;
String[] keys = new String[element_count];
int[] vals = new int[element_count];
TObjectIntMap<String> raw_map = new TObjectIntHashMap<String>();
for ( int i = 0; i < element_count; i++ ) {
keys[i] = Integer.toString( i + 1 );
vals[i] = i + 1;
raw_map.put( keys[i], vals[i] );
}
//noinspection MismatchedQueryAndUpdateOfCollection
TObjectIntMapDecorator<String> map = new TObjectIntMapDecorator<String>( raw_map );
assertEquals( raw_map, map.getMap() );
}
示例15: testPutAllMap
import gnu.trove.map.TObjectIntMap; //導入依賴的package包/類
public void testPutAllMap() {
int element_count = 20;
String[] keys = new String[element_count];
int[] vals = new int[element_count];
TObjectIntMap<String> control = new TObjectIntHashMap<String>();
for ( int i = 0; i < element_count; i++ ) {
keys[i] = Integer.toString( i + 1 );
vals[i] = i + 1;
control.put( keys[i], vals[i] );
}
TObjectIntMap<String> raw_map = new TObjectIntHashMap<String>();
Map<String,Integer> map = TDecorators.wrap( raw_map );
Map<String, Integer> source = new HashMap<String, Integer>();
for ( int i = 0; i < element_count; i++ ) {
source.put( keys[i], vals[i] );
}
map.putAll( source );
assertEquals( source, map );
assertEquals( control, raw_map );
}