List of usage examples for com.google.common.collect Sets difference
public static <E> SetView<E> difference(final Set<E> set1, final Set<?> set2)
From source file:org.apache.usergrid.persistence.collection.mvcc.changelog.ChangeLogGeneratorImpl.java
/** * See parent comment {@link ChangeLogGenerator#getChangeLog(java.util.Collection)} *//*from ww w . j av a 2 s . c o m*/ @Override public ChangeLog getChangeLog(Collection<MvccEntity> mvccEntities) { Preconditions.checkArgument(mvccEntities.size() > 0, "You must specify at least 1 entities for a change log"); //TODO, this is a SWAG on the entity size, this may be too little or too much. final ChangeLogImpl changeLog = new ChangeLogImpl(50); Iterator<MvccEntity> iterator = mvccEntities.iterator(); Set<String> previousFieldNames = getFieldNames(iterator.next().getEntity()); Set<String> currentFieldNames = null; while (iterator.hasNext()) { final MvccEntity mvccEntity = iterator.next(); currentFieldNames = getFieldNames(mvccEntity.getEntity()); if (mvccEntity.getStatus() == MvccEntity.Status.DELETED) { changeLog.clear(); continue; } final Entity currentEntity = mvccEntity.getEntity().orNull(); //get all fields in the current field that aren't in the previous fields final Set<String> deletedFields = Sets.difference(previousFieldNames, currentFieldNames); changeLog.addDeletes(deletedFields); for (String addedField : currentFieldNames) { changeLog.addWrite(currentEntity.getField(addedField)); } previousFieldNames = currentFieldNames; } //subtract off the the last set of fields from the entity if (currentFieldNames != null) { changeLog.clear(currentFieldNames); } return changeLog; }
From source file:org.dllearner.learningproblems.EvaluationCache.java
/** * Determines which examples are instances of a concept. * @param concept the concept//from ww w. ja va 2s .co m * @return A tuple of two sets, where the first element is the * set of individuals belonging to the class and the second element * is the set of individuals not belonging to the class. For all * elements, which are in neither of the sets, the cache cannot * safely determine whether they are concept instances or not. */ public SortedSetTuple<OWLIndividual> infer(OWLClassExpression concept) { if (checkForEqualConcepts) { Set<OWLIndividual> pos = cache.get(concept); Set<OWLIndividual> neg = Sets.difference(examples, pos); return new SortedSetTuple<>(pos, neg); } else { // for a negation NOT C we can only say which concepts are not in it // (those in C), but we cannot say which ones are in NOT C // for a conjunction we know that the intersection of instances // of all children belongs to the concept if (concept instanceof OWLObjectIntersectionOf) { handleMultiConjunction((OWLObjectIntersectionOf) concept); // disjunctions are similar to conjunctions but we use union here; // note that there can be instances which are neither in a concept // C nor in a concept D, but in (C OR D) } else if (concept instanceof OWLObjectUnionOf) { List<OWLClassExpression> operands = ((OWLObjectUnionOf) concept).getOperandsAsList(); Set<OWLIndividual> pos = cache.get(operands.get(0)); for (int i = 1; i < operands.size(); i++) { pos = Sets.union(pos, cache.get(operands.get(i))); } // in all other cases we cannot infer anything, so we return an // empty tuple } else { return new SortedSetTuple<>(); } } return null; }
From source file:dagger.internal.codegen.MultibindingExpression.java
/** * Returns the subset of {@code dependencies} that represent multibinding contributions that were * not included in a superclass implementation of this multibinding method. This is relevant only * for ahead-of-time subcomponents. When not generating ahead-of-time subcomponents there is only * one implementation of a multibinding expression and all {@link DependencyRequest}s from the * argment are returned./*from www. j a v a2s . c om*/ */ protected SetView<DependencyRequest> getNewContributions(ImmutableSet<DependencyRequest> dependencies) { return Sets.difference(dependencies, superclassContributions()); }
From source file:com.facebook.buck.android.dalvik.DalvikAwareOutputStreamHelper.java
private boolean isEntryTooBig(FileLike entry) { DalvikStatsTool.Stats stats = dalvikStatsCache.getStats(entry); if (currentLinearAllocSize + stats.estimatedLinearAllocSize > linearAllocLimit) { return true; }//from ww w.j a va2 s . c o m int newMethodRefs = Sets.difference(stats.methodReferences, currentMethodReferences).size(); if (currentMethodReferences.size() + newMethodRefs > MAX_METHOD_REFERENCES) { return true; } int newFieldRefs = Sets.difference(stats.fieldReferences, currentFieldReferences).size(); return currentFieldReferences.size() + newFieldRefs > MAX_FIELD_REFERENCES; }
From source file:com.googlecode.blaisemath.graph.mod.layout.SpringLayout.java
@InvokedFromThread("unknown") @Override// w w w . j a v a 2 s. c o m public final synchronized <C> double iterate(Graph<C> og, SpringLayoutState state, SpringLayoutParameters params) { Graph<C> g = og.isDirected() ? GraphUtils.copyAsUndirectedSparseGraph(og) : og; Set<C> nodes = g.nodes(); Set<C> pinned = params.getConstraints().getPinnedNodes(); Set<C> unpinned = Sets.difference(nodes, pinned).immutableCopy(); double energy; state.nodeLocationSync(nodes); state.updateRegions(params.maxRepelDist); Map<C, Point2D.Double> forces = Maps.newHashMap(); computeNonRepulsiveForces(g, nodes, pinned, forces, state, params); computeRepulsiveForces(pinned, forces, state, params); checkForces(unpinned, forces); energy = move(g, unpinned, forces, state, params); return energy; }
From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.compile.library.Randomize.java
private static List<List<TemplateElement>> createChoices(final int starsCount) { final ImmutableList.Builder<List<TemplateElement>> builder = ImmutableList.builder(); final String space = AIML.WORD_DELIMITER.getValue(); final String randomStart = RANDOM_START; final String randomEnd = RANDOM_END; final ImmutableSortedSet<Integer> set = ContiguousSet.create(Range.closed(1, starsCount), DiscreteDomain.integers());/*w ww . j a va 2 s . c om*/ for (int picked = 1; picked <= starsCount; picked++) { final Star pickedStar = Star.create(new AIMLIndex(picked)); final SetView<Integer> rest = Sets.difference(set, ImmutableSet.of(picked)); // @formatter:off // <li><star index="3"/> <srai>RANDOMSTART <srai>REMOVESTART <star index="3"/> <star index="1"/> <star index="2"/> <star index="4"/> REMOVEEND</srai> RANDOMEND</srai><li> builder.add(ImmutableList.<TemplateElement>of(pickedStar, Text.create(space), Srai.create(Text.create(randomStart + space), Srai.create(removeCopies(pickedStar, rest)), Text.create(space + randomEnd)))); // @formatter:on } return builder.build(); }
From source file:nl.thehyve.podium.service.RoleService.java
private void copyProperties(RoleRepresentation source, Role target) { Set<UUID> currentUsers = target.getUsers().stream().map(User::getUuid).collect(Collectors.toSet()); Set<UUID> desiredUsers = source.getUsers(); Set<UUID> deleteUsers = Sets.difference(currentUsers, desiredUsers); Set<UUID> addUsers = Sets.difference(desiredUsers, currentUsers); Set<User> result = target.getUsers().stream().filter(u -> !deleteUsers.contains(u.getUuid())) .collect(Collectors.toSet()); for (UUID userUuid : addUsers) { Optional<User> user = userService.getDomainUserByUuid(userUuid); if (user.isPresent()) { result.add(user.get());/* w w w . j a va 2 s . c o m*/ } else { throw new ResourceNotFound(String.format("Could not find user with uuid %s", userUuid)); } } target.setUsers(result); }
From source file:io.github.egonw.analysis.FunctionalGroupsFilter.java
static private void subsumeSubsets() { if (workingSets.isEmpty()) { return;/*from w w w. j a va 2 s . c o m*/ } Integer count = 0; while (workingSets.size() > count) { RichAtomSet outer = workingSets.get(count++); Integer i = workingSets.size() - 1; while (i >= count) { RichAtomSet inner = workingSets.get(i--); if (Sets.difference(inner.getComponents(), outer.getComponents()).isEmpty()) { workingSets.remove(inner); } } } }
From source file:com.linecorp.armeria.client.endpoint.healthcheck.EndpointHealthStateGaugeSet.java
@Override public Map<String, Metric> getMetrics() { return ImmutableMap.of(METRIC_NAME_PREFIX + metricName + ".all.count", (Gauge<Integer>) endpointGroup.allServers::size, METRIC_NAME_PREFIX + metricName + ".healthy.count", (Gauge<Integer>) endpointGroup.healthyEndpoints::size, METRIC_NAME_PREFIX + metricName + ".healthy.endpoints", (Gauge<Set<String>>) () -> ImmutableSet.copyOf(endpointGroup.healthyEndpoints).stream() .map(Endpoint::authority).collect(toImmutableSet()), METRIC_NAME_PREFIX + metricName + ".unhealthy.endpoints", (Gauge<Set<String>>) () -> { Set<String> all = ImmutableSet.copyOf(endpointGroup.allServers).stream() .map(ServerConnection::endpoint).map(Endpoint::authority).collect(toImmutableSet()); Set<String> healthy = ImmutableSet.copyOf(endpointGroup.healthyEndpoints).stream() .map(Endpoint::authority).collect(toImmutableSet()); return Sets.difference(all, healthy); });/*from w ww .ja va2s .co m*/ }
From source file:com.opengamma.web.analytics.LoggingViewportListener.java
@Override public void viewportUpdated(ViewportDefinition currentDef, ViewportDefinition newDef, GridStructure gridStructure) {// w w w. j av a 2s .co m if (currentDef.enableLogging() && newDef.enableLogging()) { // logging enabled for both versions of the viewport Set<GridCell> currentCells = Sets.newHashSet(currentDef.iterator()); Set<GridCell> newCells = Sets.newHashSet(newDef.iterator()); Set<GridCell> cellsRemoved = Sets.difference(currentCells, newCells); Set<GridCell> cellsAdded = Sets.difference(newCells, currentCells); enableLogging(targetsFor(cellsAdded.iterator(), gridStructure)); disableLogging(targetsFor(cellsRemoved.iterator(), gridStructure)); } else if (!currentDef.enableLogging() && newDef.enableLogging()) { // no logging for current viewport, increase log level for all cells enableLogging(targetsFor(newDef.iterator(), gridStructure)); } else if (currentDef.enableLogging() && !newDef.enableLogging()) { // reduce logging level for all cells in current viewport disableLogging(targetsFor(currentDef.iterator(), gridStructure)); } }