Example usage for com.google.common.collect Sets difference

List of usage examples for com.google.common.collect Sets difference

Introduction

In this page you can find the example usage for com.google.common.collect Sets difference.

Prototype

public static <E> SetView<E> difference(final Set<E> set1, final Set<?> set2) 

Source Link

Document

Returns an unmodifiable view of the difference of two sets.

Usage

From source file:com.facebook.buck.apple.MultiarchFileInfos.java

/**
 * Expand flavors representing a fat binary into its thin binary equivalents.
 *
 * Useful when dealing with functions unaware of fat binaries.
 *
 * This does not actually check that the particular flavor set is valid.
 *///from w ww . jav  a2 s  .c  o  m
public static ImmutableList<ImmutableSortedSet<Flavor>> generateThinFlavors(Set<Flavor> platformFlavors,
        SortedSet<Flavor> flavors) {
    Set<Flavor> platformFreeFlavors = Sets.difference(flavors, platformFlavors);
    ImmutableList.Builder<ImmutableSortedSet<Flavor>> thinTargetsBuilder = ImmutableList.builder();
    for (Flavor flavor : flavors) {
        if (platformFlavors.contains(flavor)) {
            thinTargetsBuilder.add(
                    ImmutableSortedSet.<Flavor>naturalOrder().addAll(platformFreeFlavors).add(flavor).build());
        }
    }
    return thinTargetsBuilder.build();
}

From source file:org.quackbot.Bot.java

/**
 * Send message to ALL joined channels minus ignored ones
 * @param msg   Message to send//from  w w  w  .ja va 2s.co  m
 */
public void sendAnnounceMessage(String msg) {
    Preconditions.checkNotNull(msg, "Msg must not be null");
    for (Channel channel : Sets.difference(getUserChannelDao().getAllChannels(), ignoredChannels))
        channel.send().message(msg);
}

From source file:com.facebook.buck.rules.DescribedRuleBuilder.java

public DescribedRuleBuilder(Description<T> description, final BuildRuleFactoryParams params)
        throws NoSuchBuildTargetException {
    this.description = Preconditions.checkNotNull(description);
    this.ruleFactoryParams = Preconditions.checkNotNull(params);
    this.target = params.target;

    /*/*from   ww  w.  j av a 2  s . c  o m*/
     * We're about to gather everything that looks like a dependency so that we can add them to the
     * BuildRule. We'll keep the actual dependencies declared in the "deps" parameter separate since
     * they'll be needed when constructing the Buildable.
     */

    final ImmutableSortedSet.Builder<BuildTarget> extraDeps = ImmutableSortedSet.naturalOrder();
    final ImmutableSortedSet.Builder<BuildTarget> declaredDeps = ImmutableSortedSet.naturalOrder();
    for (String rawDep : params.getOptionalListAttribute("deps")) {
        BuildTarget target = params.resolveBuildTarget(rawDep);
        declaredDeps.add(target);
        extraDeps.add(target);
    }
    this.declaredDeps = declaredDeps.build();

    // Scan the input to find possible BuildTargets, necessary for loading dependent rules.
    TypeCoercerFactory typeCoercerFactory = new TypeCoercerFactory();
    T arg = description.createUnpopulatedConstructorArg();
    for (Field field : arg.getClass().getFields()) {
        ParamInfo info = new ParamInfo(typeCoercerFactory, Paths.get(target.getBasePath()), field);
        if (info.hasElementTypes(BuildRule.class, SourcePath.class)) {
            detectBuildTargetsForParameter(extraDeps, info, params);
        }
    }
    this.extraDeps = ImmutableSortedSet.copyOf(Sets.difference(extraDeps.build(), this.declaredDeps));

    ImmutableSet.Builder<BuildTargetPattern> allVisibilities = ImmutableSet.builder();
    for (String rawVis : params.getOptionalListAttribute("visibility")) {
        allVisibilities
                .add(params.buildTargetPatternParser.parse(rawVis, ParseContext.forVisibilityArgument()));
    }
    this.visibilities = allVisibilities.build();
}

From source file:com.opengamma.bbg.referencedata.cache.AbstractPermanentErrorCachingReferenceDataProvider.java

private Map<Set<String>, Set<String>> determineSecuritiesForFieldSets(Set<String> securities,
        Set<String> fields, Map<String, Set<String>> failedFieldsMap) {
    Map<Set<String>, Set<String>> result = new HashMap<Set<String>, Set<String>>();
    for (String securityDes : securities) {
        Set<String> failedFields = failedFieldsMap.get(securityDes);
        Set<String> missingFields = null;
        if (failedFields == null) {
            missingFields = fields;/* w  w w . java 2 s  .  c o  m*/
        } else {
            missingFields = Sets.difference(fields, failedFields);
        }
        Set<String> securitiesMatchingFields = result.get(missingFields);
        if (securitiesMatchingFields == null) {
            securitiesMatchingFields = new TreeSet<String>();
            result.put(missingFields, securitiesMatchingFields);
        }
        securitiesMatchingFields.add(securityDes);
    }
    return result;
}

From source file:org.tensorics.core.tensor.lang.OngoingOrderedFlattening.java

private SetView<Class<?>> remainingDimensions() {
    return Sets.difference(tensor.shape().dimensionSet(), singleton(dimensionToFlatten));
}

From source file:co.cask.cdap.data2.metadata.system.AbstractSystemMetadataWriter.java

/**
 * Updates the {@link MetadataScope#SYSTEM} metadata for this {@link Id.NamespacedId entity}.
 *///from  www .  ja  v  a 2s.c o m
@Override
public void write() {
    // Delete existing system metadata before writing new metadata
    Set<String> existingProperties = metadataStore.getProperties(MetadataScope.SYSTEM, entityId).keySet();
    Sets.SetView<String> removeProperties = Sets.difference(existingProperties, PRESERVE_PROPERTIES);
    if (!removeProperties.isEmpty()) {
        String[] propertiesArray = removeProperties.toArray(new String[removeProperties.size()]);
        metadataStore.removeProperties(MetadataScope.SYSTEM, entityId, propertiesArray);
    }
    metadataStore.removeTags(MetadataScope.SYSTEM, entityId);

    // Now add the new metadata
    Map<String, String> properties = getSystemPropertiesToAdd();
    if (properties.size() > 0) {
        metadataStore.setProperties(MetadataScope.SYSTEM, entityId, properties);
    }
    String[] tags = getSystemTagsToAdd();
    if (tags.length > 0) {
        metadataStore.addTags(MetadataScope.SYSTEM, entityId, tags);
    }
    // if there is schema property then set that while providing schema indexer
    if (!Strings.isNullOrEmpty(getSchemaToAdd())) {
        metadataStore.setProperties(MetadataScope.SYSTEM, entityId,
                ImmutableMap.of(SCHEMA_FIELD_PROPERTY_PREFIX, getSchemaToAdd()), new SchemaIndexer());
    }
}

From source file:se.sics.caracaldb.View.java

public SetView<Address> addedSince(View oldView) {
    return Sets.difference(members, oldView.members);
}

From source file:com.linkedin.pinot.tools.admin.command.VerifySegmentState.java

@Override
public boolean execute() throws Exception {
    ZKHelixAdmin helixAdmin = new ZKHelixAdmin(zkAddress);
    List<String> resourcesInCluster = helixAdmin.getResourcesInCluster(clusterName);

    for (String resourceName : resourcesInCluster) {
        if (resourceName.startsWith(tablePrefix)) {
            IdealState resourceIdealState = helixAdmin.getResourceIdealState(clusterName, resourceName);
            ExternalView resourceExternalView = helixAdmin.getResourceExternalView(clusterName, resourceName);
            Map<String, Map<String, String>> mapFieldsFromIS = resourceIdealState.getRecord().getMapFields();
            Map<String, Map<String, String>> mapFieldsFromEV = resourceExternalView.getRecord().getMapFields();
            boolean error = false;
            if (mapFieldsFromIS.size() != mapFieldsFromEV.size()) {
                LOGGER.info("Table: {}, idealState size: {} does NOT match external view size: {}",
                        resourceName, mapFieldsFromIS.size(), mapFieldsFromEV.size());
                error = true;/*  w w w.  j  a va 2 s .co  m*/
            }
            if (!mapFieldsFromIS.keySet().equals(mapFieldsFromEV.keySet())) {
                Set<String> idealStateKeys = mapFieldsFromIS.keySet();
                Set<String> externalViewKeys = mapFieldsFromEV.keySet();
                Sets.SetView<String> isToEVDiff = Sets.difference(idealStateKeys, externalViewKeys);
                for (String segmentName : isToEVDiff) {
                    LOGGER.info("Segment: {} is missing in external view, ideal state: {}", segmentName,
                            mapFieldsFromIS.get(segmentName));
                }

                Sets.SetView<String> evToISDiff = Sets.difference(externalViewKeys, idealStateKeys);
                for (String segmentName : evToISDiff) {
                    LOGGER.error("Segment: {} is missing in ideal state, external view: {}", segmentName,
                            mapFieldsFromEV.get(segmentName));
                }
                error = true;
            }

            for (Map.Entry<String, Map<String, String>> idealEntry : mapFieldsFromIS.entrySet()) {
                String segmentName = idealEntry.getKey();
                Map<String, String> segmentIdealState = idealEntry.getValue();
                // try to format consistently for tool based parsing
                if (!mapFieldsFromEV.containsKey(segmentName)) {
                    LOGGER.info("Segment: {} idealstate: {} is MISSING in external view: {}", segmentName,
                            segmentIdealState, "");
                }
                Map<String, String> segmentExternalView = mapFieldsFromEV.get(segmentName);

                if (!segmentIdealState.equals(segmentExternalView)) {
                    LOGGER.info("Segment: {} idealstate: {} does NOT match external view: {}", segmentName,
                            segmentIdealState, segmentExternalView);
                    error = true;
                }
            }
            LOGGER.info(resourceName + " = " + (error ? "ERROR" : "OK"));
        }
    }
    return true;
}

From source file:org.apache.cassandra.io.sstable.SSTableDeletingTask.java

public void run() {
    blocker.ask();// www. j a  va2 s  .co m
    // If we can't successfully delete the DATA component, set the task to be retried later: see above
    File datafile = new File(desc.filenameFor(Component.DATA));
    if (!datafile.delete()) {
        logger.error("Unable to delete {} (it will be removed on server restart; we'll also retry after GC)",
                datafile);
        failedTasks.add(this);
        return;
    }
    // let the remainder be cleaned up by delete
    SSTable.delete(desc, Sets.difference(components, Collections.singleton(Component.DATA)));
    if (totalDiskSpaceUsed != null)
        totalDiskSpaceUsed.dec(bytesOnDisk);
}

From source file:org.apache.druid.segment.QueryableIndexIndexableAdapter.java

@Override
public List<String> getMetricNames() {
    final Set<String> columns = Sets.newLinkedHashSet(input.getColumnNames());
    final HashSet<String> dimensions = Sets.newHashSet(getDimensionNames());
    return ImmutableList.copyOf(Sets.difference(columns, dimensions));
}