public V put( long key, V value ) { synchronized( mutex ) { return m.put( key, value ); } } public V remove( long key ) {
public Component put(long entityId, Component component) { TLongObjectMap<Component> entityMap = store.get(component.getClass()); if (entityMap == null) { entityMap = new TLongObjectHashMap<>(); store.put(component.getClass(), entityMap); } return entityMap.put(entityId, component); }
/** * Inserts a key/value pair into the map. * * @param key an <code>Long</code> value * @param value an <code>Object</code> value * @return the previous value associated with <tt>key</tt>, * or <tt>null</tt> if none was found. */ public V put( Long key, V value ) { long k; if ( key == null ) { k = _map.getNoEntryKey(); } else { k = unwrapKey( key ); } return _map.put( k, value ); }
private EntityDelta getOrCreateEntityDeltaFor(EntityRef entity) { long id = entity.getId(); EntityDelta entityDelta = entityDeltas.get(id); if (entityDelta == null) { entityDelta = new EntityDelta(); entityDeltas.put(id, entityDelta); } return entityDelta; }
public void add(RouteDataObject ro) { tileStatistics.addObject(ro); for (int i = 0; i < ro.pointsX.length; i++) { int x31 = ro.getPoint31XTile(i); int y31 = ro.getPoint31YTile(i); long l = (((long) x31) << 31) + (long) y31; RouteSegment segment = new RouteSegment(ro, i); if (!routes.containsKey(l)) { routes.put(l, segment); } else { RouteSegment orig = routes.get(l); while (orig.next != null) { orig = orig.next; } orig.next = segment; } } }
void handleAddMember(JSONObject member) { if (members == null || removedMembers == null) return; expectedMemberCount++; long userId = member.getJSONObject("user").getLong("id"); members.put(userId, member); removedMembers.remove(userId); }
@Override protected void handleVirtualInnerWay(TDWay virtualWay) { this.virtualWays.put(virtualWay.getId(), virtualWay); }
@Override protected void handleVirtualOuterWay(TDWay virtualWay) { this.virtualWays.put(virtualWay.getId(), virtualWay); }
public synchronized void cache(Type type, long triggerId, long responseTotal, JSONObject 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)); }
boolean handleMemberChunk(JSONArray arr) { if (partialGuild == null) { //In this case we received a GUILD_DELETE with unavailable = true while chunking // however we have to wait for the GUILD_CREATE with unavailable = false before // requesting new chunks GuildSetupController.log.debug("Dropping member chunk due to unavailable guild"); return true; } for (Object o : arr) { JSONObject obj = (JSONObject) o; long id = obj.getJSONObject("user").getLong("id"); members.put(id, obj); } if (members.size() >= expectedMemberCount) { completeSetup(); return false; } return true; }
@Override protected void handleAdditionalRelationTags(TDWay way, TDRelation relation) { List<TDRelation> associatedRelations = this.additionalRelationTags.get(way.getId()); if (associatedRelations == null) { associatedRelations = new ArrayList<>(); this.additionalRelationTags.put(way.getId(), associatedRelations); } associatedRelations.add(relation); }
private void createGuildEmotePass(GuildImpl guildObj, JSONArray array) { if (!getJDA().isCacheFlagSet(CacheFlag.EMOTE)) return; TLongObjectMap<Emote> emoteMap = guildObj.getEmoteMap(); for (int i = 0; i < array.length(); i++) { JSONObject object = array.getJSONObject(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)); } }
public void onCreate(long id, JSONObject obj) { boolean available = obj.isNull("unavailable") || !obj.getBoolean("unavailable"); log.trace("Received guild create for id: {} available: {}", id, available); GuildSetupNode node = setupNodes.get(id); if (node == null) { // this is a join event node = new GuildSetupNode(id, this, true); setupNodes.put(id, node); // do not increment incomplete counter, it is only relevant to init guilds } else if (node.markedUnavailable && available && incompleteCount > 0) { //Looks like this guild decided to become available again during startup // that means we can now consider it for ReadyEvent status again! if (node.sync) syncingCount++; incompleteCount++; } node.handleCreate(obj); }
public void onReady(long id, JSONObject obj) { log.trace("Adding id to setup cache {}", id); GuildSetupNode node = new GuildSetupNode(id, this, false); setupNodes.put(id, node); node.handleReady(obj); if (node.markedUnavailable) { if (node.sync) { syncingCount--; trySyncing(); } incompleteCount--; tryChunking(); } }
public Role createRole(GuildImpl guild, JSONObject roleJson, long guildId) { boolean playbackCache = false; final long id = roleJson.getLong("id"); if (guild == null) guild = (GuildImpl) getJDA().getGuildMap().get(guildId); RoleImpl role = (RoleImpl) guild.getRolesMap().get(id); if (role == null) { role = new RoleImpl(id, guild); playbackCache = guild.getRolesMap().put(id, role) == null; } final int color = roleJson.getInt("color"); role.setName(roleJson.getString("name")) .setRawPosition(roleJson.getInt("position")) .setRawPermissions(roleJson.getLong("permissions")) .setManaged(roleJson.getBoolean("managed")) .setHoisted(roleJson.getBoolean("hoist")) .setColor(color == 0 ? Role.DEFAULT_COLOR_RAW : color) .setMentionable(roleJson.has("mentionable") && roleJson.getBoolean("mentionable")); if (playbackCache) getJDA().getEventCache().playbackCache(EventCache.Type.ROLE, id); return role; }
public PrivateChannel createPrivateChannel(JSONObject privatechat) { JSONObject recipient = privatechat.has("recipients") ? privatechat.getJSONArray("recipients").getJSONObject(0) : privatechat.getJSONObject("recipient"); final long userId = recipient.getLong("id"); UserImpl user = (UserImpl) getJDA().getUserMap().get(userId); if (user == null) { //The getJDA() can give us private channels connected to Users that we can no longer communicate with. // As such, make a fake user and fake private channel. user = createFakeUser(recipient, true); } final long channelId = privatechat.getLong("id"); PrivateChannelImpl priv = new PrivateChannelImpl(channelId, user) .setLastMessageId(Helpers.optLong(privatechat, "last_message_id", 0)); user.setPrivateChannel(priv); if (user.isFake()) { priv.setFake(true); getJDA().getFakePrivateChannelMap().put(channelId, priv); } else { getJDA().getPrivateChannelMap().put(channelId, priv); getJDA().getEventCache().playbackCache(EventCache.Type.CHANNEL, channelId); } return priv; }
public void queueAudioDisconnect(Guild guild) { locked("There was an error queueing the audio disconnect", () -> { final long guildId = guild.getIdLong(); ConnectionRequest request = queuedAudioConnections.get(guildId); if (request == null) { // If we do not have a request queuedAudioConnections.put(guildId, new ConnectionRequest(guild)); } else { // If we have a request, change to DISCONNECT request.setStage(ConnectionStage.DISCONNECT); } }); }
@Override protected void handleResponse(Response response, Request<PermissionOverride> request) { if (!response.isOk()) { request.onFailure(response); return; } boolean isMember = isMember(); long id = isMember ? member.getUser().getIdLong() : role.getIdLong(); JSONObject object = (JSONObject) request.getRawBody(); PermissionOverrideImpl override = new PermissionOverrideImpl(channel, id, isMember ? member : role); override.setAllow(object.getLong("allow")); override.setDeny(object.getLong("deny")); ((AbstractChannelImpl<?>) channel).getOverrideMap().put(id, override); request.onSuccess(override); }
public void queueAudioReconnect(VoiceChannel channel) { locked("There was an error queueing the audio reconnect", () -> { final long guildId = channel.getGuild().getIdLong(); ConnectionRequest request = queuedAudioConnections.get(guildId); if (request == null) { // If no request, then just reconnect request = new ConnectionRequest(channel, ConnectionStage.RECONNECT); queuedAudioConnections.put(guildId, request); } else { // If there is a request we change it to reconnect, no matter what it is request.setStage(ConnectionStage.RECONNECT); } // in all cases, update to this channel request.setChannel(channel); }); }
public void queueAudioConnect(VoiceChannel channel) { locked("There was an error queueing the audio connect", () -> { final long guildId = channel.getGuild().getIdLong(); ConnectionRequest request = queuedAudioConnections.get(guildId); if (request == null) { // starting a whole new connection request = new ConnectionRequest(channel, ConnectionStage.CONNECT); queuedAudioConnections.put(guildId, request); } else if (request.getStage() == ConnectionStage.DISCONNECT) { // if planned to disconnect, we want to reconnect request.setStage(ConnectionStage.RECONNECT); } // in all cases, update to this channel request.setChannel(channel); }); }