public void testSynchronizedSortedSetMultimap() { SortedSetMultimap<String, Integer> multimap = Multimaps.synchronizedSortedSetMultimap(TreeMultimap.<String, Integer>create()); multimap.putAll("foo", Arrays.asList(3, -1, 2, 4, 1)); multimap.putAll("bar", Arrays.asList(1, 2, 3, 1)); assertThat(multimap.removeAll("foo")).containsExactly(-1, 1, 2, 3, 4).inOrder(); assertFalse(multimap.containsKey("foo")); assertThat(multimap.replaceValues("bar", Arrays.asList(6, 5))) .containsExactly(1, 2, 3) .inOrder(); assertThat(multimap.get("bar")).containsExactly(5, 6).inOrder(); }
@ReceiveEvent public void delayedComponentActivated(OnActivatedComponent event, EntityRef entity, DelayedActionComponent delayedActionComponent) { delayedOperationsSortedByTime.put(delayedActionComponent.getLowestWakeUp(), entity); }
public void testAsMapGetImplementsSortedSet() { for (K key : multimap().keySet()) { SortedSet<V> valueSet = (SortedSet<V>) multimap().asMap().get(key); assertEquals(multimap().valueComparator(), valueSet.comparator()); } }
public void testAsMapValuesImplementSortedSet() { for (Collection<V> valueCollection : multimap().asMap().values()) { SortedSet<V> valueSet = (SortedSet<V>) valueCollection; assertEquals(multimap().valueComparator(), valueSet.comparator()); } }
public void testValueComparator() { assertEquals(multimap().valueComparator(), multimap().get(k0()).comparator()); } }
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); } }); }
public Collection<Stream> getByName(String name) { return nameToStream.get(name); }
public void testNewSortedSetMultimap() { CountingSupplier<TreeSet<Integer>> factory = new SortedSetSupplier(); Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class); SortedSetMultimap<Color, Integer> multimap = Multimaps.newSortedSetMultimap(map, factory); // newSortedSetMultimap calls the factory once to determine the comparator. assertEquals(1, factory.count); multimap.putAll(Color.BLUE, asList(3, 1, 4)); assertEquals(2, factory.count); multimap.putAll(Color.RED, asList(2, 7, 1, 8)); assertEquals(3, factory.count); assertEquals("[4, 3, 1]", multimap.get(Color.BLUE).toString()); assertEquals(INT_COMPARATOR, multimap.valueComparator()); }
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)")); sortedApi.putAll("external", ExternalApiWhitelist.CLASSES.stream() .map(clazz->clazz.getName() + " (CLASS)").collect(Collectors.toSet())); sortedApi.putAll("external", ExternalApiWhitelist.PACKAGES.stream() .map(packagee->packagee + " (PACKAGE)").collect(Collectors.toSet())); for (String key : sortedApi.keySet()) { System.out.println("## " + key + "\n"); for (String value : sortedApi.get(key)) { System.out.println("* " + value);
@Override public Comparator<? super V> valueComparator() { synchronized (mutex) { return delegate().valueComparator(); } }
@Override public Comparator<? super V> valueComparator() { return delegate().valueComparator(); } }
public void updateRelInMap( SortedSetMultimap<RelNode, CorrelationId> mapRefRelToCorVar) { for (RelNode rel : Lists.newArrayList(mapRefRelToCorVar.keySet())) { if (oldToNewRelMap.containsKey(rel)) { SortedSet<CorrelationId> corVarSet = mapRefRelToCorVar.removeAll(rel); mapRefRelToCorVar.putAll(oldToNewRelMap.get(rel), corVarSet); } } }
@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 SortedSet<V> replaceValues(K key, Iterable<? extends V> values) { return delegate().replaceValues(key, values); }
@Override public SortedSet<V> replaceValues(K key, Iterable<? extends V> values) { synchronized (mutex) { return delegate().replaceValues(key, values); // copy not synchronized } }
private Multimap<PortalCollection, String> getLicenses(Long organisationId) { SortedSetMultimap<Collection, ReadableInterval> intervals = licenseCache.getAvailableIntervals(organisationId); ListMultimap<PortalCollection, String> licenseInformation = ArrayListMultimap.create(); for (Collection key : intervals.keySet()) { SortedSet<ReadableInterval> collectionIntervals = intervals.get(key); List<String> values = convertIntervals(collectionIntervals); licenseInformation.putAll(toPortalCollection(key), values); } return licenseInformation; }
@GwtIncompatible // SerializableTester public void testNewSortedSetMultimapSerialization() { CountingSupplier<TreeSet<Integer>> factory = new SortedSetSupplier(); Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class); SortedSetMultimap<Color, Integer> multimap = Multimaps.newSortedSetMultimap(map, factory); multimap.putAll(Color.BLUE, asList(3, 1, 4)); multimap.putAll(Color.RED, asList(2, 7, 1, 8)); SerializableTester.reserializeAndAssert(multimap); assertEquals(INT_COMPARATOR, multimap.valueComparator()); }