/** * Returns the sum of the given lists. This is their intersection * subtracted from their union. * * @param <E> the element type * @param list1 the first list * @param list2 the second list * @return a new list containing the sum of those lists * @throws NullPointerException if either list is null */ public static <E> List<E> sum(final List<? extends E> list1, final List<? extends E> list2) { return subtract(union(list1, list2), intersection(list1, list2)); }
private void cleanupRegistry(SubscriptionName subscriptionName, List<String> currentConsumers) throws Exception { List<String> previousConsumers = rateInfos.keySet().stream() // FIXME what if the previous consumer is not in rateInfos? .filter(c -> c.getSubscription().equals(subscriptionName)) .map(c -> c.getConsumerId()).collect(Collectors.toList()); List<String> toRemove = ListUtils.subtract(previousConsumers, currentConsumers); if (!toRemove.isEmpty()) { logger.info("Removing consumers for max rates for subscription {}: {}", subscriptionName, toRemove); } toRemove.forEach(removedConsumer -> removeConsumerEntries(subscriptionName, removedConsumer)); }
private void cleanupRegistry(SubscriptionName subscriptionName, List<String> currentConsumers) throws Exception { List<String> previousConsumers = rateInfos.keySet().stream() // FIXME what if the previous consumer is not in rateInfos? .filter(c -> c.getSubscription().equals(subscriptionName)) .map(c -> c.getConsumerId()).collect(Collectors.toList()); List<String> toRemove = ListUtils.subtract(previousConsumers, currentConsumers); if (!toRemove.isEmpty()) { logger.info("Removing consumers for max rates for subscription {}: {}", subscriptionName, toRemove); } toRemove.forEach(removedConsumer -> removeConsumerEntries(subscriptionName, removedConsumer)); }
private List<TimedValue> getLatestTimedValuesForSubjectAndAttributes(Subject subject, List<AttributeMatcher> attributeMatchers) throws IncomputableFieldException { List<Attribute> attributes = getAttributes(attributeMatchers); List<TimedValue> timedValues = TimedValueUtils.getLatestBySubjectAndAttributes(subject, attributes); // We check for and throw on missing timedValues with some info on what they are if (timedValues.size() != attributeMatchers.size()) { List<Attribute> presentAttributes = timedValues.stream().map(timedValue -> timedValue.getId().getAttribute()).collect(Collectors.toList()); List<Attribute> missingAttributes = ListUtils.subtract(attributes, presentAttributes); String missingAttributesString = missingAttributes.stream().map(Attribute::getLabel).collect(Collectors.joining(", ")); throw new IncomputableFieldException(String.format("No TimedValue found for attributes %s", missingAttributesString)); } return timedValues; }