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:org.sosy_lab.cpachecker.util.predicates.interpolation.CexTraceAnalysisDirection.java

private static void createLoopDrivenStateOrdering(final List<AbstractState> pAbstractionStates,
        final Multimap<Integer, AbstractState> loopLevelsToStatesMap, Deque<CFANode> actLevelStack,
        LoopStructure loopStructure) {/*from   ww w  . j a v  a 2s .c  om*/
    ImmutableSet<CFANode> loopHeads = loopStructure.getAllLoopHeads();

    // in the nodeLoopLevel map there has to be for every seen ARGState one
    // key-value pair therefore we can use this as our index
    int actARGState = loopLevelsToStatesMap.size();

    AbstractState actState = null;
    CFANode actCFANode = null;

    boolean isCFANodeALoopHead = false;

    // move on as long as there occurs no loop-head in the ARG path
    while (!isCFANodeALoopHead && actLevelStack.isEmpty() && actARGState < pAbstractionStates.size()) {

        actState = pAbstractionStates.get(actARGState);
        actCFANode = AbstractStates.EXTRACT_LOCATION.apply(actState);

        loopLevelsToStatesMap.put(0, actState);

        isCFANodeALoopHead = loopHeads.contains(actCFANode);

        actARGState++;
    }

    // when not finished with computing the node levels
    if (actARGState != pAbstractionStates.size()) {
        actLevelStack.push(actCFANode);
        createLoopDrivenStateOrdering0(pAbstractionStates, loopLevelsToStatesMap, actLevelStack, loopStructure);
    }
}

From source file:org.apache.james.jmap.methods.GetMessagesMethod.java

private PropertyFilter buildHeadersPropertyFilter(ImmutableSet<HeaderProperty> headerProperties) {
    return new FieldNamePropertyFilter(
            (fieldName) -> headerProperties.contains(HeaderProperty.fromFieldName(fieldName)));
}

From source file:com.facebook.buck.android.AndroidPrebuiltAarDescription.java

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params,
        BuildRuleResolver buildRuleResolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);

    ImmutableSet<Flavor> flavors = params.getBuildTarget().getFlavors();
    if (flavors.contains(AAR_UNZIP_FLAVOR)) {
        Preconditions.checkState(flavors.size() == 1);
        BuildRuleParams unzipAarParams = params.copyWithDeps(Suppliers.ofInstance(ImmutableSortedSet.of()),
                Suppliers.ofInstance(ImmutableSortedSet.copyOf(ruleFinder.filterBuildRuleInputs(args.aar))));
        return new UnzipAar(unzipAarParams, args.aar);
    }/*from  ww  w  . j a  v  a 2  s  . co m*/

    BuildRule unzipAarRule = buildRuleResolver
            .requireRule(params.getBuildTarget().withFlavors(AAR_UNZIP_FLAVOR));
    Preconditions.checkState(unzipAarRule instanceof UnzipAar,
            "aar_unzip flavor created rule of unexpected type %s for target %s", unzipAarRule.getClass(),
            params.getBuildTarget());
    UnzipAar unzipAar = (UnzipAar) unzipAarRule;

    if (flavors.contains(CalculateAbi.FLAVOR)) {
        return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params,
                new BuildTargetSourcePath(unzipAar.getBuildTarget(), unzipAar.getPathToClassesJar()));
    }

    Iterable<PrebuiltJar> javaDeps = Iterables.concat(
            Iterables.filter(buildRuleResolver.getAllRules(args.deps), PrebuiltJar.class),
            Iterables.transform(
                    Iterables.filter(buildRuleResolver.getAllRules(args.deps), AndroidPrebuiltAar.class),
                    AndroidPrebuiltAar::getPrebuiltJar));

    BuildTarget abiJarTarget = params.getBuildTarget().withAppendedFlavors(CalculateAbi.FLAVOR);

    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);

    PrebuiltJar prebuiltJar = buildRuleResolver.addToIndex(createPrebuiltJar(unzipAar, params, pathResolver,
            abiJarTarget, ImmutableSortedSet.copyOf(javaDeps)));

    BuildRuleParams androidLibraryParams = params.copyWithDeps(
            /* declaredDeps */ Suppliers.ofInstance(ImmutableSortedSet.of(prebuiltJar)),
            /* extraDeps */ Suppliers.ofInstance(ImmutableSortedSet.of(unzipAar)));
    return new AndroidPrebuiltAar(androidLibraryParams, /* resolver */ pathResolver, ruleFinder,
            /* proguardConfig */ new BuildTargetSourcePath(unzipAar.getBuildTarget(),
                    unzipAar.getProguardConfig()),
            /* nativeLibsDirectory */ new BuildTargetSourcePath(unzipAar.getBuildTarget(),
                    unzipAar.getNativeLibsDirectory()),
            /* prebuiltJar */ prebuiltJar, /* unzipRule */ unzipAar, /* javacOptions */ javacOptions,
            new JavacToJarStepFactory(javacOptions, new BootClasspathAppender()), /* exportedDeps */ javaDeps,
            abiJarTarget, JavaLibraryRules.getAbiInputs(buildRuleResolver, androidLibraryParams.getDeps()));
}

From source file:eu.numberfour.n4js.ui.editor.syntaxcoloring.TokenTypeRewriter.java

private static void rewriteIdentifiers(N4JSGrammarAccess ga,
        ImmutableMap.Builder<AbstractElement, Integer> builder) {
    ImmutableSet<AbstractRule> identifierRules = ImmutableSet.of(ga.getBindingIdentifierRule(),
            ga.getIdentifierNameRule(), ga.getSymbolLiteralComputedNameRule(), ga.getIDENTIFIERRule());
    for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
        for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
            if (obj instanceof Assignment) {
                Assignment assignment = (Assignment) obj;
                AbstractElement terminal = assignment.getTerminal();
                int type = InternalN4JSParser.RULE_IDENTIFIER;
                if (terminal instanceof CrossReference) {
                    terminal = ((CrossReference) terminal).getTerminal();
                    type = IDENTIFIER_REF_TOKEN;
                }//from w  w  w  . java 2 s  . com
                if (terminal instanceof RuleCall) {
                    AbstractRule calledRule = ((RuleCall) terminal).getRule();
                    if (identifierRules.contains(calledRule)) {
                        builder.put(assignment, type);
                    }
                }
            }
        }
    }
}

From source file:org.elasticsearch.test.ElasticsearchAllocationTestCase.java

public static AllocationDeciders randomAllocationDeciders(Settings settings,
        NodeSettingsService nodeSettingsService, Random random) {
    final ImmutableSet<Class<? extends AllocationDecider>> defaultAllocationDeciders = AllocationDecidersModule.DEFAULT_ALLOCATION_DECIDERS;
    final List<AllocationDecider> list = new ArrayList<>();
    for (Class<? extends AllocationDecider> deciderClass : defaultAllocationDeciders) {
        try {/*ww  w .j a v  a 2  s  .  com*/
            try {
                Constructor<? extends AllocationDecider> constructor = deciderClass
                        .getConstructor(Settings.class, NodeSettingsService.class);
                list.add(constructor.newInstance(settings, nodeSettingsService));
            } catch (NoSuchMethodException e) {
                Constructor<? extends AllocationDecider> constructor = null;
                constructor = deciderClass.getConstructor(Settings.class);
                list.add(constructor.newInstance(settings));
            }
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
    assertThat(list.size(), equalTo(defaultAllocationDeciders.size()));
    for (AllocationDecider d : list) {
        assertThat(defaultAllocationDeciders.contains(d.getClass()), is(true));
    }
    Collections.shuffle(list, random);
    return new AllocationDeciders(settings, list.toArray(new AllocationDecider[0]));

}

From source file:org.geoserver.gwc.layer.CatalogStyleChangeListener.java

/**
 * Handles the rename of a style, truncating the cache for any layer that has it as a cached
 * alternate style; modifications to the actual style are handled at
 * {@link #handlePostModifyEvent(CatalogPostModifyEvent)}.
 * <p>//ww w .j  a  v  a  2  s .com
 * When a style is renamed, the {@link LayerInfo} and {@link LayerGroupInfo} that refer to it
 * are not modified, since they refer to the {@link StyleInfo} by id, so they don't really care
 * about the name of the style. For the tiled layer its different, because styles are referred
 * to by {@link GeoServerTileLayerInfoImpl#cachedStyles() name} in order to create the
 * appropriate "STYLES" {@link ParameterFilter parameter filter}. This method will look for any
 * tile layer backed by a {@link LayerInfo} that has a cache for the renamed style as an
 * alternate style (i.e. through a parameter filter) and will truncate the cache for that
 * layer/style. This is so because there's no way in GWC to just rename a style (that would
 * imply getting to the parameter filters that refer to that style in the meta-store and change
 * it's value preserving the parametersId)
 * <p>
 * 
 * @see org.geoserver.catalog.event.CatalogListener#handleModifyEvent(org.geoserver.catalog.event.CatalogModifyEvent)
 */
public void handleModifyEvent(CatalogModifyEvent event) throws CatalogException {
    CatalogInfo source = event.getSource();
    if (!(source instanceof StyleInfo)) {
        return;
    }
    final List<String> propertyNames = event.getPropertyNames();
    if (!propertyNames.contains("name")) {
        return;
    }
    final int index = propertyNames.indexOf("name");
    final String oldStyleName = (String) event.getOldValues().get(index);
    final String newStyleName = (String) event.getNewValues().get(index);
    if (oldStyleName.equals(newStyleName)) {
        return;
    }
    List<GeoServerTileLayer> affectedLayers;
    affectedLayers = mediator.getTileLayersForStyle(oldStyleName);

    for (GeoServerTileLayer tl : affectedLayers) {
        LayerInfo layerInfo = tl.getLayerInfo();
        if (layerInfo == null) {
            // no extra styles for layer groups
            continue;
        }

        GeoServerTileLayerInfo info = tl.getInfo();
        ImmutableSet<String> styleNames = info.cachedStyles();
        if (styleNames.contains(oldStyleName)) {
            tl.resetParameterFilters();
            // pity, we don't have a way to just rename a style in GWC
            mediator.truncateByLayerAndStyle(tl.getName(), oldStyleName);
            Set<String> newStyles = new HashSet<String>(styleNames);
            newStyles.remove(oldStyleName);
            newStyles.add(newStyleName);
            String defaultStyle = layerInfo.getDefaultStyle() == null ? null
                    : layerInfo.getDefaultStyle().getName();
            TileLayerInfoUtil.setCachedStyles(info, defaultStyle, newStyles);

            mediator.save(tl);
        }
    }
}

From source file:com.jeffreybosboom.lyne.Puzzle.java

/**
 * Returns a Puzzle with the given possibility removed from the edge between
 * the given nodes.  If the possibility is already not possible, this Puzzle
 * is returned.  If this removes the last possibility for this edge,
 * a ContradictionException is thrown.//ww w .  j a  v a  2s. c  o m
 */
public Puzzle remove(Node a, Node b, Node.Kind possibility) {
    Pair<Node, Node> p = Pair.sorted(a, b);
    ImmutableSet<Node.Kind> possibilities = possibilities(a, b);
    if (!possibilities.contains(possibility))
        return this;
    if (possibilities.size() == 1)
        throw new ContradictionException();

    ImmutableSet<Node.Kind> newSet = ImmutableSet
            .copyOf(possibilities.stream().filter(x -> x != possibility).iterator());
    return withEdgeSet(p, newSet);
}

From source file:com.google.devtools.build.android.DataSource.java

public DataSource overwrite(DataSource... sources) {
    ImmutableSet<DataSource> overrides = ImmutableSet.<DataSource>builder().addAll(this.overrides).add(sources)
            .build();/*  w  w w. jav a 2s  .  c  om*/
    Preconditions.checkArgument(!overrides.contains(this));
    return new DataSource(path, overrides);
}

From source file:google.registry.flows.ExtensionManager.java

private void checkForRestrictedExtensions(ImmutableSet<Class<? extends CommandExtension>> suppliedExtensions)
        throws OnlyToolCanPassMetadataException {
    if (suppliedExtensions.contains(MetadataExtension.class)
            && !eppRequestSource.equals(EppRequestSource.TOOL)) {
        throw new OnlyToolCanPassMetadataException();
    }//from   w w  w.  j a v a2  s .  c  om
}

From source file:se.sics.caracaldb.operations.MultiOpRequest.java

@Override
public boolean affectedBy(CaracalOp op) {
    ImmutableSet.Builder<Key> readKeysB = ImmutableSet.builder();
    for (MultiOp.Condition c : conditions) {
        readKeysB.add(c.on());//  w  w  w .  jav a 2s  .c om
    }
    ImmutableSet<Key> readKeys = readKeysB.build();
    if (op instanceof PutRequest) {
        PutRequest put = (PutRequest) op;
        return readKeys.contains(put.key);
    }
    if (op instanceof RangeQuery.Request) {
        RangeQuery.Request rqr = (RangeQuery.Request) op;
        if (!(rqr.action instanceof ActionFactory.Noop)) {
            for (Key k : readKeys) {
                if (rqr.subRange.contains(k)) {
                    return true;
                }
            }
            return false;
        }
    }
    if (op instanceof MultiOpRequest) {
        MultiOpRequest mor = (MultiOpRequest) op;
        for (Key k : readKeys) {
            if (mor.writesTo(k)) {
                return true;
            }
        }
        return false;
    }
    return false;
}