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.sonar.server.computation.step.PurgeRemovedViewsStep.java
@Override public void execute(ComputationContext context) { DbSession session = dbClient.openSession(false); try {//from w w w . j a va 2 s . c o m Set<String> viewUuidsInIndex = newHashSet(index.findAllViewUuids()); Set<String> viewUuidInDb = newHashSet( dbClient.componentDao().selectExistingUuids(session, viewUuidsInIndex)); Set<String> viewsToRemove = Sets.difference(viewUuidsInIndex, viewUuidInDb); index.delete(viewsToRemove); } finally { session.close(); } }
From source file:com.facebook.buck.rules.BuildRulePipelinesRunner.java
/** Gives the factory a way to construct a {@link RunnableWithFuture} to build the given rule. */ public <T extends RulePipelineState> void addRule(SupportsPipelining<T> rule, Function<T, RunnableWithFuture<Optional<BuildResult>>> ruleStepRunnerFactory) { BuildRulePipelineStage<T> pipelineStage = getPipelineStage(rule); SupportsPipelining<T> previousRuleInPipeline = rule.getPreviousRuleInPipeline(); if (previousRuleInPipeline != null) { Preconditions.checkState(/*ww w.ja v a 2 s. co m*/ previousRuleInPipeline.getPipelineStateFactory() == rule.getPipelineStateFactory(), "To help ensure that rules have pipeline-compatible rule keys, all rules in a pipeline must share a PipelineStateFactory instance."); Preconditions.checkState( Sets.difference(rule.getBuildDeps(), previousRuleInPipeline.getBuildDeps()) .equals(Collections.singleton(previousRuleInPipeline)), "Each rule in a pipeline cannot depend on rules which are not also dependencies of the previous rule in the pipeline. This ensures that each rule in the pipeline is ready to build as soon as the previous one completes."); getPipelineStage(previousRuleInPipeline).setNextStage(pipelineStage); } pipelineStage.setRuleStepRunnerFactory(ruleStepRunnerFactory); }
From source file:org.graylog2.rest.models.messages.responses.DecorationStats.java
@SuppressWarnings("unused") @JsonProperty(FIELD_REMOVED_FIELDS)// ww w .j av a 2 s .c om public Map<String, Object> removedFields() { return Sets.difference(originalMessage().keySet(), decoratedMessage().keySet()).stream() .collect(Collectors.toMap(Function.identity(), key -> originalMessage().get(key))); }
From source file:org.eclipse.viatra.query.runtime.matchers.planning.operations.PProject.java
@Override public void checkConsistency(SubPlan subPlan) { super.checkConsistency(subPlan); final SubPlan parentPlan = subPlan.getParentPlans().get(0); Preconditions.checkArgument(parentPlan.getVisibleVariables().containsAll(toVariables), "Variables missing from project: " + Joiner.on(',').join( Sets.difference(new HashSet<PVariable>(toVariables), parentPlan.getVisibleVariables()))); }
From source file:com.google.errorprone.bugpatterns.MissingCasesInEnumSwitch.java
@Override public Description matchSwitch(SwitchTree tree, VisitorState state) { TypeSymbol switchType = ((JCSwitch) tree).getExpression().type.tsym; if (switchType.getKind() != ElementKind.ENUM) { return Description.NO_MATCH; }// www. j a v a 2s . c om if (hasDefaultCase(tree)) { return Description.NO_MATCH; } Set<String> unhandled = Sets.difference(ASTHelpers.enumValues(switchType), collectEnumSwitchCases(tree)); if (unhandled.isEmpty()) { return Description.NO_MATCH; } Description.Builder description = buildDescription(tree).setMessage(buildMessage(unhandled)); buildFixes(tree, state, unhandled, description); return description.build(); }
From source file:org.tensorics.core.tensor.lang.OngoingDimensionFlattening.java
private SetView<Class<?>> remainingDimensions() { return Sets.difference(tensor.shape().dimensionSet(), dimensionsToFlatten); }
From source file:com.publictransitanalytics.scoregenerator.distance.RangedCachingReachabilityClient.java
@Override public Map<PointLocation, WalkingCosts> getWalkingCosts(final PointLocation location, final LocalDateTime currentTime, final LocalDateTime cutoffTime) throws DistanceClientException, InterruptedException { final Duration duration = timeTracker.getDuration(currentTime, cutoffTime); final ImmutableMap.Builder<PointLocation, WalkingCosts> builder = ImmutableMap.builder(); final Set<PointLocation> uncached; final boolean updateMaxStored; final Duration maxStored = store.getMaxStored(location); if (maxStored != null) { final Map<PointLocation, WalkingCosts> cached = store.get(location, duration); builder.putAll(cached);/* www . j a v a 2 s . co m*/ if (duration.compareTo(maxStored) > 0) { uncached = Sets.difference(points, cached.keySet()); updateMaxStored = true; } else { uncached = Collections.emptySet(); updateMaxStored = false; } } else { uncached = points; updateMaxStored = true; } if (!uncached.isEmpty()) { final Map<PointLocation, WalkingCosts> estimatedCosts = estimationClient.getDistances(location, uncached); final Map<PointLocation, WalkingCosts> candidateEstimates = filterTimes(estimatedCosts, duration); final Set<PointLocation> candidates = candidateEstimates.keySet(); if (!candidates.isEmpty()) { final Map<PointLocation, WalkingCosts> candidateCosts = distanceClient.getDistances(location, candidates); final Map<PointLocation, WalkingCosts> filteredDistances = filterTimes(candidateCosts, duration); store.putAll(location, filteredDistances); builder.putAll(filteredDistances); } } if (updateMaxStored) { store.updateMaxStored(location, duration); } return builder.build(); }
From source file:info.archinnov.achilles.entity.operations.EntityInitializer.java
public <T, CONTEXT extends PersistenceContext> void initializeEntity(T entity, EntityMeta entityMeta, EntityInterceptor<CONTEXT, T> interceptor) { log.debug("Initializing lazy fields for entity {} of class {}", entity, entityMeta.getClassName()); Set<PropertyMeta> alreadyLoadedMetas = FluentIterable.from(interceptor.getAlreadyLoaded()) .transform(new AlreadyLoadedTransformer(entityMeta.getGetterMetas())).toImmutableSet(); Set<PropertyMeta> allLazyMetas = FluentIterable.from(entityMeta.getPropertyMetas().values()) .filter(lazyType).toImmutableSet(); Set<PropertyMeta> toBeLoadedMetas = Sets.difference(allLazyMetas, alreadyLoadedMetas); for (PropertyMeta propertyMeta : toBeLoadedMetas) { Object value = propertyMeta.getValueFromField(entity); if (propertyMeta.isCounter()) { Counter counter = (Counter) value; Object realObject = proxifier.getRealObject(entity); propertyMeta.setValueToField(realObject, CounterBuilder.incr(counter.get())); }/* ww w. j a v a2 s .c om*/ } for (PropertyMeta propertyMeta : alreadyLoadedMetas) { if (propertyMeta.isCounter()) { Object value = propertyMeta.getValueFromField(entity); Counter counter = (Counter) value; Object realObject = proxifier.getRealObject(entity); propertyMeta.setValueToField(realObject, CounterBuilder.incr(counter.get())); } } }
From source file:org.usergrid.persistence.query.ir.result.SubtractionIterator.java
@Override protected Set<UUID> advance() { if (!keepIterator.hasNext()) { return null; }//from w w w . j av a 2s .co m Set<UUID> results = new LinkedHashSet<UUID>(pageSize); while (keepIterator.hasNext() && results.size() < pageSize) { Set<UUID> keepPage = keepIterator.next(); while (subtractIterator.hasNext() && keepPage.size() > 0) { keepPage = Sets.difference(keepPage, subtractIterator.next()); } subtractIterator.reset(); results.addAll(keepPage); } return results; }
From source file:co.mitro.core.servlets.CreateOrganization.java
/** Returns an error message if request is not valid. Checks basic request formatting. */ static String validateRequest(RPC.CreateOrganizationRequest request) { if (Strings.isNullOrEmpty(request.name)) { return "name cannot be empty"; }/*from ww w. j ava2 s. com*/ if (Strings.isNullOrEmpty(request.publicKey)) { return "publicKey cannot be empty"; } if (request.adminEncryptedKeys == null || request.adminEncryptedKeys.isEmpty()) { return "adminEncryptedKeys cannot be empty"; } if (request.memberGroupKeys == null || request.memberGroupKeys.isEmpty()) { return "memberGroupKeys cannot be empty"; } // ensure that every admin is also a member SetView<String> adminsNotInMembers = Sets.difference(request.adminEncryptedKeys.keySet(), request.memberGroupKeys.keySet()); if (!adminsNotInMembers.isEmpty()) { return "each admin must be a member"; } return null; }