Java Code Examples for it.unimi.dsi.fastutil.objects.ObjectIterator#hasNext()
The following examples show how to use
it.unimi.dsi.fastutil.objects.ObjectIterator#hasNext() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FastCollectionsUtils.java From fastjgame with Apache License 2.0 | 6 votes |
/** * 移除map中符合条件的元素,并对删除的元素执行后续的操作 * * @param map 必须是可修改的map * @param predicate 过滤条件,为真的删除 * @param then 元素删除之后执行的逻辑 * @param <V> the type of value * @return 删除的元素数量 */ public static <V> int removeIfAndThen(final Int2ObjectMap<V> map, final IntObjPredicate<? super V> predicate, IntObjConsumer<V> then) { if (map.size() == 0) { return 0; } ObjectIterator<Int2ObjectMap.Entry<V>> itr = map.int2ObjectEntrySet().iterator(); int removeNum = 0; Int2ObjectMap.Entry<V> entry; int k; V v; while (itr.hasNext()) { entry = itr.next(); k = entry.getIntKey(); v = entry.getValue(); if (predicate.test(k, v)) { itr.remove(); removeNum++; then.accept(k, v); } } return removeNum; }
Example 2
Source File: BukkitBridge.java From BungeeTabListPlus with GNU General Public License v3.0 | 6 votes |
@Override @Nullable Server getConnection() { synchronized (this) { ObjectIterator<Server> iterator = connections.iterator(); while (iterator.hasNext()) { Server server = iterator.next(); if (server.isConnected()) { return server; } else { iterator.remove(); } } return null; } }
Example 3
Source File: TeleporterPaths.java From TFC2 with GNU General Public License v3.0 | 6 votes |
/** * called periodically to remove out-of-date portal locations from the cache list. Argument par1 is a * WorldServer.getTotalWorldTime() value. */ @Override public void removeStalePortalLocations(long worldTime) { if (worldTime % 100L == 0L) { long i = worldTime - 600L; ObjectIterator<Teleporter.PortalPosition> objectiterator = this.destinationCoordinateCache.values().iterator(); while (objectiterator.hasNext()) { Teleporter.PortalPosition teleporter$portalposition = (Teleporter.PortalPosition)objectiterator.next(); if (teleporter$portalposition == null || teleporter$portalposition.lastUpdateTime < i) { objectiterator.remove(); } } } }
Example 4
Source File: BlockVectorSet.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
public Vector get(int index) { int count = 0; ObjectIterator<Int2ObjectMap.Entry<LocalBlockVectorSet>> iter = localSets.int2ObjectEntrySet().iterator(); while (iter.hasNext()) { Int2ObjectMap.Entry<LocalBlockVectorSet> entry = iter.next(); LocalBlockVectorSet set = entry.getValue(); int size = set.size(); int newSize = count + size; if (newSize > index) { int localIndex = index - count; Vector pos = set.getIndex(localIndex); if (pos != null) { int pair = entry.getIntKey(); int cx = MathMan.unpairX(pair); int cz = MathMan.unpairY(pair); pos.mutX((cx << 11) + pos.getBlockX()); pos.mutZ((cz << 11) + pos.getBlockZ()); return pos; } } count += newSize; } return null; }
Example 5
Source File: Item.java From StreamingRec with Apache License 2.0 | 6 votes |
/** * Returns the item as a CSV line */ @Override public String toString() { String keywords = ""; //in case there are keywords -> serialize them if(this.keywords!=null){ StringBuilder sb = new StringBuilder(); ObjectIterator<Entry<String>> fastIterator = this.keywords.object2IntEntrySet().fastIterator(); while(fastIterator.hasNext()){ Entry<String> next = fastIterator.next(); sb.append(next.getKey().replace("-","").replace("#", "")); sb.append("-"); sb.append(next.getIntValue()); if(fastIterator.hasNext()){ sb.append("#"); } } keywords = sb.toString(); } //write CSV string return publisher + Constants.CSV_SEPARATOR + Constants.DATE_FORMAT.format(createdAt) + Constants.CSV_SEPARATOR + id + Constants.CSV_SEPARATOR + url + Constants.CSV_SEPARATOR + title + Constants.CSV_SEPARATOR + category + Constants.CSV_SEPARATOR + text + Constants.CSV_SEPARATOR + keywords; }
Example 6
Source File: Anvil.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public void doGarbageCollection(long time) { long start = System.currentTimeMillis(); int maxIterations = size(); if (lastPosition > maxIterations) lastPosition = 0; int i; synchronized (chunks) { ObjectIterator<BaseFullChunk> iter = chunks.values().iterator(); if (lastPosition != 0) iter.skip(lastPosition); for (i = 0; i < maxIterations; i++) { if (!iter.hasNext()) { iter = chunks.values().iterator(); } if (!iter.hasNext()) break; BaseFullChunk chunk = iter.next(); if (chunk == null) continue; if (chunk.isGenerated() && chunk.isPopulated() && chunk instanceof Chunk) { Chunk anvilChunk = (Chunk) chunk; chunk.compress(); if (System.currentTimeMillis() - start >= time) break; } } } lastPosition += i; }
Example 7
Source File: BaseLevelProvider.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public synchronized void close() { this.unloadChunks(); synchronized (regions) { ObjectIterator<BaseRegionLoader> iter = this.regions.values().iterator(); while (iter.hasNext()) { try { iter.next().close(); } catch (IOException e) { throw new RuntimeException("Unable to close RegionLoader", e); } lastRegion.set(null); iter.remove(); } } this.level = null; }
Example 8
Source File: BaseLevelProvider.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public void doGarbageCollection() { int limit = (int) (System.currentTimeMillis() - 50); synchronized (regions) { if (regions.isEmpty()) { return; } ObjectIterator<BaseRegionLoader> iter = regions.values().iterator(); while (iter.hasNext()) { BaseRegionLoader loader = iter.next(); if (loader.lastUsed <= limit) { try { loader.close(); } catch (IOException e) { throw new RuntimeException("Unable to close RegionLoader", e); } lastRegion.set(null); iter.remove(); } } } }
Example 9
Source File: TofuTeleporter.java From TofuCraftReload with MIT License | 6 votes |
/** * called periodically to remove out-of-date portal locations from the cache list. Argument par1 is a * WorldServer.getTotalWorldTime() value. */ @Override public void removeStalePortalLocations(long worldTime) { if (worldTime % 100L == 0L) { long i = worldTime - 300L; ObjectIterator<PortalPosition> objectiterator = this.destinationCoordinateCache.values().iterator(); while (objectiterator.hasNext()) { PortalPosition teleporter$portalposition = (PortalPosition) objectiterator.next(); if (teleporter$portalposition == null || teleporter$portalposition.lastUpdateTime < i) { objectiterator.remove(); } } } }
Example 10
Source File: FastCollectionsUtils.java From fastjgame with Apache License 2.0 | 6 votes |
/** * 移除map中符合条件的元素,并对删除的元素执行后续的操作 * * @param map 必须是可修改的map * @param predicate 过滤条件,为真的删除 * @param then 元素删除之后执行的逻辑 * @param <V> the type of value * @return 删除的元素数量 */ public static <V> int removeIfAndThen(final Short2ObjectMap<V> map, final ShortObjPredicate<? super V> predicate, ShortObjConsumer<V> then) { if (map.size() == 0) { return 0; } ObjectIterator<Short2ObjectMap.Entry<V>> itr = map.short2ObjectEntrySet().iterator(); int removeNum = 0; Short2ObjectMap.Entry<V> entry; short k; V v; while (itr.hasNext()) { entry = itr.next(); k = entry.getShortKey(); v = entry.getValue(); if (predicate.test(k, v)) { itr.remove(); removeNum++; then.accept(k, v); } } return removeNum; }
Example 11
Source File: FastCollectionsUtils.java From fastjgame with Apache License 2.0 | 6 votes |
/** * 移除map中符合条件的元素,并对删除的元素执行后续的操作。 * * @param map 必须是可修改的map * @param predicate 过滤条件,为真的删除 * @param then 元素删除之后执行的逻辑 * @param <V> the type of value * @return 删除的元素数量 */ public static <V> int removeIfAndThen(final Long2ObjectMap<V> map, final LongObjPredicate<? super V> predicate, LongObjConsumer<V> then) { if (map.size() == 0) { return 0; } ObjectIterator<Long2ObjectMap.Entry<V>> itr = map.long2ObjectEntrySet().iterator(); int removeNum = 0; Long2ObjectMap.Entry<V> entry; long k; V v; while (itr.hasNext()) { entry = itr.next(); k = entry.getLongKey(); v = entry.getValue(); if (predicate.test(k, v)) { itr.remove(); removeNum++; then.accept(k, v); } } return removeNum; }
Example 12
Source File: Level.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public void doChunkGarbageCollection() { this.timings.doChunkGC.startTiming(); // remove all invaild block entities. if (!blockEntities.isEmpty()) { ObjectIterator<BlockEntity> iter = blockEntities.values().iterator(); while (iter.hasNext()) { BlockEntity blockEntity = iter.next(); if (blockEntity != null) { if (!blockEntity.isValid()) { iter.remove(); blockEntity.close(); } } else { iter.remove(); } } } for (Map.Entry<Long, ? extends FullChunk> entry : provider.getLoadedChunks().entrySet()) { long index = entry.getKey(); if (!this.unloadQueue.containsKey(index)) { FullChunk chunk = entry.getValue(); int X = chunk.getX(); int Z = chunk.getZ(); if (!this.isSpawnChunk(X, Z)) { this.unloadChunkRequest(X, Z, true); } } } this.provider.doGarbageCollection(); this.timings.doChunkGC.stopTiming(); }
Example 13
Source File: BaseLevelProvider.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void unloadChunks() { ObjectIterator<BaseFullChunk> iter = chunks.values().iterator(); while (iter.hasNext()) { iter.next().unload(true, false); iter.remove(); } }
Example 14
Source File: TmpPlistaTransaction.java From StreamingRec with Apache License 2.0 | 5 votes |
@Override public String toString() { String itemID; if (item == null) { itemID = "null"; } else { itemID = String.valueOf(item.id); } String keywords = ""; if(this.keywords!=null){ StringBuilder sb = new StringBuilder(); ObjectIterator<Entry<String>> fastIterator = this.keywords.object2IntEntrySet().fastIterator(); while(fastIterator.hasNext()){ Entry<String> next = fastIterator.next(); sb.append(next.getKey().replace("-","").replace("#", "")); sb.append("-"); sb.append(next.getIntValue()); if(fastIterator.hasNext()){ sb.append("#"); } } keywords = sb.toString(); } return publisher + Constants.CSV_SEPARATOR + category + Constants.CSV_SEPARATOR + itemID + Constants.CSV_SEPARATOR + cookie + Constants.CSV_SEPARATOR + timestamp.getTime() + Constants.CSV_SEPARATOR + keywords; }
Example 15
Source File: WorldObjectContainer.java From WorldGrower with GNU General Public License v3.0 | 5 votes |
public void moveItemsFrom(WorldObjectContainer otherInventory) { ObjectIterator<Entry<WorldObject>> iterator = otherInventory.worldObjects.int2ObjectEntrySet().fastIterator(); while(iterator.hasNext()) { Entry<WorldObject> otherEntry = iterator.next(); WorldObject otherWorldObject = otherEntry.getValue(); if (otherWorldObject.getProperty(Constants.QUANTITY) == null) { throw new IllegalStateException("otherWorldObject.getProperty(Constants.QUANTITY) is null: " + otherWorldObject); } addQuantity(otherWorldObject, otherWorldObject.getProperty(Constants.QUANTITY)); iterator.remove(); } }
Example 16
Source File: BlockVectorSet.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public Iterator<Vector> iterator() { final ObjectIterator<Int2ObjectMap.Entry<LocalBlockVectorSet>> entries = localSets.int2ObjectEntrySet().iterator(); if (!entries.hasNext()) { return new ArrayList<Vector>().iterator(); } return new Iterator<Vector>() { Int2ObjectMap.Entry<LocalBlockVectorSet> entry = entries.next(); Iterator<Vector> entryIter = entry.getValue().iterator(); MutableBlockVector mutable = new MutableBlockVector(); @Override public void remove() { entryIter.remove(); } @Override public boolean hasNext() { return entryIter.hasNext() || entries.hasNext(); } @Override public Vector next() { while (!entryIter.hasNext()) { if (!entries.hasNext()) { throw new NoSuchElementException("End of iterator"); } entry = entries.next(); entryIter = entry.getValue().iterator(); } Vector localPos = entryIter.next(); int pair = entry.getIntKey(); int cx = MathMan.unpairX(pair); int cz = MathMan.unpairY(pair); return mutable.setComponents((cx << 11) + localPos.getBlockX(), localPos.getBlockY(), (cz << 11) + localPos.getBlockZ()); } }; }
Example 17
Source File: Anvil.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void doGarbageCollection(long time) { long start = System.currentTimeMillis(); int maxIterations = size(); if (lastPosition > maxIterations) lastPosition = 0; ObjectIterator<BaseFullChunk> iter = getChunks(); if (lastPosition != 0) iter.skip(lastPosition); int i; for (i = 0; i < maxIterations; i++) { if (!iter.hasNext()) { iter = getChunks(); } BaseFullChunk chunk = iter.next(); if (chunk == null) continue; if (chunk.isGenerated() && chunk.isPopulated() && chunk instanceof Chunk) { Chunk anvilChunk = (Chunk) chunk; for (cn.nukkit.level.format.ChunkSection section : anvilChunk.getSections()) { if (section instanceof ChunkSection) { ChunkSection anvilSection = (ChunkSection) section; if (!anvilSection.isEmpty()) { anvilSection.compress(); } } } if (System.currentTimeMillis() - start >= time) break; } } lastPosition += i; }
Example 18
Source File: BukkitBridge.java From BungeeTabListPlus with GNU General Public License v3.0 | 5 votes |
private void removeObsoleteConnections() { synchronized (this) { ObjectIterator<Server> iterator = connections.iterator(); while (iterator.hasNext()) { Server server = iterator.next(); if (!server.isConnected()) { iterator.remove(); } } } }
Example 19
Source File: Player.java From Nukkit with GNU General Public License v3.0 | 4 votes |
protected void sendNextChunk() { if (!this.connected) { return; } Timings.playerChunkSendTimer.startTiming(); if (!loadQueue.isEmpty()) { int count = 0; ObjectIterator<Long2ObjectMap.Entry<Boolean>> iter = loadQueue.long2ObjectEntrySet().fastIterator(); while (iter.hasNext()) { Long2ObjectMap.Entry<Boolean> entry = iter.next(); long index = entry.getLongKey(); if (count >= this.chunksPerTick) { break; } int chunkX = Level.getHashX(index); int chunkZ = Level.getHashZ(index); ++count; this.usedChunks.put(index, false); this.level.registerChunkLoader(this, chunkX, chunkZ, false); if (!this.level.populateChunk(chunkX, chunkZ)) { if (this.spawned && this.teleportPosition == null) { continue; } else { break; } } iter.remove(); PlayerChunkRequestEvent ev = new PlayerChunkRequestEvent(this, chunkX, chunkZ); this.server.getPluginManager().callEvent(ev); if (!ev.isCancelled()) { this.level.requestChunk(chunkX, chunkZ, this); } } } if (this.chunkLoadCount >= this.spawnThreshold && !this.spawned && this.teleportPosition == null) { this.doFirstSpawn(); } Timings.playerChunkSendTimer.stopTiming(); }
Example 20
Source File: Player.java From Nukkit with GNU General Public License v3.0 | 4 votes |
protected void sendNextChunk() { if (!this.connected) { return; } Timings.playerChunkSendTimer.startTiming(); if (!loadQueue.isEmpty()) { int count = 0; ObjectIterator<Long2ObjectMap.Entry<Boolean>> iter = loadQueue.long2ObjectEntrySet().fastIterator(); while (iter.hasNext()) { Long2ObjectMap.Entry<Boolean> entry = iter.next(); long index = entry.getLongKey(); if (count >= this.chunksPerTick) { break; } int chunkX = Level.getHashX(index); int chunkZ = Level.getHashZ(index); ++count; this.usedChunks.put(index, false); this.level.registerChunkLoader(this, chunkX, chunkZ, false); if (!this.level.populateChunk(chunkX, chunkZ)) { if (this.spawned && this.teleportPosition == null) { continue; } else { break; } } iter.remove(); PlayerChunkRequestEvent ev = new PlayerChunkRequestEvent(this, chunkX, chunkZ); this.server.getPluginManager().callEvent(ev); if (!ev.isCancelled()) { this.level.requestChunk(chunkX, chunkZ, this); } } } if (this.chunkLoadCount >= this.spawnThreshold && !this.spawned && this.teleportPosition == null) { this.doFirstSpawn(); } Timings.playerChunkSendTimer.stopTiming(); }