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:eu.redzoo.reactive.kafka.rest.Environment.java

public ImmutableMap<String, String> getConfigValues(ImmutableSet<String> names) {
    return ImmutableMap.copyOf(Maps.filterKeys(configs, name -> names.contains(name)));
}

From source file:com.outerspacecat.icalendar.RecurrencePredicates.java

/**
 * Returns a predicate for determining whether or not to keep instances of
 * {@link FixedSchedule}. Used to apply BYDAY values to a YEARLY recurrence.
 * <p>/*from   www  . j  a  va2 s . com*/
 * May not work for all chronologies.
 * 
 * @param byDay the values to check supplied fixed schedules against. Must be
 *        non {@code null} and must contain one or more elements.
 * @return a predicate for determining whether or not to keep instances of
 *         {@link FixedSchedule}. Never {@code null}.
 */
static Predicate<ChronoFixedSchedule> yearlyByDayLimiter(final ImmutableSet<DayOfWeekOccurrence> byDay) {
    Preconditions.checkNotNull(byDay, "byDay required");
    Preconditions.checkArgument(!byDay.isEmpty(), "byDay must be non empty");

    return new Predicate<ChronoFixedSchedule>() {
        @Override
        public boolean apply(final ChronoFixedSchedule input) {
            Preconditions.checkNotNull(input, "input required");

            DayOfWeek dayOfWeek = DayOfWeek.of(input.getDateOfStart().get(ChronoField.DAY_OF_WEEK));

            int dayOfYear = input.getDateOfStart().get(ChronoField.DAY_OF_YEAR);

            int numericPrefix = dayOfYear / 7 + (dayOfYear % 7 == 0 ? 0 : 1);

            int daysInYear = (int) (input.getDateOfStart().range(ChronoField.DAY_OF_YEAR).getMaximum());

            int dayOfWeekOccurrencesInYear = (int) (numericPrefix + ((daysInYear - dayOfYear) / 7));

            return byDay.contains(new DayOfWeekOccurrence(Optional.absent(), dayOfWeek))
                    || byDay.contains(new DayOfWeekOccurrence(Optional.fromNullable(numericPrefix), dayOfWeek))
                    || byDay.contains(new DayOfWeekOccurrence(
                            Optional.fromNullable(numericPrefix - dayOfWeekOccurrencesInYear - 1), dayOfWeek));
        }
    };
}

From source file:com.outerspacecat.icalendar.RecurrencePredicates.java

/**
 * Returns a predicate for determining whether or not to keep instances of
 * {@link FixedSchedule}. Used to apply BYDAY values to a MONTHLY recurrence.
 * <p>/*from   w w  w.  j ava  2 s.co m*/
 * May not work for all chronologies.
 * 
 * @param byDay the values to check supplied fixed schedules against. Must be
 *        non {@code null} and must contain one or more elements. The second
 *        element of each tuple must be non {@code null}. If the first element
 *        is non {@code null}, then it must be >= 1 and <= 31.
 * @return a predicate for determining whether or not to keep instances of
 *         {@link FixedSchedule}. Never {@code null}.
 */
static Predicate<ChronoFixedSchedule> monthlyByDayLimiter(final ImmutableSet<DayOfWeekOccurrence> byDay) {
    Preconditions.checkNotNull(byDay, "byDay required");
    Preconditions.checkArgument(!byDay.isEmpty(), "byDay must be non empty");

    return new Predicate<ChronoFixedSchedule>() {
        @Override
        public boolean apply(final ChronoFixedSchedule input) {
            Preconditions.checkNotNull(input, "input required");

            DayOfWeek dayOfWeek = DayOfWeek.of(input.getDateOfStart().get(ChronoField.DAY_OF_WEEK));

            int dayOfMonth = input.getDateOfStart().get(ChronoField.DAY_OF_MONTH);

            int numericPrefix = dayOfMonth / 7 + (dayOfMonth % 7 == 0 ? 0 : 1);

            long daysInMonth = input.getDateOfStart().range(ChronoField.DAY_OF_MONTH).getMaximum();

            int dayOfWeekOccurrencesInMonth = (int) (numericPrefix + ((daysInMonth - dayOfMonth) / 7));

            return byDay.contains(new DayOfWeekOccurrence(Optional.absent(), dayOfWeek))
                    || byDay.contains(new DayOfWeekOccurrence(Optional.fromNullable(numericPrefix), dayOfWeek))
                    || byDay.contains(new DayOfWeekOccurrence(
                            Optional.fromNullable(numericPrefix - dayOfWeekOccurrencesInMonth - 1), dayOfWeek));
        }
    };
}

From source file:com.palantir.giraffe.file.base.attribute.DynamicAttributeAccessor.java

public Map<String, Object> readAttributes(String attributes) throws IOException {
    ImmutableSet<String> attributeSet = ImmutableSet.copyOf(attributes.split(","));
    if (attributeSet.contains("*")) {
        return readAllAttributes();
    } else {//from  w w w .j a v a  2 s  .c om
        return readAttributes(attributeSet);
    }
}

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

private static void filterRDotJava(List<String> rDotJavaLines, OutputStream output,
        ImmutableSet<String> allReferencedResources, Optional<String> keepResourcePattern) throws IOException {
    String packageName = null;//from  w ww  . jav a 2  s  . c  om
    Matcher m;

    Optional<Pattern> keepPattern = keepResourcePattern.map(Pattern::compile);

    for (String line : rDotJavaLines) {
        if (packageName == null) {
            m = R_DOT_JAVA_PACKAGE_NAME_PATTERN.matcher(line);
            if (m.find()) {
                packageName = m.group(1);
            } else {
                continue;
            }
        }
        m = R_DOT_JAVA_LINE_PATTERN.matcher(line);
        // We match on the package name + resource name.
        // This can cause us to keep (for example) R.layout.foo when only R.string.foo
        // is referenced.  That is a very rare case, though, and not worth the complexity to fix.
        if (m.find()) {
            final String resource = m.group(1);
            boolean shouldWriteLine = allReferencedResources.contains(packageName + "." + resource)
                    || (keepPattern.isPresent() && keepPattern.get().matcher(resource).find());
            if (!shouldWriteLine) {
                continue;
            }
        }
        output.write(line.getBytes(Charsets.UTF_8));
        output.write('\n');
    }
}

From source file:com.jeffreybosboom.lyne.rules.DesiredEdgesRule.java

@Override
public Puzzle apply(Puzzle puzzle) {
    for (Iterator<Node> i = puzzle.nodes().iterator(); i.hasNext();) {
        Node a = i.next();//from   w ww.j ava2 s.  c  om
        List<Node> neighbors = puzzle.neighbors(a).collect(Collectors.toList());
        int knownColored = 0, knownNone = 0;
        for (Node n : neighbors) {
            ImmutableSet<Node.Kind> possibilities = puzzle.possibilities(a, n);
            if (!possibilities.contains(Node.Kind.NONE))
                ++knownColored;
            if (possibilities.stream().noneMatch(Node.Kind::isColored))
                ++knownNone;
        }
        int unknown = neighbors.size() - knownColored - knownNone;

        if (knownColored > a.desiredEdges())
            throw new ContradictionException();
        if (knownColored + unknown < a.desiredEdges())
            throw new ContradictionException();
        if (unknown == 0)
            continue;

        //All unknown possibilities are NONE.
        if (knownColored == a.desiredEdges())
            for (Node n : neighbors) {
                ImmutableSet<Node.Kind> possibilities = puzzle.possibilities(a, n);
                if (possibilities.contains(Node.Kind.NONE)
                        && possibilities.stream().anyMatch(Node.Kind::isColored))
                    puzzle = puzzle.set(a, n, Node.Kind.NONE);
            }
        //All unknown possibilities are not NONE (but we don't know which color).
        else if (knownColored + unknown == a.desiredEdges())
            for (Node n : neighbors) {
                ImmutableSet<Node.Kind> possibilities = puzzle.possibilities(a, n);
                if (possibilities.contains(Node.Kind.NONE)
                        && possibilities.stream().anyMatch(Node.Kind::isColored))
                    puzzle = puzzle.remove(a, n, Node.Kind.NONE);
            }
    }
    return puzzle;
}

From source file:com.facebook.buck.cxx.CxxLibraryFlavored.java

@Override
public boolean hasFlavors(ImmutableSet<Flavor> flavors) {
    return getCxxPlatformsProvider().getUnresolvedCxxPlatforms().containsAnyOf(flavors)
            || flavors.contains(CxxCompilationDatabase.COMPILATION_DATABASE)
            || flavors.contains(CxxCompilationDatabase.UBER_COMPILATION_DATABASE)
            || CxxInferEnhancer.INFER_FLAVOR_DOMAIN.containsAnyOf(flavors)
            || flavors.contains(CxxInferEnhancer.InferFlavors.INFER_ANALYZE.getFlavor())
            || flavors.contains(CxxInferEnhancer.InferFlavors.INFER_CAPTURE_ALL.getFlavor())
            || flavors.contains(CxxDescriptionEnhancer.EXPORTED_HEADER_SYMLINK_TREE_FLAVOR)
            || LinkerMapMode.FLAVOR_DOMAIN.containsAnyOf(flavors)
            || !Sets.intersection(cxxBuckConfig.getDeclaredPlatforms(), flavors).isEmpty();
}

From source file:eu.trentorise.opendata.semtext.jackson.MetadataDeserializer.java

@Override
public Map<String, Object> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {

    ImmutableMap.Builder<String, Object> retb = ImmutableMap.builder();

    while (jp.nextToken() != JsonToken.END_OBJECT) {

        String namespace = jp.getCurrentName();
        // current token is "name",
        // move to next, which is "name"'s value
        jp.nextToken();/*from  w w  w  .j  av  a 2s  .  co  m*/

        ImmutableSet<String> namespaces = SemTextModule.getMetadataNamespaces(hasMetadataClass);
        if (namespaces.contains(namespace)) {
            TypeReference typeRef = SemTextModule.getMetadataTypeReference(hasMetadataClass, namespace);

            Object metadata;

            try {
                metadata = jp.readValueAs(typeRef);
            } catch (Exception ex) {
                throw new SemTextMetadataException("Jackson error while deserializing metadata - ",
                        hasMetadataClass, namespace, typeRef, ex);
            }

            if (metadata == null) {
                throw new SemTextMetadataException("Found null metadata while deserializing!", hasMetadataClass,
                        namespace, typeRef);
            }

            retb.put(namespace, metadata);
        } else {
            throw new SemTextMetadataException(
                    "Found metadata under not registered namespace while deserializing!", hasMetadataClass,
                    namespace, null);
        }
    }

    return retb.build();
}

From source file:org.onosproject.yang.compiler.plugin.buck.YangLibraryDescription.java

@Override
public boolean hasFlavors(ImmutableSet<Flavor> flavors) {
    return flavors.isEmpty() || flavors.contains(SOURCES);
}

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

/**
 * @param output  Output of "ls" command.
 * @param filePattern  A {@link Pattern} that is used to check if a file is valid, and if it
 *     matches, {@code filePattern.group(1)} should return the hash in the file name.
 * @param requiredHashes  Hashes of dex files required for this apk.
 * @param foundHashes  Builder to receive hashes that we need and were found.
 * @param toDelete  Builder to receive files that we need to delete.
 *///from  ww w . j  ava2s .  c o m
@VisibleForTesting
static void processLsOutput(String output, Pattern filePattern, ImmutableSet<String> requiredHashes,
        ImmutableSet.Builder<String> foundHashes, ImmutableSet.Builder<String> toDelete) {
    for (String line : Splitter.on(LINE_ENDING).omitEmptyStrings().split(output)) {
        if (line.equals("lock")) {
            continue;
        }

        Matcher m = filePattern.matcher(line);
        if (m.matches()) {
            if (requiredHashes.contains(m.group(1))) {
                foundHashes.add(m.group(1));
            } else {
                toDelete.add(line);
            }
        } else {
            toDelete.add(line);
        }
    }
}