gnu.trove.iterator.TLongObjectIterator Java Examples

The following examples show how to use gnu.trove.iterator.TLongObjectIterator. 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: ShapeInterpolationMode.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
private SectionInfo createSectionInfo(final PainteraBaseView paintera)
{
	Interval selectionSourceBoundingBox = null;
	for (final TLongObjectIterator<SelectedObjectInfo> it = selectedObjects.iterator(); it.hasNext();)
	{
		it.advance();
		if (selectionSourceBoundingBox == null)
			selectionSourceBoundingBox = it.value().sourceBoundingBox;
		else
			selectionSourceBoundingBox = Intervals.union(selectionSourceBoundingBox, it.value().sourceBoundingBox);
	}

	final AffineTransform3D globalTransform = new AffineTransform3D();
	paintera.manager().getTransform(globalTransform);

	return new SectionInfo(
			mask,
			globalTransform,
			getMaskDisplayTransformIgnoreScaling(SHAPE_INTERPOLATION_SCALE_LEVEL),
			selectionSourceBoundingBox,
			new TLongObjectHashMap<>(selectedObjects)
		);
}
 
Example #2
Source File: FallingBlocksMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Make any unsupported blocks fall that are disturbed for the current tick
 */
private void fallCheck() {
    this.visitsWorstTick = Math.max(this.visitsWorstTick, this.visitsThisTick);
    this.visitsThisTick = 0;

    World world = this.getMatch().getWorld();
    TLongObjectMap<ParticipantState> blockDisturbers = this.blockDisturbersByTick.remove(this.getMatch().getClock().now().tick);
    if(blockDisturbers == null) return;

    TLongSet supported = new TLongHashSet();
    TLongSet unsupported = new TLongHashSet();
    TLongObjectMap<ParticipantState> fallsByBreaker = new TLongObjectHashMap<>();

    try {
        while(!blockDisturbers.isEmpty()) {
            long pos = blockDisturbers.keySet().iterator().next();
            ParticipantState breaker = blockDisturbers.remove(pos);

            // Search down for the first block that can actually fall
            for(;;) {
                long below = neighborPos(pos, BlockFace.DOWN);
                if(!Materials.isColliding(blockAt(world, below).getType())) break;
                blockDisturbers.remove(pos); // Remove all the blocks we find along the way
                pos = below;
            }

            // Check if the block needs to fall, if it isn't already falling
            if(!fallsByBreaker.containsKey(pos) && !this.isSupported(pos, supported, unsupported)) {
                fallsByBreaker.put(pos, breaker);
            }
        }
    } catch(MaxSearchVisitsExceeded ex) {
        this.logError(ex);
    }

    for(TLongObjectIterator<ParticipantState> iter = fallsByBreaker.iterator(); iter.hasNext();) {
        iter.advance();
        this.fall(iter.key(), iter.value());
    }
}
 
Example #3
Source File: WebSocketClient.java    From JDA with Apache License 2.0 6 votes vote down vote up
protected void updateAudioManagerReferences()
{
    AbstractCacheView<AudioManager> managerView = api.getAudioManagersView();
    try (UnlockHook hook = managerView.writeLock())
    {
        final TLongObjectMap<AudioManager> managerMap = managerView.getMap();
        if (managerMap.size() > 0)
            LOG.trace("Updating AudioManager references");

        for (TLongObjectIterator<AudioManager> it = managerMap.iterator(); it.hasNext(); )
        {
            it.advance();
            final long guildId = it.key();
            final AudioManagerImpl mng = (AudioManagerImpl) it.value();

            GuildImpl guild = (GuildImpl) api.getGuildById(guildId);
            if (guild == null)
            {
                //We no longer have access to the guild that this audio manager was for. Set the value to null.
                queuedAudioConnections.remove(guildId);
                mng.closeAudioConnection(ConnectionStatus.DISCONNECTED_REMOVED_DURING_RECONNECT);
                it.remove();
            }
        }
    }
}
 
Example #4
Source File: GuildSetupController.java    From JDA with Apache License 2.0 5 votes vote down vote up
public boolean containsMember(long userId, @Nullable GuildSetupNode excludedNode)
{
    for (TLongObjectIterator<GuildSetupNode> it = setupNodes.iterator(); it.hasNext();)
    {
        it.advance();
        GuildSetupNode node = it.value();
        if (node != excludedNode && node.containsMember(userId))
            return true;
    }
    return false;
}
 
Example #5
Source File: EventCache.java    From JDA with Apache License 2.0 5 votes vote down vote up
public synchronized void timeout(final long responseTotal)
{
    if (eventCache.isEmpty())
        return;
    AtomicInteger count = new AtomicInteger();
    eventCache.forEach((type, map) ->
    {
        if (map.isEmpty())
            return;
        TLongObjectIterator<List<CacheNode>> iterator = map.iterator();
        while (iterator.hasNext())
        {
            iterator.advance();
            long triggerId = iterator.key();
            List<CacheNode> cache = iterator.value();
            //Remove when this node is more than 100 events ago
            cache.removeIf(node ->
            {
                boolean remove = responseTotal - node.responseTotal > TIMEOUT_AMOUNT;
                if (remove)
                {
                    count.incrementAndGet();
                    LOG.trace("Removing type {}/{} from event cache with payload {}", type, triggerId, node.event);
                }
                return remove;
            });
            if (cache.isEmpty())
                iterator.remove();
        }
    });
    int amount = count.get();
    if (amount > 0)
        LOG.debug("Removed {} events from cache that were too old to be recycled", amount);
}
 
Example #6
Source File: SparseMatrixT.java    From fnlp with GNU Lesser General Public License v3.0 5 votes vote down vote up
public SparseMatrixT<T> resize(int[] dim){
	SparseMatrixT<T> mat = new SparseMatrixT<T>(dim);
	TLongObjectIterator<T> it = vector.iterator();
	while(it.hasNext()){
		it.advance();
		long key = it.key();
		T val = it.value();
		int[] idx = getIndices(key);
		mat.set(idx, val);
	}
	return mat;
}
 
Example #7
Source File: SparseMatrix.java    From fnlp with GNU Lesser General Public License v3.0 5 votes vote down vote up
public SparseMatrix<T> resize(int dim){
	SparseMatrix<T> mat = new SparseMatrix<T>(dim);
	TLongObjectIterator<T> it = vector.iterator();
	while(it.hasNext()){
		it.advance();
		long key = it.key();
		T val = it.value();
		int[] idx = getIndices(key);
		mat.set(idx[0],idx[1], val);
	}
	return mat;
}
 
Example #8
Source File: FallingBlocksMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
/** Make any unsupported blocks fall that are disturbed for the current tick */
private void fallCheck() {
  this.visitsWorstTick = Math.max(this.visitsWorstTick, this.visitsThisTick);
  this.visitsThisTick = 0;

  World world = match.getWorld();
  TLongObjectMap<ParticipantState> blockDisturbers =
      this.blockDisturbersByTick.remove(match.getTick().tick);
  if (blockDisturbers == null) return;

  TLongSet supported = new TLongHashSet();
  TLongSet unsupported = new TLongHashSet();
  TLongObjectMap<ParticipantState> fallsByBreaker = new TLongObjectHashMap<>();

  try {
    while (!blockDisturbers.isEmpty()) {
      long pos = blockDisturbers.keySet().iterator().next();
      ParticipantState breaker = blockDisturbers.remove(pos);

      // Search down for the first block that can actually fall
      for (; ; ) {
        long below = neighborPos(pos, BlockFace.DOWN);
        if (!Materials.isSolid(blockAt(world, below).getType())) break;
        blockDisturbers.remove(pos); // Remove all the blocks we find along the way
        pos = below;
      }

      // Check if the block needs to fall, if it isn't already falling
      if (!fallsByBreaker.containsKey(pos) && !this.isSupported(pos, supported, unsupported)) {
        fallsByBreaker.put(pos, breaker);
      }
    }
  } catch (MaxSearchVisitsExceeded ex) {
    this.logError(ex);
  }

  for (TLongObjectIterator<ParticipantState> iter = fallsByBreaker.iterator(); iter.hasNext(); ) {
    iter.advance();
    this.fall(iter.key(), iter.value());
  }
}
 
Example #9
Source File: WebSocketClient.java    From JDA with Apache License 2.0 4 votes vote down vote up
protected ConnectionRequest getNextAudioConnectRequest()
{
    //Don't try to setup audio connections before JDA has finished loading.
    if (sessionId == null)
        return null;

    long now = System.currentTimeMillis();
    TLongObjectIterator<ConnectionRequest> it =  queuedAudioConnections.iterator();
    while (it.hasNext())
    {
        it.advance();
        ConnectionRequest audioRequest = it.value();
        if (audioRequest.getNextAttemptEpoch() < now)
        {
            // Check if the guild is ready
            long guildId = audioRequest.getGuildIdLong();
            Guild guild = api.getGuildById(guildId);
            if (guild == null)
            {
                // Not yet ready, check if the guild is known to this shard
                GuildSetupController controller = api.getGuildSetupController();
                if (!controller.isKnown(guildId))
                {
                    // The guild is not tracked anymore -> we can't connect the audio channel
                    LOG.debug("Removing audio connection request because the guild has been removed. {}", audioRequest);
                    it.remove();
                }
                continue;
            }

            ConnectionListener listener = guild.getAudioManager().getConnectionListener();
            if (audioRequest.getStage() != ConnectionStage.DISCONNECT)
            {
                VoiceChannel channel = guild.getVoiceChannelById(audioRequest.getChannelId());
                if (channel == null)
                {
                    it.remove();
                    if (listener != null)
                        listener.onStatusChange(ConnectionStatus.DISCONNECTED_CHANNEL_DELETED);
                    continue;
                }

                if (!guild.getSelfMember().hasPermission(channel, Permission.VOICE_CONNECT))
                {
                    it.remove();
                    if (listener != null)
                        listener.onStatusChange(ConnectionStatus.DISCONNECTED_LOST_PERMISSION);
                    continue;
                }
            }

            return audioRequest;
        }
    }

    return null;
}
 
Example #10
Source File: ThreadPrivateTLongObjHashMap.java    From Chronicle-Network with Apache License 2.0 4 votes vote down vote up
@Override
public TLongObjectIterator<V> iterator() {
    assertThreadPrivate();
    return delegate.iterator();
}