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:com.intelligentsia.dowsers.entity.view.processor.Projection.java
@Override public Item apply(final Entity input) { final Item item = super.apply(input); if (item != null) { // must we do a local copy of this set ? final Iterator<String> iterator = Sets.difference(item.keySet(), attributeNames).iterator(); while (iterator.hasNext()) { item.remove(iterator.next()); }/*from w w w . j ava 2s . c o m*/ } return item; }
From source file:org.eclipse.sirius.synchronizer.MappingHiearchyTable.java
private Collection<? extends Mapping> getLeaves(Collection<? extends Mapping> mappings) { Set<Mapping> hasChildren = Sets.newLinkedHashSet(); for (Mapping mapping : mappings) { if (mapping.getSuper().some()) { hasChildren.add(mapping.getSuper().get()); }/*w w w . jav a 2s. c o m*/ } return Sets.difference(Sets.newLinkedHashSet(mappings), hasChildren); }
From source file:com.facebook.buck.dalvik.DalvikAwareOutputStreamHelper.java
private boolean isEntryTooBig(FileLike entry) { DalvikStatsTool.Stats stats = dalvikStatsCache.getStats(entry); if (currentLinearAllocSize + stats.estimatedLinearAllocSize > linearAllocLimit) { return true; }//w ww.j a va2s .c o m int newReferences = Sets.difference(stats.methodReferences, currentMethodReferences).size(); if (currentMethodReferences.size() + newReferences > MAX_METHOD_REFERENCES) { return true; } return false; }
From source file:org.glowroot.agent.fat.storage.util.Schemas.java
static void syncIndexes(@Untainted String tableName, ImmutableList<Index> indexes, Connection connection) throws SQLException { ImmutableSet<Index> desiredIndexes = ImmutableSet.copyOf(indexes); Set<Index> existingIndexes = getIndexes(tableName, connection); for (Index index : Sets.difference(existingIndexes, desiredIndexes)) { execute("drop index " + index.name(), connection); }/* w w w . ja v a 2 s . c om*/ for (Index index : Sets.difference(desiredIndexes, existingIndexes)) { createIndex(tableName, index, connection); } // test the logic existingIndexes = getIndexes(tableName, connection); if (!existingIndexes.equals(desiredIndexes)) { logger.error("the logic in syncIndexes() needs fixing"); } }
From source file:org.springframework.ide.eclipse.boot.dash.livexp.MappedValuesSet.java
/** * Called when the target set changes. This should add and remove valuelistener to * the LiveExps in the target to ensure we listen each expression. *//* www .ja v a 2 s . c om*/ private synchronized void refreshValueListeners() { ImmutableSet<LiveExpression<T>> current = target.getValues(); SetView<LiveExpression<T>> removed = Sets.difference(listenersAttached, current); SetView<LiveExpression<T>> added = Sets.difference(current, listenersAttached); for (LiveExpression<T> exp : removed) { exp.removeListener(valueListener); } for (LiveExpression<T> exp : added) { exp.addListener(valueListener); } listenersAttached = current; }
From source file:org.ambraproject.rhino.model.ingest.ArticlePackage.java
public void validateAssetCompleteness(Set<Doi> manuscriptDois) { Set<Doi> packageDois = getAllItems().stream().map(ArticleItemInput::getDoi).collect(Collectors.toSet()); Set<Doi> missingDois = Sets.difference(manuscriptDois, packageDois); if (!missingDois.isEmpty()) { String message = "Asset DOIs mentioned in manuscript are not included in package: " + missingDois.stream().map(Doi::getName).sorted().collect(Collectors.toList()); throw new RestClientException(message, HttpStatus.BAD_REQUEST); }//w ww . j ava2s.c o m }
From source file:org.eclipse.viatra.transformation.debug.model.TransformationState.java
public void updateActivations(Set<Activation<?>> nextActivations, Set<Activation<?>> conflictingActivations) { SetView<Activation<?>> addedElements = Sets.difference(conflictingActivations, Sets.newHashSet(this.conflictingActivations)); SetView<Activation<?>> removedElements = Sets.difference(Sets.newHashSet(this.conflictingActivations), conflictingActivations);/*from ww w . ja va 2s. co m*/ newActivations.addAll(addedElements); newActivations.removeAll(removedElements); this.nextActivations = Lists.newArrayList(nextActivations); this.conflictingActivations = Lists.newArrayList(conflictingActivations); }
From source file:org.dcache.gplazma.roles.RolesPlugin.java
@Override public void session(Set<Principal> principals, Set<Object> attributes) throws AuthenticationException { Set<Role> allowedRoles = allAuthorizedRoles(principals); Set<Role> desiredRoles = principals.stream().filter(DesiredRole.class::isInstance) .map(DesiredRole.class::cast).map(DesiredRole::getName).map(Role::new).collect(Collectors.toSet()); Set<Role> unauthorizedRoles = Sets.difference(desiredRoles, allowedRoles).copyInto(new HashSet<>()); if (!unauthorizedRoles.isEmpty()) { String description = unauthorizedRoles.size() == 1 ? unauthorizedRoles.iterator().next().toString() : unauthorizedRoles.stream().map(LoginAttribute::toString) .collect(Collectors.joining(",", "[", "]")); throw new AuthenticationException("unauthorized for " + description); }/* w w w . j a v a 2s. com*/ attributes.addAll(desiredRoles); Sets.difference(allowedRoles, desiredRoles).stream().map(Role::getRole).map(UnassertedRole::new) .forEach(attributes::add); }
From source file:org.eclipse.umlgen.reverse.c.internal.reconciler.Utils.java
/** * This returns only the objects which are only in the given <code>left</code> list. * * @param left/*from w ww . ja v a 2 s . c om*/ * The left list * @param right * The right list * @param function * Function which applies on the 2 lists * @param <T> * Any Java object * @param <X> * Any java object * @return The objects only in left side */ public static <X, T> Collection<T> inLeftOnly(Collection<T> left, Collection<T> right, final Function<? super T, X> function) { Set<X> leftSet = ImmutableSet.copyOf(Iterables.transform(left, function)); Set<X> rigthSet = ImmutableSet.copyOf(Iterables.transform(right, function)); Set<X> intersection = Sets.intersection(leftSet, rigthSet); final Set<X> inLeftOnlyAfterFunction = Sets.difference(leftSet, intersection); return Collections2.filter(left, new Predicate<T>() { public boolean apply(T input) { return inLeftOnlyAfterFunction.contains(function.apply(input)); } }); }
From source file:com.continuuity.weave.internal.ApplicationBundler.java
/** * Constructs a ApplicationBundler.//ww w. j ava 2s . c o m * * @param excludePackages Class packages to exclude * @param includePackages Always includes classes/resources in these packages. Note that * classes in these packages will not get inspected for dependencies. */ public ApplicationBundler(Iterable<String> excludePackages, Iterable<String> includePackages) { this.excludePackages = ImmutableList.copyOf(excludePackages); this.includePackages = ImmutableList.copyOf(includePackages); this.acceptClassPath = Sets.difference( Sets.newHashSet(Splitter.on(File.pathSeparatorChar).split(System.getProperty("java.class.path"))), Sets.newHashSet( Splitter.on(File.pathSeparatorChar).split(System.getProperty("sun.boot.class.path")))); }