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.jimfs.Options.java

/**
 * Returns an immutable set of open options for opening a new output stream.
 *//*w  w w  .j a v  a  2 s.  c om*/
public static ImmutableSet<OpenOption> getOptionsForOutputStream(OpenOption... options) {
    if (options.length == 0) {
        return DEFAULT_WRITE;
    }

    ImmutableSet<OpenOption> result = ImmutableSet.copyOf(options);
    if (result.contains(READ)) {
        throw new UnsupportedOperationException("'READ' not allowed");
    }
    return result;
}

From source file:com.facebook.buck.util.BuckArgsMethods.java

/**
 * Drops options from the args array./*from   ww w  .j  a  va2s. co  m*/
 *
 * @param args args array.
 * @param optionsToSkip if args contains an element from this array skip the element and the
 *     element immediately after it.
 * @return filtered args array
 */
public static ImmutableList<String> filterArgs(List<String> args, ImmutableSet<String> optionsToSkip) {
    ImmutableList.Builder<String> result = ImmutableList.builder();
    for (int i = 0; i < args.size(); ++i) {
        if (optionsToSkip.contains(args.get(i))) {
            i += 1;
        } else {
            result.add(args.get(i));
        }
    }
    return result.build();
}

From source file:google.registry.model.registry.Registries.java

/**
 * Returns TLD which the domain name or hostname falls under, no matter how many levels of
 * sublabels there are.//from  ww w .j av  a  2s .c  o  m
 *
 * <p><b>Note:</b> This routine will only work on names under TLDs for which this registry is
 * authoritative. To extract TLDs from domains (not hosts) that other registries control, use
 * {@link google.registry.util.DomainNameUtils#getTldFromDomainName(String)
 * DomainNameUtils#getTldFromDomainName}.
 *
 * @param domainName domain name or host name (but not TLD) under an authoritative TLD
 * @return TLD or absent if {@code domainName} has no labels under an authoritative TLD
 */
public static Optional<InternetDomainName> findTldForName(InternetDomainName domainName) {
    ImmutableSet<String> tlds = getTlds();
    while (domainName.hasParent()) {
        domainName = domainName.parent();
        if (tlds.contains(domainName.toString())) {
            return Optional.of(domainName);
        }
    }
    return Optional.absent();
}

From source file:com.google.template.soy.error.SoyErrors.java

/**
 * Same as {@link #getDidYouMeanMessage(Iterable, String)} but with some additional heuristics for
 * proto fields.//from   www  . java2s  . com
 */
public static String getDidYouMeanMessageForProtoFields(ImmutableSet<String> fields, String fieldName) {
    // TODO(lukes): when we have map/case enum support add more cases here.
    if (fields.contains(fieldName + "List")) {
        return String.format(" Did you mean '%sList'?", fieldName);
    } else {
        return getDidYouMeanMessage(fields, fieldName);
    }
}

From source file:at.ac.univie.isc.asio.tool.Beans.java

/**
 * Create a copy of given input properties.
 *
 * @param input source properties//w w w .  j  ava  2 s  . c  om
 * @param exclude keys of properties that should be omitted
 * @return map of copied properties
 */
public static Map<String, String> copyToMap(final Properties input, final String... exclude) {
    final ImmutableSet<String> excluded = ImmutableSet.copyOf(exclude);
    final ImmutableMap.Builder<String, String> clone = ImmutableMap.builder();
    for (String key : input.stringPropertyNames()) {
        if (!excluded.contains(key)) {
            clone.put(key, input.getProperty(key));
        }
    }
    return clone.build();
}

From source file:google.registry.mapreduce.inputs.EppResourceBaseReader.java

static <R extends EppResource> ImmutableSet<String> varargsToKinds(
        ImmutableSet<Class<? extends R>> resourceClasses) {
    // Ignore EppResource when finding kinds, since it doesn't have one and doesn't imply filtering.
    return resourceClasses.contains(EppResource.class) ? ImmutableSet.<String>of()
            : FluentIterable.from(resourceClasses).transform(CLASS_TO_KIND_FUNCTION).toSet();
}

From source file:de.se_rwth.langeditor.util.antlr.Formatting.java

public static void insertLineBreaks(TokenStreamRewriter rewriter, ImmutableSet<String> linebreakerLiterals,
        int whiteSpaceTokenType) {
    TokenStream tokens = rewriter.getTokenStream();
    for (int i = 0; i < tokens.size(); i++) {
        Token token = tokens.get(i);//from   www  .  j  ava 2  s.  c o  m
        if (linebreakerLiterals.contains(token.getText())) {
            breakLine(token, rewriter, whiteSpaceTokenType);
        }
    }
}

From source file:de.metas.ui.web.handlingunits.HUEditorRowFilters.java

public static Predicate<HUEditorRow> toPredicate(@NonNull final HUEditorRowFilter filter) {
    Predicate<HUEditorRow> predicate = Predicates.alwaysTrue();
    if (filter == HUEditorRowFilter.ALL) {
        return predicate;
    }/*from   w ww. ja v a2 s . c  o m*/

    // Filter by row type
    final Select rowType = filter.getSelect();
    if (rowType == Select.ALL) {
        // nothing
    } else if (rowType == Select.ONLY_TOPLEVEL) {
        predicate = predicate.and(HUEditorRow::isTopLevel);
    } else if (rowType == Select.LU) {
        predicate = predicate.and(HUEditorRow::isLU);
    } else if (rowType == Select.TU) {
        predicate = predicate.and(HUEditorRow::isTU);
    } else if (rowType == Select.CU) {
        predicate = predicate.and(HUEditorRow::isCU);
    } else {
        throw new AdempiereException("Unknown: " + rowType);
    }

    // Filter by string filter
    final String stringFilter = filter.getUserInputFilter();
    if (!Check.isEmpty(stringFilter, true)) {
        predicate = predicate.and(row -> row.matchesStringFilter(stringFilter));
    }

    // Exclude M_HU_IDs
    final ImmutableSet<HuId> excludeHUIds = filter.getExcludeHUIds();
    if (!excludeHUIds.isEmpty()) {
        predicate = predicate.and(row -> !excludeHUIds.contains(row.getHuId()));
    }

    // Include HUStatuses
    final ImmutableSet<String> onlyHUStatuses = filter.getOnlyHUStatuses();
    if (!onlyHUStatuses.isEmpty()) {
        predicate = predicate.and(row -> onlyHUStatuses.contains(row.getHUStatus()));
    }

    // Exclude HUStatuses
    final ImmutableSet<String> excludeHUStatuses = filter.getExcludeHUStatuses();
    if (!excludeHUStatuses.isEmpty()) {
        predicate = predicate.and(row -> !excludeHUStatuses.contains(row.getHUStatus()));
    }

    return predicate;
}

From source file:de.se_rwth.langeditor.util.antlr.ParseTrees.java

public static ImmutableSet<ParseTree> filterContexts(ParseTree parseTree,
        ImmutableSet<Class<? extends ParseTree>> types) {
    Set<ParserRuleContext> matchingRules = Trees.getDescendants(parseTree).stream()
            .filter(descendant -> types.contains(descendant.getClass())).map(ParserRuleContext.class::cast)
            .collect(Collectors.toSet());
    return ImmutableSet.copyOf(matchingRules);
}

From source file:com.google.javascript.jscomp.newtypes.EnumType.java

static boolean areSubtypes(JSType t1, JSType t2) {
    ImmutableSet<EnumType> s1 = t1.getEnums();
    if (s1 == null) {
        return true;
    }//from w  ww.ja  v  a 2s . c  om
    ImmutableSet<EnumType> s2 = t2.getEnums();
    for (EnumType e : s1) {
        if (s2 != null && s2.contains(e)) {
            continue;
        }
        if (!e.declaredType.isSubtypeOf(t2)) {
            return false;
        }
    }
    return true;
}