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.facebook.buck.apple.simulator.AppleSimulatorController.java

public boolean canStartSimulator(String simulatorUdid) throws IOException, InterruptedException {
    ImmutableSet<String> bootedSimulatorDeviceUdids = getBootedSimulatorDeviceUdids(processExecutor);
    if (bootedSimulatorDeviceUdids.size() == 0) {
        return true;
    } else if (bootedSimulatorDeviceUdids.size() > 1) {
        LOG.debug("Multiple simulators booted (%s), cannot start simulator.", bootedSimulatorDeviceUdids);
        return false;
    } else if (!bootedSimulatorDeviceUdids.contains(simulatorUdid)) {
        LOG.debug("Booted simulator (%s) does not match desired (%s), cannot start simulator.",
                Iterables.getOnlyElement(bootedSimulatorDeviceUdids), simulatorUdid);
        return false;
    } else {/*from   ww  w.ja v a2s. co m*/
        return true;
    }
}

From source file:com.facebook.buck.rules.macros.MacroFinder.java

public ImmutableList<MacroMatchResult> findAll(ImmutableSet<String> macros, String blob) throws MacroException {

    ImmutableList.Builder<MacroMatchResult> results = ImmutableList.builder();

    // Iterate over all macros found in the string, and return a list of MacroMatchResults.
    Matcher matcher = MACRO_PATTERN.matcher(blob);
    while (matcher.find()) {
        if (matcher.start() > 0 && blob.charAt(matcher.start() - 1) == '\\') {
            continue;
        }//from   w  w w . j a v  a2s  .  c om
        String name = matcher.group(1);
        if (!macros.contains(name)) {
            throw new MacroException(String.format("no such macro \"%s\"", name));
        }
        String input = Optional.fromNullable(matcher.group(2)).or("");
        MatchResult matchResult = matcher.toMatchResult();
        results.add(MacroMatchResult.builder().setMacroType(name).setMacroInput(input)
                .setStartIndex(matchResult.start()).setEndIndex(matchResult.end()).build());
    }

    return results.build();
}

From source file:org.apache.abdera2.activities.extra.Extra.java

public static EntryTransformer<String, Object, Object> caseTransform(final String... lowerFields) {
    final ImmutableSet<String> fields = ImmutableSet.copyOf(lowerFields);
    return new EntryTransformer<String, Object, Object>() {
        public Object transformEntry(String key, Object value) {
            return fields.contains(key) ? value.toString().toLowerCase() : value;
        }/*from   w w  w . jav  a  2s. c  o m*/
    };
}

From source file:com.facebook.buck.model.MacroFinder.java

public Optional<MacroMatchResult> match(ImmutableSet<String> macros, String blob) throws MacroException {

    MacroMatchResult result = new MacroFinderAutomaton(blob).next();
    if (result != null && !result.isEscaped() && result.getStartIndex() == 0
            && result.getEndIndex() == blob.length()) {
        if (!macros.contains(result.getMacroType())) {
            throw new MacroException(
                    String.format("expanding %s: no such macro \"%s\"", blob, result.getMacroType()));
        }//from  w ww . ja v a 2  s  . c  o  m
        return Optional.of(result);
    }
    return Optional.empty();
}

From source file:com.google.googlejavaformat.java.ImportOrderer.java

/**
 * Returns the index of the first place where one of the given identifiers occurs, or {@code
 * Optional.empty()} if there is none.//from w w w  .  j a  v  a  2 s  .  c  o m
 *
 * @param start the index to start looking at
 * @param identifiers the identifiers to look for
 */
private Optional<Integer> findIdentifier(int start, ImmutableSet<String> identifiers) {
    for (int i = start; i < toks.size(); i++) {
        if (isIdentifierToken(i)) {
            String id = tokenAt(i);
            if (identifiers.contains(id)) {
                return Optional.of(i);
            }
        }
    }
    return Optional.empty();
}

From source file:com.google.devtools.build.lib.rules.android.ResourceFilter.java

ImmutableList<Artifact> filter(RuleContext ruleContext, ImmutableList<Artifact> artifacts) {
    if (!isPrefiltering()) {
        return artifacts;
    }// w  w w  . j a  v  a2  s.  c o m

    /*
     * Build an ImmutableSet rather than an ImmutableList to remove duplicate Artifacts in the case
     * where one Artifact is the best option for multiple densities.
     */
    ImmutableSet.Builder<Artifact> builder = ImmutableSet.builder();

    List<BestArtifactsForDensity> bestArtifactsForAllDensities = new ArrayList<>();
    for (Density density : getDensities(ruleContext)) {
        bestArtifactsForAllDensities.add(new BestArtifactsForDensity(ruleContext, density));
    }

    ImmutableList<FolderConfiguration> folderConfigs = getConfigurationFilters(ruleContext);

    for (Artifact artifact : artifacts) {
        if (!matchesConfigurationFilters(folderConfigs, getConfigForArtifact(ruleContext, artifact))) {
            continue;
        }

        if (!shouldFilterByDensity(artifact)) {
            builder.add(artifact);
            continue;
        }

        for (BestArtifactsForDensity bestArtifactsForDensity : bestArtifactsForAllDensities) {
            bestArtifactsForDensity.maybeAddArtifact(artifact);
        }
    }

    for (BestArtifactsForDensity bestArtifactsForDensity : bestArtifactsForAllDensities) {
        builder.addAll(bestArtifactsForDensity.get());
    }

    ImmutableSet<Artifact> keptArtifacts = builder.build();
    for (Artifact artifact : artifacts) {
        if (keptArtifacts.contains(artifact)) {
            continue;
        }

        String parentDir = artifact.getPath().getParentDirectory().getBaseName();
        filteredResources.add(parentDir + "/" + artifact.getFilename());
    }

    return keptArtifacts.asList();
}

From source file:com.github.jsdossier.ModulePrefixProvider.java

@Override
public Path get() {
    ImmutableSet<Path> modules = getModulePaths();

    Path path;//  www. j av a  2  s  .co  m
    if (userSuppliedPrefix.isPresent()) {
        path = userSuppliedPrefix.get();
        checkArgument(isDirectory(path), "Module prefix must be a directory: %s", path);
        for (Path module : modules) {
            checkArgument(module.startsWith(path), "Module prefix <%s> is not an ancestor of module %s", path,
                    module);
        }
    } else {
        path = getCommonPrefix(inputFs.getPath("").toAbsolutePath(), modules);
        if (modules.contains(path) && path.getParent() != null) {
            path = path.getParent();
        }
    }

    // Always display at least one parent directory, if possible.
    for (Path module : modules) {
        if (path.equals(module.getParent())) {
            return firstNonNull(path.getParent(), path);
        }
    }

    return path;
}

From source file:org.projectbuendia.client.user.UserManager.java

/**
 * Called when users are retrieved from the server, in order to send events and update user
 * state as necessary.//from   ww  w.ja v  a 2  s.  co m
 */
private void onUsersSynced(Set<User> syncedUsers) throws UserSyncException {
    if (syncedUsers == null || syncedUsers.isEmpty()) {
        throw new UserSyncException("Set of users retrieved from server is null or empty.");
    }

    ImmutableSet<User> addedUsers = ImmutableSet.copyOf(Sets.difference(syncedUsers, mKnownUsers));
    ImmutableSet<User> deletedUsers = ImmutableSet.copyOf(Sets.difference(mKnownUsers, syncedUsers));

    mKnownUsers.clear();
    mKnownUsers.addAll(syncedUsers);
    mEventBus.post(new KnownUsersSyncedEvent(addedUsers, deletedUsers));

    if (mActiveUser != null && deletedUsers.contains(mActiveUser)) {
        // TODO: Potentially clear mActiveUser here.
        mEventBus.post(new ActiveUserUnsetEvent(mActiveUser, ActiveUserUnsetEvent.REASON_USER_DELETED));
    }

    // If at least one user was added or deleted, the set of known users has changed.
    if (!addedUsers.isEmpty() || !deletedUsers.isEmpty()) {
        setDirty(true);
    }
}

From source file:de.metas.ui.web.process.descriptor.WebuiRelatedProcessDescriptor.java

@lombok.Builder
private WebuiRelatedProcessDescriptor(final ProcessId processId, final String internalName,
        final ITranslatableString processCaption, final ITranslatableString processDescription,
        @NonNull @Singular final ImmutableSet<DisplayPlace> displayPlaces, final boolean defaultQuickAction,
        @NonNull final Supplier<ProcessPreconditionsResolution> preconditionsResolutionSupplier,
        final String debugProcessClassname) {
    this.processId = processId;
    this.internalName = internalName;
    this.processCaption = processCaption;
    this.processDescription = processDescription;
    this.displayPlaces = displayPlaces;
    this.defaultQuickAction = defaultQuickAction && displayPlaces.contains(DisplayPlace.ViewQuickActions);

    // Memorize the resolution supplier to make sure it's not invoked more than once because it might be an expensive operation.
    // Also we assume this is a short living instance which was created right before checking
    this.preconditionsResolutionSupplier = ExtendedMemorizingSupplier
            .of(() -> ValueAndDuration.fromSupplier(preconditionsResolutionSupplier));

    this.debugProcessClassname = debugProcessClassname;
}

From source file:com.facebook.buck.cli.AuditInputCommand.java

@Override
int runCommandWithOptionsInternal(AuditCommandOptions options) throws IOException {
    // Create a PartialGraph that is composed of the transitive closure of all of the dependent
    // BuildRules for the specified BuildTargets.
    final ImmutableSet<String> fullyQualifiedBuildTargets = ImmutableSet
            .copyOf(options.getArgumentsFormattedAsBuildTargets());

    if (fullyQualifiedBuildTargets.isEmpty()) {
        console.printBuildFailure("Please specify at least one build target.");
        return 1;
    }//w  w w . ja  va2  s. c o  m

    RawRulePredicate predicate = new RawRulePredicate() {
        @Override
        public boolean isMatch(Map<String, Object> rawParseData, BuildRuleType buildRuleType,
                BuildTarget buildTarget) {
            return fullyQualifiedBuildTargets.contains(buildTarget.getFullyQualifiedName());
        }
    };
    PartialGraph partialGraph;
    try {
        partialGraph = PartialGraph.createPartialGraph(predicate, getProjectFilesystem(),
                options.getDefaultIncludes(), getParser(), getBuckEventBus());
    } catch (BuildTargetException | BuildFileParseException e) {
        console.printBuildFailureWithoutStacktrace(e);
        return 1;
    }

    if (options.shouldGenerateJsonOutput()) {
        return printJsonInputs(partialGraph);
    }
    return printInputs(partialGraph);
}