@SuppressWarnings({"unchecked"}) public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // SUPER super.readExternal( in ); // NO_ENTRY_KEY no_entry_key = in.readShort(); // NUMBER OF ENTRIES int size = in.readInt(); setUp( size ); // ENTRIES while (size-- > 0) { short key = in.readShort(); V val = (V) in.readObject(); put(key, val); } }
/** {@inheritDoc} */ public boolean containsKey( short key ) { return contains( key ); }
@SuppressWarnings({"unchecked"}) public boolean remove( Object o ) { return removeElement( (E) o ); }
/** {@inheritDoc} */ @SuppressWarnings({"unchecked"}) public boolean retainEntries( TShortObjectProcedure<? super V> procedure ) { boolean modified = false; byte[] states = _states; short[] keys = _set; V[] values = _values; // Temporarily disable compaction. This is a fix for bug #1738760 tempDisableAutoCompaction(); try { for ( int i = keys.length; i-- > 0; ) { if ( states[i] == FULL && ! procedure.execute( keys[i], values[i] ) ) { removeAt( i ); modified = true; } } } finally { reenableAutoCompaction( true ); } return modified; }
/** {@inheritDoc} */ public boolean equals( Object other ) { if ( ! ( other instanceof TShortObjectMap ) ) { return false; } TShortObjectMap that = ( TShortObjectMap ) other; if ( that.size() != this.size() ) { return false; } try { TShortObjectIterator iter = this.iterator(); while ( iter.hasNext() ) { iter.advance(); short 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 boolean execute( short key, V value) { put( key, value ); return true; } };
@Override @SideOnly(Side.CLIENT) public void registerModels() { super.registerModels(); TShortObjectHashMap<ModelResourceLocation> alreadyRegistered = new TShortObjectHashMap<>(); for (short metaItem : generatedItems) { OrePrefix prefix = this.orePrefixes[metaItem / 1000]; MaterialIconSet materialIconSet = Material.MATERIAL_REGISTRY.getObjectById(metaItem % 1000).materialIconSet; short registrationKey = (short) (metaItem / 1000 * 1000 + materialIconSet.ordinal()); if (!alreadyRegistered.containsKey(registrationKey)) { ResourceLocation resourceLocation = prefix.materialIconType.getItemModelPath(materialIconSet); ModelBakery.registerItemVariants(this, resourceLocation); alreadyRegistered.put(registrationKey, new ModelResourceLocation(resourceLocation, "inventory")); } ModelResourceLocation resourceLocation = alreadyRegistered.get(registrationKey); metaItemsModels.put(metaItem, resourceLocation); } }
@Test public void testCompleteUpdateSendsBlockAddedEvents() throws Exception { final Chunk chunk = mockChunkAt(0, 0, 0); final short blockId = 42; final EntityRef blockEntity = mock(EntityRef.class); registerBlockWithIdAndEntity(blockId, blockEntity, blockManager); final TShortObjectHashMap<TIntList> blockPositionMappings = new TShortObjectHashMap<>(); blockPositionMappings.put(blockId, withPositions(new Vector3i(1, 2, 3))); final ReadyChunkInfo readyChunkInfo = ReadyChunkInfo.createForRestoredChunk(chunk, blockPositionMappings, mock(ChunkStore.class), Collections.emptyList()); when(chunkFinalizer.completeFinalization()).thenReturn(readyChunkInfo); chunkProvider.completeUpdate(); final ArgumentCaptor<Event> eventArgumentCaptor = ArgumentCaptor.forClass(Event.class); verify(blockEntity, atLeastOnce()).send(eventArgumentCaptor.capture()); final Event event = eventArgumentCaptor.getAllValues().get(0); assertThat(event, instanceOf(OnAddedBlocks.class)); assertThat(((OnAddedBlocks) event).getBlockPositions(), hasItem(new Vector3i(1, 2, 3))); }
/** {@inheritDoc} */ public V get( short key ) { int index = index( key ); return index < 0 ? null : _values[index]; }
/** * Creates a new <code>TShortObjectHashMap</code> that contains the entries * in the map passed to it. * * @param map the <tt>TShortObjectMap</tt> to be copied. */ public TShortObjectHashMap( TShortObjectMap<? extends V> map ) { this( map.size(), 0.5f, map.getNoEntryKey() ); putAll( map ); }
/** {@inheritDoc} */ public boolean forEachKey( TShortProcedure procedure ) { return forEach( procedure ); }
@SuppressWarnings({"unchecked"}) private V doPut( V value, int index ) { V previous = null; boolean isNewMapping = true; if ( index < 0 ) { index = -index -1; previous = _values[index]; isNewMapping = false; } _values[index] = value; if (isNewMapping) { postInsertHook( consumeFreeSlot ); } return previous; }
public String toString() { final StringBuilder buf = new StringBuilder("{"); forEachEntry(new TShortObjectProcedure<V>() { private boolean first = true; public boolean execute(short key, Object value) { if ( first ) first = false; else buf.append( "," ); buf.append(key); buf.append("="); buf.append(value); return true; } }); buf.append("}"); return buf.toString(); } } // TShortObjectHashMap
resourceLocations[i] = new ModelResourceLocation(resourceLocation, "inventory"); specialItemsModels.put((short) (metaItemOffset + itemMetaKey), resourceLocations); continue; if(specialItemsModels.containsKey(itemDamage)) { int modelIndex = getModelIndex((short) (itemDamage - metaItemOffset), itemStack); return specialItemsModels.get(itemDamage)[modelIndex];
/** {@inheritDoc} */ public V put( short key, V value ) { int index = insertionIndex( key ); return doPut( key, value, index ); }
/** {@inheritDoc} */ @SuppressWarnings({"unchecked"}) public boolean retainEntries( TShortObjectProcedure<? super V> procedure ) { boolean modified = false; byte[] states = _states; short[] keys = _set; V[] values = _values; // Temporarily disable compaction. This is a fix for bug #1738760 tempDisableAutoCompaction(); try { for ( int i = keys.length; i-- > 0; ) { if ( states[i] == FULL && ! procedure.execute( keys[i], values[i] ) ) { removeAt( i ); modified = true; } } } finally { reenableAutoCompaction( true ); } return modified; }
@SuppressWarnings({"unchecked"}) public boolean remove( Object o ) { return removeElement( (E) o ); }
/** {@inheritDoc} */ public boolean equals( Object other ) { if ( ! ( other instanceof TShortObjectMap ) ) { return false; } TShortObjectMap that = ( TShortObjectMap ) other; if ( that.size() != this.size() ) { return false; } try { TShortObjectIterator iter = this.iterator(); while ( iter.hasNext() ) { iter.advance(); short 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; }
/** {@inheritDoc} */ public void putAll( Map<? extends Short, ? extends V> map ) { Set<? extends Map.Entry<? extends Short,? extends V>> set = map.entrySet(); for ( Map.Entry<? extends Short,? extends V> entry : set ) { put( entry.getKey(), entry.getValue() ); } }