Example usage for com.google.common.collect ImmutableSet contains

List of usage examples for com.google.common.collect ImmutableSet contains

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSet contains.

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:com.google.devtools.build.lib.analysis.LocationTemplateContext.java

private LocationTemplateContext(TemplateContext delegate, RuleContext ruleContext,
        @Nullable ImmutableMap<Label, ImmutableCollection<Artifact>> labelMap, ImmutableSet<Options> options) {
    this(delegate, ruleContext.getLabel(),
            // Use a memoizing supplier to avoid eagerly building the location map.
            Suppliers.memoize(() -> LocationExpander.buildLocationMap(ruleContext, labelMap,
                    options.contains(Options.ALLOW_DATA))),
            options.contains(Options.EXEC_PATHS));
}

From source file:org.elasticsoftware.elasticactors.cluster.LocalActorRefGroup.java

@Override
public ActorRefGroup withMembersRemoved(ActorRef... membersToRemove) {
    // create a set for faster lookup
    ImmutableSet<ActorRef> memberToRemoveSet = ImmutableSet.copyOf(membersToRemove);
    ImmutableListMultimap.Builder<ActorShardRef, ActorRef> newMemberMap = ImmutableListMultimap.builder();
    for (Map.Entry<ActorShardRef, ActorRef> entry : this.members.entries()) {
        if (!memberToRemoveSet.contains(entry.getValue())) {
            newMemberMap.put(entry.getKey(), entry.getValue());
        }/*  w w w  . java 2s. co  m*/
    }
    return new LocalActorRefGroup(newMemberMap.build());
}

From source file:uk.ac.york.mondo.integration.api.EffectiveMetamodelRuleset.java

/**
 * Undoes the effects of a {@link #include(String, String)} or {@link #exclude(String, String)} call.
 *///from   ww  w  .j a  v a 2  s. c om
public void reset(String mmURI, String type) {
    ImmutableSet<String> oldInclusions = inclusions.remove(mmURI, type);
    if (oldInclusions != null && !oldInclusions.contains(WILDCARD)) {
        inclusions.put(mmURI, type, oldInclusions);
    }

    ImmutableSet<String> oldExclusions = exclusions.remove(mmURI, type);
    if (oldExclusions != null && !oldExclusions.contains(WILDCARD)) {
        exclusions.put(mmURI, type, oldExclusions);
    }
}

From source file:com.spectralogic.ds3autogen.c.CCodeGenerator.java

/**
 * Find all types that are embedded members.  Many 'top-level' types are not embedded and therefore those parsers
 * are useless./*from   www  . j a  v a2s.  com*/
 */
public static ImmutableSet<String> getEmbeddedTypes(final Ds3ApiSpec spec,
        final ImmutableSet<String> enumTypes) {
    final ImmutableSet<String> embeddedTypes = spec.getTypes().values().stream()
            .flatMap(type -> type.getElements().stream())
            .filter(element -> !element.getType().equalsIgnoreCase("array")).map(Ds3Element::getType)
            .collect(GuavaCollectors.immutableSet());
    final ImmutableSet<String> embeddedComponentTypes = spec.getTypes().values().stream()
            .flatMap(type -> type.getElements().stream())
            .filter(element -> element.getType().equalsIgnoreCase("array")).map(Ds3Element::getComponentType)
            .collect(GuavaCollectors.immutableSet());

    final ImmutableSet<String> basicTypes = ImmutableSet.of("boolean", "java.lang.Boolean", "int",
            "java.lang.Integer", "long", "java.lang.Long", "double", "java.lang.Double", "java.lang.String",
            "java.util.UUID", "java.util.Date", "java.lang.object",
            "com.spectralogic.util.db.lang.SqlOperation");

    return Stream.of(embeddedTypes, embeddedComponentTypes).flatMap(Collection::stream)
            .filter(type -> !enumTypes.contains(StructHelper.getResponseTypeName(type)))
            .filter(type -> !basicTypes.contains(type)).map(StructHelper::getResponseTypeName).sorted()
            .collect(GuavaCollectors.immutableSet());
}

From source file:com.rapid7.diskstorage.dynamodb.iterator.MultiRowParallelScanInterpreter.java

/**
 * This class relies heavily on the behavior of segmented scans with respect to which hash keys are scanned by each segment.
 * Here's a rough ASCII example to help illustrate:
 *  ___________________________//from   ww w .  j ava 2  s.c  om
 * |hk:A         |hk:B         |
 * ----------------------------
 * ^segment 1        ^segment 2
 *
 * Because we are scanning in segments across the entire hash key space, it is possible for the same hash key to appear in two different segments.
 * We are also running all of the scan segments in parallel, so we have no control over which segment returns first.
 *
 * In the example, if segment 2 was the first segment to post a result, we would store hk:B as a "boundary" key. That way when
 * segment 1 eventually reaches hk:B in its scan, we know that another segment has already returned this hash key and we can safely skip returning it.
 *
 * By doing this, we avoid returning a RecordIterator for the same hash key twice and we only need to store at most 2 hash keys per segment.
 *
 */
@Override
public List<SingleKeyRecordIterator> buildRecordIterators(ScanContext scanContext) {
    final ScanResult dynamoDbResult = scanContext.getScanResult();
    final int segment = scanContext.getScanRequest().getSegment();
    final List<Map<String, AttributeValue>> items = dynamoDbResult.getItems();
    // If the scan returned no results, we need to shortcut and just throw back an empty result set
    if (items.isEmpty()) {
        return Collections.emptyList();
    }

    List<SingleKeyRecordIterator> recordIterators = Lists.newLinkedList();

    final Iterator<Map<String, AttributeValue>> itemIterator = items.iterator();
    final Map<String, AttributeValue> firstItem = itemIterator.next();
    final StaticBuffer firstKey = new KeyBuilder(firstItem).build(Constants.TITAN_HASH_KEY);

    // Computes the full set of boundary keys up to this point. This includes the previous end key for this segment.
    final ImmutableSet<StaticBuffer> boundaryKeys = aggregateBoundaryKeys();

    // The first key in this scan segment might already have been returned by a previous scan segment
    if (!boundaryKeys.contains(firstKey)) {
        recordIterators.add(buildRecordIteratorForHashKey(firstKey));
    }

    StaticBuffer hashKey = firstKey;
    while (itemIterator.hasNext()) {
        final Optional<StaticBuffer> nextKey = findNextHashKey(itemIterator, hashKey);
        if (nextKey.isPresent()) {
            // Found a new hash key. Make a record iterator and look for the next unique hash key
            hashKey = nextKey.get();
            recordIterators.add(buildRecordIteratorForHashKey(hashKey));
        }
    }

    // If we've already seen the final hashKey in a previous scan segment result, we want to avoid returning it again.
    if (!hashKey.equals(firstKey) && boundaryKeys.contains(hashKey)) {
        recordIterators.remove(recordIterators.size() - 1);
    }

    // Update the boundary keys for this segment
    if (scanContext.isFirstResult()) {
        setInitialBoundaryKeys(segment, firstKey, hashKey);
    } else {
        updateLastKey(segment, hashKey);
    }
    return recordIterators;
}

From source file:com.amazon.janusgraph.diskstorage.dynamodb.iterator.MultiRowParallelScanInterpreter.java

/**
 * This class relies heavily on the behavior of segmented scans with respect to which hash keys are scanned by each segment.
 * Here's a rough ASCII example to help illustrate:
 *  ___________________________//from  w w  w .j ava  2s. c om
 * |hk:A         |hk:B         |
 * ----------------------------
 * ^segment 1        ^segment 2
 *
 * Because we are scanning in segments across the entire hash key space, it is possible for the same hash key to appear in two different segments.
 * We are also running all of the scan segments in parallel, so we have no control over which segment returns first.
 *
 * In the example, if segment 2 was the first segment to post a result, we would store hk:B as a "boundary" key. That way when
 * segment 1 eventually reaches hk:B in its scan, we know that another segment has already returned this hash key and we can safely skip returning it.
 *
 * By doing this, we avoid returning a RecordIterator for the same hash key twice and we only need to store at most 2 hash keys per segment.
 *
 */
@Override
public List<SingleKeyRecordIterator> buildRecordIterators(ScanContext scanContext) {
    final ScanResult dynamoDbResult = scanContext.getScanResult();
    final int segment = scanContext.getScanRequest().getSegment();
    final List<Map<String, AttributeValue>> items = dynamoDbResult.getItems();
    // If the scan returned no results, we need to shortcut and just throw back an empty result set
    if (items.isEmpty()) {
        return Collections.emptyList();
    }

    List<SingleKeyRecordIterator> recordIterators = Lists.newLinkedList();

    final Iterator<Map<String, AttributeValue>> itemIterator = items.iterator();
    final Map<String, AttributeValue> firstItem = itemIterator.next();
    final StaticBuffer firstKey = new KeyBuilder(firstItem).build(Constants.JANUSGRAPH_HASH_KEY);

    // Computes the full set of boundary keys up to this point. This includes the previous end key for this segment.
    final ImmutableSet<StaticBuffer> boundaryKeys = aggregateBoundaryKeys();

    // The first key in this scan segment might already have been returned by a previous scan segment
    if (!boundaryKeys.contains(firstKey)) {
        recordIterators.add(buildRecordIteratorForHashKey(firstKey));
    }

    StaticBuffer hashKey = firstKey;
    while (itemIterator.hasNext()) {
        final Optional<StaticBuffer> nextKey = findNextHashKey(itemIterator, hashKey);
        if (nextKey.isPresent()) {
            // Found a new hash key. Make a record iterator and look for the next unique hash key
            hashKey = nextKey.get();
            recordIterators.add(buildRecordIteratorForHashKey(hashKey));
        }
    }

    // If we've already seen the final hashKey in a previous scan segment result, we want to avoid returning it again.
    if (!hashKey.equals(firstKey) && boundaryKeys.contains(hashKey)) {
        recordIterators.remove(recordIterators.size() - 1);
    }

    // Update the boundary keys for this segment
    if (scanContext.isFirstResult()) {
        setInitialBoundaryKeys(segment, firstKey, hashKey);
    } else {
        updateLastKey(segment, hashKey);
    }
    return recordIterators;
}

From source file:com.facebook.buck.go.GoTestDescription.java

@Override
public boolean hasFlavors(ImmutableSet<Flavor> flavors) {
    return goBuckConfig.getPlatformFlavorDomain().containsAnyOf(flavors)
            || flavors.contains(TEST_LIBRARY_FLAVOR);
}

From source file:com.facebook.buck.haskell.HaskellBinaryDescription.java

@Override
public boolean hasFlavors(ImmutableSet<Flavor> flavors) {
    if (cxxPlatforms.containsAnyOf(flavors)) {
        return true;
    }/*  w ww .  j a  va  2 s . c  o m*/

    for (Type type : Type.values()) {
        if (flavors.contains(type.getFlavor())) {
            return true;
        }
    }

    return false;
}

From source file:dagger.internal.codegen.MultibindingFactoryCreationExpression.java

protected final ImmutableSet<FrameworkDependency> frameworkDependenciesToImplement() {
    ImmutableSet<Key> alreadyImplementedKeys = componentImplementation
            .superclassContributionsMade(bindingRequest()).stream().map(dependency -> dependency.key())
            .collect(toImmutableSet());//w  ww.j av  a  2s  .  c  om
    return binding.frameworkDependencies().stream()
            .filter(frameworkDependency -> !alreadyImplementedKeys.contains(frameworkDependency.key()))
            .collect(toImmutableSet());
}

From source file:com.bennavetta.aeneas.mesos.slave.MesosSlave.java

public void configureFromEnvironment() {
    final ImmutableSet<String> ignoredKeys = ImmutableSet.of("version", "download_sha1", "download_url");

    System.getenv().forEach((key, value) -> {
        if (key.startsWith("MESOS_")) {
            String argName = key.substring(6).toLowerCase();
            if (!ignoredKeys.contains(argName)) {
                setOption(argName, value);
            }//from  w  w  w  . j  a  v a  2 s . c o  m
        }
    });
}