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

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

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this set contains no elements.

Usage

From source file:com.facebook.presto.operator.aggregation.AggregationCompiler.java

private static Set<Class<?>> getStateClasses(Class<?> clazz) {
    ImmutableSet.Builder<Class<?>> builder = ImmutableSet.builder();
    for (Method inputFunction : findPublicStaticMethodsWithAnnotation(clazz, InputFunction.class)) {
        checkArgument(inputFunction.getParameterTypes().length > 0, "Input function has no parameters");
        Class<?> stateClass = inputFunction.getParameterTypes()[0];
        checkArgument(AccumulatorState.class.isAssignableFrom(stateClass),
                "stateClass is not a subclass of AccumulatorState");
        builder.add(stateClass);/*from   w w  w .j a  v  a 2 s  . co  m*/
    }
    ImmutableSet<Class<?>> stateClasses = builder.build();
    checkArgument(!stateClasses.isEmpty(), "No input functions found");

    return stateClasses;
}

From source file:de.metas.ui.web.window.datatypes.DocumentIdsSelection.java

public static DocumentIdsSelection ofStringSet(final Collection<String> stringDocumentIds) {
    if (stringDocumentIds == null || stringDocumentIds.isEmpty()) {
        return EMPTY;
    }//w  w w. ja v  a  2  s  . c o  m

    final ImmutableSet.Builder<DocumentId> documentIdsBuilder = ImmutableSet.builder();
    for (final String documentIdStr : stringDocumentIds) {
        if (ALL_String.equals(documentIdStr)) {
            return ALL;
        }

        documentIdsBuilder.add(DocumentId.of(documentIdStr));
    }

    final ImmutableSet<DocumentId> documentIds = documentIdsBuilder.build();
    if (documentIds.isEmpty()) {
        return EMPTY;
    }
    return new DocumentIdsSelection(false, documentIds);
}

From source file:com.google.errorprone.bugpatterns.StaticImports.java

/**
 * Returns a {@code StaticImportInfo} for a static field or method import.
 *///from  ww  w.j  av  a 2  s. c o m
private static StaticImportInfo tryAsStaticMember(JCTree.JCFieldAccess access, VisitorState state) {
    Name identifier = access.getIdentifier();
    if (identifier.contentEquals("*")) {
        // Java doesn't allow non-canonical types inside wildcard imports,
        // so there's nothing to do here.
        return null;
    }
    String importedTypeName = access.getExpression().toString();
    Type importedType = state.getTypeFromString(importedTypeName);
    if (importedType == null) {
        return null;
    }

    Types types = state.getTypes();

    Type canonicalType = types.erasure(importedType);
    if (canonicalType == null) {
        return null;
    }
    Symbol.TypeSymbol baseType;
    {
        Symbol sym = ASTHelpers.getSymbol(access.getExpression());
        if (!(sym instanceof Symbol.TypeSymbol)) {
            return null;
        }
        baseType = (Symbol.TypeSymbol) sym;
    }
    Symbol.PackageSymbol pkgSym = ((JCTree.JCCompilationUnit) state.getPath().getCompilationUnit()).packge;
    ImmutableSet<Symbol> members = lookup(baseType, baseType, identifier, types, pkgSym);
    if (members.isEmpty()) {
        return null;
    }

    /* Find the most specific subtype that defines one of the members that is imported.
     * TODO(gak): we should instead find the most specific subtype with a member that is _used_ */
    Type canonicalOwner = null;
    for (Symbol member : members) {
        Type owner = types.erasure(member.owner.type);
        if (canonicalOwner == null || types.isSubtype(owner, canonicalOwner)) {
            canonicalOwner = owner;
        }
    }

    if (canonicalOwner == null) {
        return null;
    }
    return StaticImportInfo.create(importedTypeName, canonicalOwner.toString(), identifier.toString(), members);
}

From source file:com.facebook.buck.distributed.DistBuildUtil.java

/** Checks whether the given targets match the Stampede project whitelist */
protected static boolean doTargetsMatchProjectWhitelist(ImmutableSet<String> buildTargets,
        ImmutableSet<String> projectWhitelist) {
    if (buildTargets.isEmpty()) {
        return false;
    }//  w  w  w . j ava  2  s.  co  m
    boolean mismatchFound = false;
    for (String buildTarget : buildTargets) {
        Pattern pattern = Pattern.compile(TARGET_TO_PROJECT_REGREX);
        Matcher matcher = pattern.matcher(buildTarget);

        if (matcher.find()) {
            // Check the project for the given target is whitelisted
            String projectForTarget = matcher.group(1);
            mismatchFound = !projectWhitelist.contains(projectForTarget);
        } else {
            mismatchFound = true;
        }

        if (mismatchFound) {
            break;
        }
    }

    return !mismatchFound;
}

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

/**
 * Propagate flavors represented by the given {@link FlavorDomain} objects from a parent
 * target to its dependencies.// ww  w. ja  v  a 2 s  . co  m
 */
public static ImmutableSortedSet<BuildTarget> propagateFlavorDomains(BuildTarget target,
        Iterable<FlavorDomain<?>> domains, Iterable<BuildTarget> deps) {

    Set<Flavor> flavors = Sets.newHashSet();

    // For each flavor domain, extract the corresponding flavor from the parent target and
    // verify that each dependency hasn't already set this flavor.
    for (FlavorDomain<?> domain : domains) {

        // Now extract all relevant domain flavors from our parent target.
        ImmutableSet<Flavor> flavorSet = Sets.intersection(domain.getFlavors(), target.getFlavors())
                .immutableCopy();

        if (flavorSet.isEmpty()) {
            throw new HumanReadableException("%s: no flavor for \"%s\"", target, domain.getName());
        }
        flavors.addAll(flavorSet);

        // First verify that our deps are not already flavored for our given domains.
        for (BuildTarget dep : deps) {
            if (domain.getFlavor(dep).isPresent()) {
                throw new HumanReadableException("%s: dep %s already has flavor for \"%s\" : %s", target, dep,
                        domain.getName(), flavorSet.toString());
            }
        }
    }

    ImmutableSortedSet.Builder<BuildTarget> flavoredDeps = ImmutableSortedSet.naturalOrder();

    // Now flavor each dependency with the relevant flavors.
    for (BuildTarget dep : deps) {
        flavoredDeps.add(BuildTarget.builder(dep).addAllFlavors(flavors).build());
    }

    return flavoredDeps.build();
}

From source file:com.kolich.curacao.mappers.request.matchers.DefaultCuracaoRegexPathMatcher.java

@Nonnull
private static final ImmutableMap<String, String> getNamedGroupsAndValues(final String regex, final Matcher m) {
    final ImmutableSet<String> groups = getNamedGroups(regex);
    // If the provided regex has no capture groups, there's no point in
    // actually trying to build a new map to hold the results
    if (groups.isEmpty()) {
        return ImmutableMap.of(); // Empty, immutable map
    } else {/*from   w  w  w .  jav a2  s. co  m*/
        final ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
        // For each extract "capture group" in the regex...
        for (final String groupName : groups) {
            final String value;
            if ((value = m.group(groupName)) != null) {
                // Only non-null values are injected into the map.
                builder.put(groupName, value);
            }
        }
        return builder.build(); // Immutable
    }
}

From source file:org.gradle.internal.ImmutableActionSet.java

private static <T> ImmutableActionSet<T> fromActions(ImmutableSet<Action<? super T>> set) {
    if (set.isEmpty()) {
        return empty();
    }//w w  w .jav  a 2  s.  com
    if (set.size() == 1) {
        return new SingletonSet<T>(set.iterator().next());
    }
    if (set.size() <= FEW_VALUES) {
        return new SetWithFewActions<T>(set);
    }
    return new SetWithManyActions<T>(set);
}

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  ww w.j  av a 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.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>/*ww w. j  av a2s . c om*/
 * 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:eu.eidas.auth.engine.xml.opensaml.AssertionUtil.java

private static String getUniquenessIdentifier(@Nonnull ImmutableAttributeMap attributeMap)
        throws EIDASSAMLEngineException {
    for (final Map.Entry<AttributeDefinition<?>, ImmutableSet<? extends AttributeValue<?>>> entry : attributeMap
            .getAttributeMap().entrySet()) {
        AttributeDefinition<?> attributeDefinition = entry.getKey();
        ImmutableSet<? extends AttributeValue<?>> values = entry.getValue();
        if (attributeDefinition.isUniqueIdentifier() && !values.isEmpty()) {
            AttributeValueMarshaller<?> attributeValueMarshaller = attributeDefinition
                    .getAttributeValueMarshaller();
            try {
                return attributeValueMarshaller.marshal((AttributeValue) values.iterator().next());
            } catch (AttributeValueMarshallingException e) {
                LOG.error("BUSINESS EXCEPTION : Invalid Attribute Value " + e, e);
                throw new EIDASSAMLEngineException(EidasErrorKey.INTERNAL_ERROR.errorCode(),
                        EidasErrorKey.INTERNAL_ERROR.errorCode(), e);
            }/*  w ww .  j  a va2 s  .co m*/
        }
    }
    String message = "Unique Identifier not found: " + attributeMap;
    LOG.info("BUSINESS EXCEPTION : " + message);
    throw new EIDASSAMLEngineException(EidasErrorKey.INTERNAL_ERROR.errorCode(),
            EidasErrorKey.INTERNAL_ERROR.errorCode(), message);
}