@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); }
private static Automaton dfaToDkAutomaton(TIntObjectMap<State> map, Machine machine) { dk.brics.automaton.Automaton dkAut = new dk.brics.automaton.Automaton(); APList aps = machine.getInAPs(); for(int stateNr = 0; stateNr < machine.getStateSize(); stateNr ++) { State state = getState(map, stateNr); // initial states if(machine.getInitialState() == stateNr) { dkAut.setInitialState(state); } // final states if(machine.getAcceptance().isFinal(stateNr)) { state.setAccept(true); } for (int letter = 0; letter < aps.size(); letter ++) { int succ = machine.getSuccessor(stateNr, letter); State stateSucc = getState(map, succ); state.addTransition(new Transition(aps.get(letter).toString().charAt(0), stateSucc)); } } dkAut.setDeterministic(true); return dkAut; }
public void createMesh(List<Mesher> meshers, JmeResourceManager resourceManager) { Realm realm = chunk.getRealm(); TIntObjectMap<Mesh> meshes = new TIntObjectHashMap<>(); for (Mesher mesher : meshers) { meshes.putAll(mesher.buildMeshes(chunk)); } geometries.clear(); for (int key : meshes.keys()) { Block block = realm.getCosmos().getBlocks().get(key); Geometry geometry = new Geometry(chunk.toString() + ":" + block.getName(), meshes.get(key)); geometry.setMaterial(resourceManager.getMaterial(block)); geometry.setQueueBucket(Bucket.Transparent); geometries.add(geometry); } }
@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> 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); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(map); ByteArrayInputStream bias = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bias); Map<Integer, String> deserialized = (Map<Integer, String>) ois.readObject(); assertEquals(map, deserialized); }
public void testContainsKey() { 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( "Key should be present: " + keys[i] + ", map: " + map, map.containsKey( keys[i] ) ); } int key = 1138; assertFalse( "Key should not be present: " + key + ", map: " + map, map.containsKey( key ) ); }
public void testPutAllMap() { int element_count = 20; int[] keys = new int[element_count]; String[] vals = new String[element_count]; TIntObjectMap<String> control = new TIntObjectHashMap<String>(); for ( int i = 0; i < element_count; i++ ) { keys[i] = i + 1; vals[i] = Integer.toString( i + 1 ); control.put( keys[i], vals[i] ); } TIntObjectMap<String> map = new TIntObjectHashMap<String>(); Map<Integer, String> source = new HashMap<Integer, String>(); for ( int i = 0; i < element_count; i++ ) { source.put( keys[i], vals[i] ); } map.putAll( source ); assertEquals( control, map ); }
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] ) ); }
public void testContainsKey() { 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); for (int i = 0; i < element_count; i++) { assertTrue("Key should be present: " + keys[i] + ", map: " + map, map.containsKey(keys[i])); } int key = 1138; assertFalse("Key should not be present: " + key + ", map: " + map, map.containsKey(key)); }
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() ); }
public void testTransformValues() { int element_count = 20; int[] keys = new int[element_count]; String[] vals = new String[element_count]; TIntObjectMap<String> 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 ); map.put( keys[i], vals[i] ); } assertEquals( element_count, map.size() ); map.transformValues( new TObjectFunction<String,String>() { @Override public String execute( String value ) { return value + "/" + value; } } ); for ( int i = 0; i < element_count; i++ ) { String expected = vals[i] + "/" + vals[i]; assertEquals( expected, map.get( keys[i] ) ); } }
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])); }
@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 ); }
public void testPutAllMap() { int element_count = 20; int[] keys = new int[element_count]; String[] vals = new String[element_count]; TIntObjectMap<String> raw_control = new TIntObjectHashMap<String>(); for (int i = 0; i < element_count; i++) { keys[i] = i + 1; vals[i] = Integer.toString(i + 1); raw_control.put(keys[i], vals[i]); } Map<Integer, String> control = TDecorators.wrap(raw_control); TIntObjectMap<String> raw_map = new TIntObjectHashMap<String>(); Map<Integer, String> map = TDecorators.wrap(raw_map); Map<Integer, String> source = new HashMap<Integer, String>(); for (int i = 0; i < element_count; i++) { source.put(keys[i], vals[i]); } map.putAll(source); assertEquals(control, map); }
public void testContainsValue() { 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); 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)); //noinspection SuspiciousMethodCalls assertFalse("Random object should not be present in map: " + map, map.containsValue(new Object())); }
public void testPutAll() throws Exception { TIntObjectMap<String> raw_t = new TIntObjectHashMap<String>(); Map<Integer, String> t = TDecorators.wrap(raw_t); TIntObjectMap<String> raw_m = new TIntObjectHashMap<String>(); Map<Integer, String> m = TDecorators.wrap(raw_m); m.put(2, "one"); m.put(4, "two"); m.put(6, "three"); t.put(5, "four"); assertEquals(1, t.size()); t.putAll(m); assertEquals(4, t.size()); assertEquals("two", t.get(4)); }
private static mt_other encodeOther(TIntObjectMap<metric_value> t_other, int timestampsSize) { LOG.log(Level.FINEST, "encoding {0}", TDecorators.wrap(t_other)); metric_value[] values = new metric_value[timestampsSize]; int values_len = 0; for (int i = 0; i < values.length; ++i) { metric_value mv = t_other.get(i); if (mv != null) values[values_len++] = mv; } mt_other result = new mt_other(); result.presence = createPresenceBitset(t_other.keySet(), timestampsSize); result.values = Arrays.copyOf(values, values_len); return result; }
public void testTransformValues() { int element_count = 20; int[] keys = new int[element_count]; String[] vals = new String[element_count]; TIntObjectMap<String> 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 ); map.put( keys[i], vals[i] ); } assertEquals( element_count, map.size() ); map.transformValues( new TObjectFunction<String,String>() { public String execute( String value ) { return value + "/" + value; } } ); for ( int i = 0; i < element_count; i++ ) { String expected = vals[i] + "/" + vals[i]; assertEquals( expected, map.get( keys[i] ) ); } }
/** {@inheritDoc} */ public boolean equals( Object other ) { if ( ! ( other instanceof TIntObjectMap ) ) { return false; } TIntObjectMap that = ( TIntObjectMap ) other; if ( that.size() != this.size() ) { return false; } try { TIntObjectIterator iter = this.iterator(); while ( iter.hasNext() ) { iter.advance(); int key = iter.key(); Object value = iter.value(); if ( value == null ) { if ( !( that.get( key ) == null && that.containsKey( key ) ) ) { return false; } } else { if ( !value.equals( that.get( key ) ) ) { return false; } } } } catch ( ClassCastException ex ) { // unused. } return true; }
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // MAP //noinspection unchecked _map = ( TIntObjectMap<V> ) in.readObject(); }
public boolean equals( Object other ) { if ( ! ( other instanceof TIntObjectMap ) ) { return false; } TIntObjectMap that = ( TIntObjectMap ) other; if ( that.size() != this.size() ) { return false; } try { TIntObjectIterator iter = this.iterator(); while ( iter.hasNext() ) { iter.advance(); int key = iter.key(); Object value = iter.value(); if ( value == null ) { if ( !( that.get( key ) == null && that.containsKey( key ) ) ) { return false; } } else { if ( !value.equals( that.get( key ) ) ) { return false; } } } } catch ( ClassCastException ex ) { // unused. } return true; }
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)); map.put(null, "null-key"); assertEquals("null-key", map.get(null)); }
protected MeshBuilder getBuilder(TIntObjectMap<MeshBuilder> builders, Block block) { MeshBuilder builder = builders.get(block.getId()); if (builder == null) { builder = createMeshBuilder(block); builders.put(block.getId(), builder); } return builder; }
private final void fillWithQuads( int[][] mask, int currentSlice, TIntObjectMap<MeshBuilder> builders, QuadCreator quadCreator) { for (int x = 0; x < mask.length; x++) { int[] row = mask[x]; for (int y = 0; y < row.length; y++) { int currentId = row[y]; Block block = realm.getCosmos().getBlock(currentId); if (block.getBlockType() == BlockType.CUBE) { int startX = x; int startY = y; int endY = findYEnd(row, currentId, startY); int endX = findXEnd(mask, currentId, startY, endY, x); y = endY - 1; MeshBuilder builder = getBuilder(builders, block); quadCreator.create( builder, startX, startY, endX, endY, currentSlice); } } } }
public void testConstructors() { 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] ); } TIntObjectMap<String> capacity = new TIntObjectHashMap<String>( 20 ); for ( int i = 0; i < element_count; i++ ) { capacity.put( keys[i], vals[i] ); } assertEquals( map, capacity ); TIntObjectMap<String> cap_and_factor = new TIntObjectHashMap<String>( 20, 0.75f ); for ( int i = 0; i < element_count; i++ ) { cap_and_factor.put( keys[i], vals[i] ); } assertEquals( map, cap_and_factor ); TIntObjectMap<String> fully_specified = new TIntObjectHashMap<String>( 20, 0.75f, Integer.MIN_VALUE ); for ( int i = 0; i < element_count; i++ ) { fully_specified.put( keys[i], vals[i] ); } assertEquals( map, fully_specified ); TIntObjectMap<String> copy = new TIntObjectHashMap<String>( map ); assertEquals( map, copy ); }
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 ) ); }
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 ) ); }