Java Code Examples for gnu.trove.map.TLongObjectMap#put()

The following examples show how to use gnu.trove.map.TLongObjectMap#put() . 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: FallingBlocksMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
private void disturb(long pos, BlockState blockState, @Nullable ParticipantState disturber) {
  FallingBlocksRule rule = this.ruleWithShortestDelay(blockState);
  if (rule != null) {
    long tick = match.getTick().tick + rule.delay;
    TLongObjectMap<ParticipantState> blockDisturbers = this.blockDisturbersByTick.get(tick);

    if (blockDisturbers == null) {
      blockDisturbers = new TLongObjectHashMap<>();
      this.blockDisturbersByTick.put(tick, blockDisturbers);
    }

    Block block = blockState.getBlock();
    if (!blockDisturbers.containsKey(pos)) {
      blockDisturbers.put(pos, disturber);
    }
  }
}
 
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: FallingBlocksMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
private void disturb(long pos, BlockState blockState, @Nullable ParticipantState disturber) {
    FallingBlocksRule rule = this.ruleWithShortestDelay(blockState);
    if(rule != null) {
        long tick = this.getMatch().getClock().now().tick + rule.delay;
        TLongObjectMap<ParticipantState> blockDisturbers = this.blockDisturbersByTick.get(tick);

        if(blockDisturbers == null) {
            blockDisturbers = new TLongObjectHashMap<>();
            this.blockDisturbersByTick.put(tick, blockDisturbers);
        }

        Block block = blockState.getBlock();
        if(!blockDisturbers.containsKey(pos)) {
            blockDisturbers.put(pos, disturber);
        }
    }
}
 
Example 4
Source File: EntityBuilder.java    From JDA with Apache License 2.0 6 votes vote down vote up
private void createGuildEmotePass(GuildImpl guildObj, DataArray array)
{
    if (!getJDA().isCacheFlagSet(CacheFlag.EMOTE))
        return;
    SnowflakeCacheViewImpl<Emote> emoteView = guildObj.getEmotesView();
    try (UnlockHook hook = emoteView.writeLock())
    {
        TLongObjectMap<Emote> emoteMap = emoteView.getMap();
        for (int i = 0; i < array.length(); i++)
        {
            DataObject object = array.getObject(i);
            if (object.isNull("id"))
            {
                LOG.error("Received GUILD_CREATE with an emoji with a null ID. JSON: {}", object);
                continue;
            }
            final long emoteId = object.getLong("id");
            emoteMap.put(emoteId, createEmote(guildObj, object, false));
        }
    }
}
 
Example 5
Source File: CommitCanvasN5.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private static <T> T computeIfAbsent(final TLongObjectMap<T> map, final long key, final Supplier<T> fallback)
{
	T t = map.get(key);
	if (t == null)
	{
		t = fallback.get();
		map.put(key, t);
	}
	return t;
}
 
Example 6
Source File: LatestExchangeRates.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ExchangeRate getRate(Currency fromCurrency, Currency toCurrency) {
    if (fromCurrency.id == toCurrency.id) {
        return ExchangeRate.ONE;
    }
    TLongObjectMap<ExchangeRate> rateMap = getMapFor(fromCurrency.id);
    ExchangeRate rate = rateMap.get(toCurrency.id);
    if (rate == null) {
        rate = ExchangeRate.NA;
        rateMap.put(toCurrency.id, rate);
    }
    return rate;
}
 
Example 7
Source File: HistoryExchangeRates.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
private SortedSet<ExchangeRate> getSetFor(TLongObjectMap<SortedSet<ExchangeRate>> rates, long date) {
    SortedSet<ExchangeRate> s = rates.get(date);
    if (s == null) {
        s = new TreeSet<ExchangeRate>();
        rates.put(date, s);
    }
    return s;
}
 
Example 8
Source File: ReadyHandler.java    From JDA with Apache License 2.0 5 votes vote down vote up
@Override
protected Long handleInternally(DataObject content)
{
    EntityBuilder builder = getJDA().getEntityBuilder();

    DataArray guilds = content.getArray("guilds");
    //Make sure we don't have any duplicates here!
    TLongObjectMap<DataObject> distinctGuilds = new TLongObjectHashMap<>();
    for (int i = 0; i < guilds.length(); i++)
    {
        DataObject guild = guilds.getObject(i);
        long id = guild.getUnsignedLong("id");
        DataObject previous = distinctGuilds.put(id, guild);
        if (previous != null)
            WebSocketClient.LOG.warn("Found duplicate guild for id {} in ready payload", id);
    }

    DataObject selfJson = content.getObject("user");

    builder.createSelfUser(selfJson);
    if (getJDA().getGuildSetupController().setIncompleteCount(distinctGuilds.size()))
    {
        distinctGuilds.forEachEntry((id, guild) ->
        {
            getJDA().getGuildSetupController().onReady(id, guild);
            return true;
        });
    }

    handleReady(content);
    return null;
}
 
Example 9
Source File: EventCache.java    From JDA with Apache License 2.0 5 votes vote down vote up
public synchronized void cache(Type type, long triggerId, long responseTotal, DataObject event, CacheConsumer handler)
{
    TLongObjectMap<List<CacheNode>> triggerCache =
            eventCache.computeIfAbsent(type, k -> new TLongObjectHashMap<>());

    List<CacheNode> items = triggerCache.get(triggerId);
    if (items == null)
    {
        items = new LinkedList<>();
        triggerCache.put(triggerId, items);
    }

    items.add(new CacheNode(responseTotal, event, handler));
}
 
Example 10
Source File: EntityBuilder.java    From JDA with Apache License 2.0 5 votes vote down vote up
public TLongObjectMap<DataObject> convertToUserMap(ToLongFunction<DataObject> getId, DataArray array)
{
    TLongObjectMap<DataObject> map = new TLongObjectHashMap<>();
    for (int i = 0; i < array.length(); i++)
    {
        DataObject obj = array.getObject(i);
        long userId = getId.applyAsLong(obj);
        map.put(userId, obj);
    }
    return map;
}
 
Example 11
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 12
Source File: LatestExchangeRates.java    From financisto with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void addRate(ExchangeRate r) {
    TLongObjectMap<ExchangeRate> rateMap = getMapFor(r.fromCurrencyId);
    rateMap.put(r.toCurrencyId, r);
}
 
Example 13
Source File: ChainingTSCPair.java    From monsoon with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public synchronized void add(@NonNull DateTime ts, @NonNull TimeSeriesValue tv) {
    final TLongObjectMap<TimeSeriesValue> tail = tailRefForUpdate.get();
    if (tail != null)
        tail.put(ts.getMillis(), tv);
}
 
Example 14
Source File: GuildSetupNode.java    From JDA with Apache License 2.0 4 votes vote down vote up
private void updateAudioManagerReference(GuildImpl guild)
{
    JDAImpl api = getController().getJDA();
    AbstractCacheView<AudioManager> managerView = api.getAudioManagersView();
    try (UnlockHook hook = managerView.writeLock())
    {
        TLongObjectMap<AudioManager> audioManagerMap = managerView.getMap();
        AudioManagerImpl mng = (AudioManagerImpl) audioManagerMap.get(id);
        if (mng == null)
            return;
        ConnectionListener listener = mng.getConnectionListener();
        final AudioManagerImpl newMng = new AudioManagerImpl(guild);
        newMng.setSelfMuted(mng.isSelfMuted());
        newMng.setSelfDeafened(mng.isSelfDeafened());
        newMng.setQueueTimeout(mng.getConnectTimeout());
        newMng.setSendingHandler(mng.getSendingHandler());
        newMng.setReceivingHandler(mng.getReceivingHandler());
        newMng.setConnectionListener(listener);
        newMng.setAutoReconnect(mng.isAutoReconnect());

        if (mng.isConnected())
        {
            final long channelId = mng.getConnectedChannel().getIdLong();

            final VoiceChannel channel = api.getVoiceChannelById(channelId);
            if (channel != null)
            {
                if (mng.isConnected())
                    mng.closeAudioConnection(ConnectionStatus.ERROR_CANNOT_RESUME);
            }
            else
            {
                //The voice channel is not cached. It was probably deleted.
                api.getClient().removeAudioConnection(id);
                if (listener != null)
                    listener.onStatusChange(ConnectionStatus.DISCONNECTED_CHANNEL_DELETED);
            }
        }
        audioManagerMap.put(id, newMng);
    }
}