private void updateCache(Stream stream) { LOG.debug("Updating stream id/title cache for {}/'{}'", stream.getId(), stream.getTitle()); idToStream.put(stream.getId(), stream); nameToStream.put(stream.getTitle(), stream); }
sortedApi.put(category, apiPackage + " (PACKAGE)"); } else { sortedApi.put(category, apiClass.getName() + (apiClass.isInterface() ? " (INTERFACE)" : " (CLASS)")); sortedApi.put(category, apiPackage + " (PACKAGE)"); } else { sortedApi.put(category, apiClass.getName() + (apiClass.isInterface() ? " (INTERFACE)" : " (CLASS)"));
@ReceiveEvent public void delayedComponentActivated(OnActivatedComponent event, EntityRef entity, DelayedActionComponent delayedActionComponent) { delayedOperationsSortedByTime.put(delayedActionComponent.getLowestWakeUp(), entity); }
@ReceiveEvent public void periodicComponentActivated(OnActivatedComponent event, EntityRef entity, PeriodicActionComponent periodicActionComponent) { periodicOperationsSortedByTime.put(periodicActionComponent.getLowestWakeUp(), entity); }
@Override public Void visitFieldAccess(RexFieldAccess fieldAccess) { final RexNode ref = fieldAccess.getReferenceExpr(); if (ref instanceof RexCorrelVariable) { final RexCorrelVariable var = (RexCorrelVariable) ref; if (mapFieldAccessToCorVar.containsKey(fieldAccess)) { //for cases where different Rel nodes are referring to // same correlation var (e.g. in case of NOT IN) // avoid generating another correlation var // and record the 'rel' is using the same correlation mapRefRelToCorRef.put(rel, mapFieldAccessToCorVar.get(fieldAccess)); } else { final CorRef correlation = new CorRef(var.id, fieldAccess.getField().getIndex(), corrIdGenerator++); mapFieldAccessToCorVar.put(fieldAccess, correlation); mapRefRelToCorRef.put(rel, correlation); } } return super.visitFieldAccess(fieldAccess); }
/** Test that creating one TreeMultimap from a SortedSetMultimap uses natural ordering. */ public void testCreateFromSortedSetMultimap() { SortedSetMultimap<Double, Double> tree = TreeMultimap.create(KEY_COMPARATOR, VALUE_COMPARATOR); tree.put(1.0, 2.0); tree.put(2.0, 3.0); tree.put(3.0, 4.0); tree.put(4.0, 5.0); SortedSetMultimap<Double, Double> sorted = Multimaps.unmodifiableSortedSetMultimap(tree); TreeMultimap<Double, Double> copyFromSorted = TreeMultimap.create(sorted); assertEquals(tree, copyFromSorted); assertSame(Ordering.natural(), copyFromSorted.keyComparator()); assertSame(Ordering.natural(), copyFromSorted.valueComparator()); assertSame(Ordering.natural(), copyFromSorted.get(1.0).comparator()); }
Comparator.comparing(MiniDescription::name)); for (BugPatternInstance pattern : patterns) { sorted.put( IndexEntry.create(enabledChecks.contains(pattern.name), pattern.severity), MiniDescription.create(pattern));
private void invokeDelayedOperations(long currentWorldTime) { List<EntityRef> operationsToInvoke = new LinkedList<>(); Iterator<Long> scheduledOperationsIterator = delayedOperationsSortedByTime.keySet().iterator(); long processedTime; while (scheduledOperationsIterator.hasNext()) { processedTime = scheduledOperationsIterator.next(); if (processedTime > currentWorldTime) { break; } operationsToInvoke.addAll(delayedOperationsSortedByTime.get(processedTime)); scheduledOperationsIterator.remove(); } operationsToInvoke.stream().filter(EntityRef::exists).forEach(delayedEntity -> { final DelayedActionComponent delayedActions = delayedEntity.getComponent(DelayedActionComponent.class); // If there is a DelayedActionComponent, proceed. Else report an error to the log. if (delayedActions != null) { final Set<String> actionIds = delayedActions.removeActionsUpTo(currentWorldTime); saveOrRemoveComponent(delayedEntity, delayedActions); if (!delayedActions.isEmpty()) { delayedOperationsSortedByTime.put(delayedActions.getLowestWakeUp(), delayedEntity); } for (String actionId : actionIds) { delayedEntity.send(new DelayedActionTriggeredEvent(actionId)); } } else { logger.error("ERROR: This entity is missing a DelayedActionComponent: {}. " + "So skipping delayed actions for this entity.", delayedEntity); } }); }
private void invokePeriodicOperations(long currentWorldTime) { List<EntityRef> operationsToInvoke = new LinkedList<>(); Iterator<Long> scheduledOperationsIterator = periodicOperationsSortedByTime.keySet().iterator(); long processedTime; while (scheduledOperationsIterator.hasNext()) { processedTime = scheduledOperationsIterator.next(); if (processedTime > currentWorldTime) { break; } operationsToInvoke.addAll(periodicOperationsSortedByTime.get(processedTime)); scheduledOperationsIterator.remove(); } operationsToInvoke.stream().filter(EntityRef::exists).forEach(periodicEntity -> { final PeriodicActionComponent periodicActionComponent = periodicEntity.getComponent(PeriodicActionComponent.class); // If there is a PeriodicActionComponent, proceed. Else report an error to the log. if (periodicActionComponent != null) { final Set<String> actionIds = periodicActionComponent.getTriggeredActionsAndReschedule(currentWorldTime); saveOrRemoveComponent(periodicEntity, periodicActionComponent); if (!periodicActionComponent.isEmpty()) { periodicOperationsSortedByTime.put(periodicActionComponent.getLowestWakeUp(), periodicEntity); } for (String actionId : actionIds) { periodicEntity.send(new PeriodicActionTriggeredEvent(actionId)); } } else { logger.error("ERROR: This entity is missing a DelayedActionComponent: {}. " + "So skipping delayed actions for this entity", periodicEntity); } }); }
@Override public void addPeriodicAction(EntityRef entity, String actionId, long initialDelay, long period) { long scheduleTime = time.getGameTimeInMs() + initialDelay; PeriodicActionComponent periodicActionComponent = entity.getComponent(PeriodicActionComponent.class); if (periodicActionComponent != null) { final long oldWakeUp = periodicActionComponent.getLowestWakeUp(); periodicActionComponent.addScheduledActionId(actionId, scheduleTime, period); entity.saveComponent(periodicActionComponent); final long newWakeUp = periodicActionComponent.getLowestWakeUp(); if (oldWakeUp < newWakeUp) { periodicOperationsSortedByTime.remove(oldWakeUp, entity); periodicOperationsSortedByTime.put(newWakeUp, entity); } else { // Even if the oldWakeUp time is greater than or equal to the new one, the next action should still be added // to the delayedOperationsSortedByTime mapping. periodicOperationsSortedByTime.put(scheduleTime, entity); } } else { periodicActionComponent = new PeriodicActionComponent(); periodicActionComponent.addScheduledActionId(actionId, scheduleTime, period); entity.addComponent(periodicActionComponent); } }
@Override public void addDelayedAction(EntityRef entity, String actionId, long delay) { long scheduleTime = time.getGameTimeInMs() + delay; DelayedActionComponent delayedActionComponent = entity.getComponent(DelayedActionComponent.class); if (delayedActionComponent != null) { final long oldWakeUp = delayedActionComponent.getLowestWakeUp(); delayedActionComponent.addActionId(actionId, scheduleTime); entity.saveComponent(delayedActionComponent); final long newWakeUp = delayedActionComponent.getLowestWakeUp(); if (oldWakeUp < newWakeUp) { delayedOperationsSortedByTime.remove(oldWakeUp, entity); delayedOperationsSortedByTime.put(newWakeUp, entity); } else { // Even if the oldWakeUp time is greater than or equal to the new one, the next action should still be added // to the delayedOperationsSortedByTime mapping. delayedOperationsSortedByTime.put(scheduleTime, entity); } } else { delayedActionComponent = new DelayedActionComponent(); delayedActionComponent.addActionId(actionId, scheduleTime); entity.addComponent(delayedActionComponent); } }
@Override public void cancelPeriodicAction(EntityRef entity, String actionId) { PeriodicActionComponent periodicActionComponent = entity.getComponent(PeriodicActionComponent.class); long oldWakeUp = periodicActionComponent.getLowestWakeUp(); periodicActionComponent.removeScheduledActionId(actionId); long newWakeUp = periodicActionComponent.getLowestWakeUp(); if (!periodicActionComponent.isEmpty() && oldWakeUp < newWakeUp) { periodicOperationsSortedByTime.remove(oldWakeUp, entity); periodicOperationsSortedByTime.put(newWakeUp, entity); } else if (periodicActionComponent.isEmpty()) { periodicOperationsSortedByTime.remove(oldWakeUp, entity); } saveOrRemoveComponent(entity, periodicActionComponent); }
@Override public void cancelDelayedAction(EntityRef entity, String actionId) { DelayedActionComponent delayedComponent = entity.getComponent(DelayedActionComponent.class); long oldWakeUp = delayedComponent.getLowestWakeUp(); delayedComponent.removeActionId(actionId); long newWakeUp = delayedComponent.getLowestWakeUp(); if (!delayedComponent.isEmpty() && oldWakeUp < newWakeUp) { delayedOperationsSortedByTime.remove(oldWakeUp, entity); delayedOperationsSortedByTime.put(newWakeUp, entity); } else if (delayedComponent.isEmpty()) { delayedOperationsSortedByTime.remove(oldWakeUp, entity); } saveOrRemoveComponent(entity, delayedComponent); }
private static SortedSetMultimap<Integer, byte[]> getRowsForBatches( Supplier<SqlConnection> connectionSupplier, String query, Object[] args) { SqlConnection connection = connectionSupplier.get(); try { AgnosticResultSet results = connection.selectResultSetUnregisteredQuery(query, args); SortedSetMultimap<Integer, byte[]> ret = TreeMultimap.create( Ordering.natural(), UnsignedBytes.lexicographicalComparator()); for (AgnosticResultRow row : results.rows()) { @SuppressWarnings("deprecation") byte[] rowName = row.getBytes("row_name"); int batchNum = row.getInteger("batch_num"); if (rowName != null) { ret.put(batchNum, rowName); } } return ret; } finally { closeSql(connection); } }
private void internalAdd(int idx, final Document document) { for (String field : document.getFieldNames()) { Iterator<AToken> tokens = parser.parseDocumentField(field, document.getField(field)); SortedSetMultimap<String, Integer> termPositions = TreeMultimap.create(); int tokenCount = 0; while (tokens.hasNext()) { tokenCount++; AToken token = tokens.next(); termPositions.put(token.getText(), token.getPosition()); } for (String term : termPositions.keySet()) { Key key = new Key(field, term); SortedSet<Integer> positionsSet = termPositions.get(term); int[] positions = new int[positionsSet.size()]; int p = 0; for (Integer i : positionsSet) { positions[p++] = i; } DocTermMatchList original = invertedIndex.putIfAbsent(key, new DocTermMatchList(idx, positions, tokenCount)); if (original != null) { original.add(idx, positions, tokenCount); } } } }
@Override public void put(Window window, K key, V value) { @SuppressWarnings("unchecked") Window.SessionWindow<K> sessionWindow = (Window.SessionWindow<K>)window; super.put(window, key, value); keyToWindows.put(key, sessionWindow); }
@VisibleForTesting void appendHttpHeaders(HttpRequest request, SortedSetMultimap<String, String> canonicalizedHeaders) { Multimap<String, String> headers = request.getHeaders(); for (Entry<String, String> header : headers.entries()) { if (header.getKey() == null) continue; String key = header.getKey().toString().toLowerCase(Locale.getDefault()); // Ignore any headers that are not particularly interesting. if (key.equalsIgnoreCase(HttpHeaders.CONTENT_TYPE) || key.equalsIgnoreCase("Content-MD5") || key.equalsIgnoreCase(HttpHeaders.DATE) || key.startsWith("x-" + headerTag + "-")) { canonicalizedHeaders.put(key, header.getValue()); } } }
private Multimap<String, Bundle> buildMap(List<Bundle> bundles) { SortedSetMultimap<String, Bundle> result = TreeMultimap.create(Collator.getInstance(), new BundleVersionComparator()); for (Bundle bundle : bundles) { result.put(bundle.getSymbolicName(), bundle); } return result; }
@Override public void migrateWindow(Window.SessionWindow<K> fromWindow, Window.SessionWindow<K> toWindow) { if (!containsWindow(fromWindow)) { throw new NoSuchElementException(); } map.put(toWindow, map.remove(fromWindow)); keyToWindows.remove(fromWindow.getKey(), fromWindow); keyToWindows.put(toWindow.getKey(), toWindow); }