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.jackrabbit.oak.run.osgi.ConfigTracker.java
/** * Synchronizes the configs. All config added by this class is also kept in sync with re runs * i.e. if a config was added in first run and say later removed then that would also be removed * from the ConfigurationAdmin//from w w w . ja v a2s .co m */ private void synchronizeConfigs(ConfigInstaller configInstaller) throws Exception { Set<String> existingPids = configInstaller.determineExistingConfigs(); Map<String, Map<String, Object>> configs = Maps.newHashMap(); Map<String, Map<String, Object>> configFromFile = parseJSONConfig( (String) config.get(OakOSGiRepositoryFactory.REPOSITORY_CONFIG_FILE)); configs.putAll(configFromFile); @SuppressWarnings("unchecked") Map<String, Map<String, Object>> runtimeConfig = (Map<String, Map<String, Object>>) config .get(OakOSGiRepositoryFactory.REPOSITORY_CONFIG); if (runtimeConfig != null) { configs.putAll(runtimeConfig); } configInstaller.installConfigs(configs); //Find out the config *installed by ConfigInstaller* and are not present in //current config files. Such configs must be remove. Note it does not lead to //removal of configs added by using ConfigAdmin directly, say using WebConsole //ui Set<String> pidsToBeRemoved = Sets.difference(existingPids, configs.keySet()); configInstaller.removeConfigs(pidsToBeRemoved); }
From source file:org.apache.druid.data.input.parquet.avro.ParquetAvroHadoopInputRowParser.java
/** * imitate avro extension {@link org.apache.druid.data.input.avro.AvroParsers#parseGenericRecord} */// w ww . j av a 2 s . co m @Override public List<InputRow> parseBatch(GenericRecord record) { Map<String, Object> row = recordFlattener.flatten(record); final List<String> dimensions = parseSpec.getDimensionsSpec().hasCustomDimensions() ? parseSpec.getDimensionsSpec().getDimensionNames() : new ArrayList( Sets.difference(row.keySet(), parseSpec.getDimensionsSpec().getDimensionExclusions())); // check for parquet Date // https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#date LogicalType logicalType = determineTimestampSpecLogicalType(record.getSchema(), timestampSpec.getTimestampColumn()); DateTime dateTime; if (logicalType instanceof LogicalTypes.Date) { int daysSinceEpoch = (Integer) record.get(timestampSpec.getTimestampColumn()); dateTime = DateTimes.utc(TimeUnit.DAYS.toMillis(daysSinceEpoch)); } else { // Fall back to a binary format that will be parsed using joda-time dateTime = timestampSpec.extractTimestamp(row); } return ImmutableList.of(new MapBasedInputRow(dateTime, dimensions, row)); }
From source file:org.eclipse.sw360.datahandler.couchdb.AttachmentConnector.java
public void deleteAttachmentDifference(Set<Attachment> before, Set<Attachment> after) { // it is important to take the set difference between sets of ids, not of attachments themselves // otherwise, when `after` contains the same attachment (with the same id), but with one field changed (e.g. sha1), // then they are considered unequal and the set difference will contain this attachment and therefore // deleteAttachments(Collection<Attachment>) will delete an attachment that is present in `after` deleteAttachmentsByIds(Sets.difference(getAttachmentContenIds(before), getAttachmentContenIds(after))); }
From source file:co.mitro.core.server.BeforeAfterState.java
public void trackUsers(Set<Integer> userIds) throws SQLException { // don't query users that we already have. Set<Integer> usersToQuery = Sets.difference(userIds, userIdToSecretIds.keySet()); addUserDataToSet(usersToQuery, this.userIdToSecretIds); }
From source file:com.google.devtools.build.lib.analysis.Util.java
public static ImmutableSet<ConfiguredTargetKey> findImplicitDeps(RuleContext ruleContext) { // (1) Consider rule attribute dependencies. Set<ConfiguredTargetKey> maybeImplicitDeps = CompactHashSet.create(); Set<ConfiguredTargetKey> explicitDeps = CompactHashSet.create(); AttributeMap attributes = ruleContext.attributes(); ListMultimap<String, ConfiguredTargetAndData> targetMap = ruleContext.getConfiguredTargetAndDataMap(); for (String attrName : attributes.getAttributeNames()) { List<ConfiguredTargetAndData> attrValues = targetMap.get(attrName); if (attrValues != null && !attrValues.isEmpty()) { if (attributes.isAttributeValueExplicitlySpecified(attrName)) { addLabelsAndConfigs(explicitDeps, attrValues); } else { addLabelsAndConfigs(maybeImplicitDeps, attrValues); }//w w w . j a va 2 s . com } } // (2) Consider toolchain dependencies ToolchainContext toolchainContext = ruleContext.getToolchainContext(); if (toolchainContext != null) { BuildConfiguration config = ruleContext.getConfiguration(); for (Label toolchain : toolchainContext.getResolvedToolchainLabels()) { maybeImplicitDeps.add(ConfiguredTargetKey.of(toolchain, config)); } maybeImplicitDeps.add(ConfiguredTargetKey.of(toolchainContext.getExecutionPlatform().label(), config)); maybeImplicitDeps.add(ConfiguredTargetKey.of(toolchainContext.getTargetPlatform().label(), config)); } return ImmutableSet.copyOf(Sets.difference(maybeImplicitDeps, explicitDeps)); }
From source file:org.dishevelled.venn.model.TernaryVennModelImpl.java
/** * Create a new ternary venn model with the specified sets. * * @param first first set, must not be null * @param second second set, must not be null * @param third third set, must not be null */// ww w .ja v a2s . com public TernaryVennModelImpl(final Set<? extends E> first, final Set<? extends E> second, final Set<? extends E> third) { if (first == null) { throw new IllegalArgumentException("first must not be null"); } if (second == null) { throw new IllegalArgumentException("second must not be null"); } if (third == null) { throw new IllegalArgumentException("third must not be null"); } // todo defensive copy? this.first = new ObservableSetImpl(first); this.second = new ObservableSetImpl(second); this.third = new ObservableSetImpl(third); // alias ObservableSet<E> f = this.first; ObservableSet<E> s = this.second; ObservableSet<E> t = this.third; firstOnly = Sets.difference(Sets.difference(f, s), t); // f - s - t secondOnly = Sets.difference(Sets.difference(s, f), t); // s - f - t thirdOnly = Sets.difference(Sets.difference(t, f), s); // t - f - s firstSecond = Sets.difference(Sets.intersection(f, s), t); // f n s - t firstThird = Sets.difference(Sets.intersection(f, t), s); // f n t - s secondThird = Sets.difference(Sets.intersection(s, t), f); // s n t - f intersection = Sets.intersection(f, Sets.intersection(s, t)); // f n s n t union = Sets.union(f, Sets.union(s, t)); // f u s u t selection = new SelectionView<E>(union, f, s, t); exclusives = new HashMap<ImmutableBitSet, Set<E>>(7); exclusives.put(toImmutableBitSet(0), firstOnly); exclusives.put(toImmutableBitSet(1), secondOnly); exclusives.put(toImmutableBitSet(2), thirdOnly); exclusives.put(toImmutableBitSet(0, 1), firstSecond); exclusives.put(toImmutableBitSet(0, 2), firstThird); exclusives.put(toImmutableBitSet(1, 2), secondThird); exclusives.put(toImmutableBitSet(0, 1, 2), intersection); }
From source file:blockplus.model.polyomino.PolyominoProperties.java
private static Iterable<IPosition> computeLights(final Set<IPosition> corners, final Set<IPosition> sides) { return Sets.difference(corners, sides); }
From source file:edu.cmu.lti.oaqa.bioqa.providers.kb.CachedUtsSynonymExpansionProvider.java
@Override public Map<String, Set<String>> getSynonyms(Collection<String> ids) throws AnalysisEngineProcessException { Map<String, Set<String>> ret = ids.stream().filter(id2synonyms::containsKey) .collect(Collectors.toMap(Function.identity(), id2synonyms::get)); Set<String> mids = Sets.difference(ImmutableSet.copyOf(ids), ret.keySet()); LOG.info("Retrieved {} from cache, requesting {} missing concepts.", ret.size(), mids.size()); Map<String, Set<String>> mids2synonysm = delegate.getSynonyms(mids); ret.putAll(mids2synonysm);/*from w ww . j av a 2 s .c o m*/ id2synonyms.putAll(mids2synonysm); db.commit(); db.getEngine().clearCache(); return ret; }
From source file:com.cloudera.csd.validation.references.constraints.SubstitutionConstraint.java
@Override public List<ConstraintViolation<T>> checkConstraint(Annotation annotation, Object obj, DescriptorPath path, SetMultimap<ReferenceType, String> allowedRefs) { AvailableSubstitutions ref = (AvailableSubstitutions) annotation; Method method = path.getHeadNode().as(PropertyNode.class).getMethod(); Set<SubstitutionType> types = ImmutableSet.copyOf(ref.type()); Collection<String> templates = getIds(method, obj); List<ConstraintViolation<T>> errors = Lists.newArrayList(); for (String template : templates) { Set<String> variables = interpolator.getVariables(template); Set<String> candidates = Sets.newLinkedHashSet(); for (SubstitutionType type : types) { if (type == SubstitutionType.PARAMETERS) { candidates.addAll(allowedRefs.get(ReferenceType.PARAMETER)); } else { candidates.add(type.toString().toLowerCase()); }//from w w w. j av a 2 s . c o m } Set<String> badVars = Sets.difference(variables, candidates); if (!badVars.isEmpty()) { errors.add(createViolation(template, path, badVars, candidates)); } } return errors; }
From source file:com.infinities.skyport.cache.secondlevel.PatchHandler.java
@SuppressWarnings("unchecked") private void onEntitiesRefreshed(RefreshedEvent<T> e) throws Exception { Collection<T> refreshedCaches = e.getNewEntries(); Set<T> productsAdded = new HashSet<T>(); Set<T> productsRemoved = new HashSet<T>(); Set<T> productsChanged = new HashSet<T>(); Map<String, T> newCache = new HashMap<String, T>(); Map<String, DiffResult> patchs = new HashMap<String, DiffResult>(); for (T newProduct : refreshedCaches) { T product = (T) BeanUtils.cloneBean(newProduct); String id = BeanUtils.getProperty(product, idProperty); newCache.put(id, product);//from www .j ava 2 s. c om T oldProduct = cache.get(id); if (oldProduct == null) { productsAdded.add(product); continue; } int compare = comparator.compare(oldProduct, product); if (compare != 0) { DiffResult patch = patchBuilder.diff(oldProduct, product); patchs.put(id, patch); productsChanged.add(product); } } Set<String> idsRemoved = Sets.difference(cache.keySet(), newCache.keySet()); for (String id : idsRemoved) { T product = cache.get(id); productsRemoved.add(product); } cache.clear(); cache.putAll(newCache); if (!productsRemoved.isEmpty()) { GenericSuccessEvent<T> event = new GenericSuccessEvent<T>(Type.REMOVED, e.getConfigid(), productsRemoved); fireEvent(event); } if (!productsAdded.isEmpty()) { GenericSuccessEvent<T> event = new GenericSuccessEvent<T>(Type.ADDED, e.getConfigid(), productsAdded); fireEvent(event); } if (!productsChanged.isEmpty()) { GenericSuccessEvent<T> event = new GenericSuccessEvent<T>(Type.MODIFIED, e.getConfigid(), productsChanged); event.getPatchs().putAll(patchs); fireEvent(event); } GenericSuccessEvent<T> event = new GenericSuccessEvent<T>(Type.REFRESHED, e.getConfigid(), new ArrayList<T>(newCache.values())); fireEvent(event); }