/** * Returns an iterator that will be {@linkplain FastEntrySet fast}, if possible, * on the {@linkplain Map#entrySet() entry set} of the provided {@code map}. * * @param map * a map from which we will try to extract a (fast) iterator on the * entry set. * @return an iterator on the entry set of the given map that will be fast, if * possible. * @since 8.0.0 */ @SuppressWarnings("unchecked") public static <V> ObjectIterator<Short2ObjectMap.Entry<V>> fastIterator(Short2ObjectMap<V> map) { final ObjectSet<Short2ObjectMap.Entry<V>> entries = map.short2ObjectEntrySet(); return entries instanceof Short2ObjectMap.FastEntrySet ? ((Short2ObjectMap.FastEntrySet<V>) entries).fastIterator() : entries.iterator(); } /**
/** * Iterates {@linkplain FastEntrySet#fastForEach(Consumer) quickly}, if * possible, on the {@linkplain Map#entrySet() entry set} of the provided * {@code map}. * * @param map * a map on which we will try to iterate * {@linkplain FastEntrySet#fastForEach(Consumer) quickly}. * @param consumer * the consumer that will be passed to * {@link FastEntrySet#fastForEach(Consumer)}, if possible, or to * {@link Iterable#forEach(Consumer)}. * @since 8.1.0 */ @SuppressWarnings("unchecked") public static <V> void fastForEach(Short2ObjectMap<V> map, final Consumer<? super Short2ObjectMap.Entry<V>> consumer) { final ObjectSet<Short2ObjectMap.Entry<V>> entries = map.short2ObjectEntrySet(); if (entries instanceof Short2ObjectMap.FastEntrySet) ((Short2ObjectMap.FastEntrySet<V>) entries).fastForEach(consumer); else entries.forEach(consumer); } /**
/** * Iterates quickly over this entry set; the iteration might happen always on * the same entry instance, suitably mutated. * * <p> * This default implementation just delegates to {@link #forEach(Consumer)}. * * @param consumer * a consumer that will by applied to the entries of this set; the * entries might be represented by the same entry instance, suitably * mutated. * @since 8.1.0 */ default void fastForEach(final Consumer<? super Short2ObjectMap.Entry<V>> consumer) { forEach(consumer); } }
public void tickTiles( long currentTimeMS ) { for ( ChunkSlice chunkSlice : this.chunkSlices ) { if ( chunkSlice != null && chunkSlice.getTileEntities() != null ) { ObjectIterator<Short2ObjectMap.Entry<TileEntity>> iterator = chunkSlice.getTileEntities().short2ObjectEntrySet().fastIterator(); while ( iterator.hasNext() ) { TileEntity tileEntity = iterator.next().getValue(); tileEntity.update( currentTimeMS ); if ( tileEntity.isNeedsPersistence() ) { this.needsPersistance = true; } } } } }