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.google.devtools.build.lib.packages.AdvertisedProviderSet.java

public static AdvertisedProviderSet create(ImmutableSet<Class<?>> nativeProviders,
        ImmutableSet<String> skylarkProviders) {
    if (nativeProviders.isEmpty() && skylarkProviders.isEmpty()) {
        return EMPTY;
    }/* www.jav a 2 s .  co m*/
    return new AdvertisedProviderSet(false, nativeProviders, skylarkProviders);
}

From source file:dagger.internal.codegen.Scope.java

/**
 * Returns at most one associated scoped annotation from the source code element, throwing an
 * exception if there are more than one.
 *///ww w.j a v  a  2  s .  co  m
static Optional<Scope> uniqueScopeOf(Element element) {
    ImmutableSet<? extends AnnotationMirror> scopeAnnotations = getScopes(element);
    if (scopeAnnotations.isEmpty()) {
        return Optional.empty();
    }
    return Optional.of(scope(Iterables.getOnlyElement(scopeAnnotations)));
}

From source file:com.facebook.buck.apple.Flavors.java

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

    Set<Flavor> flavors = new HashSet<>();

    // 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(dep.withAppendedFlavors(flavors));
    }

    return flavoredDeps.build();
}

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

static ImmutableSet<EnumType> union(ImmutableSet<EnumType> s1, ImmutableSet<EnumType> s2) {
    if (s1.isEmpty()) {
        return s2;
    }/*from www . ja va2 s .  c o m*/
    if (s2.isEmpty() || s1.equals(s2)) {
        return s1;
    }
    return Sets.union(s1, s2).immutableCopy();
}

From source file:ai.grakn.graql.internal.reasoner.query.QueryAnswerStream.java

/**
 * lazy stream join with fast lookup from inverse answer map
 * @param stream left stream operand//from  w  ww.  j  a v  a2  s  .c  o  m
 * @param stream2 right stream operand
 * @param stream2InverseMap inverse map of right operand from cache
 * @param joinVars intersection on variables of two streams
 * @return joined stream
 */
public static Stream<Answer> joinWithInverse(Stream<Answer> stream, Stream<Answer> stream2,
        Map<Pair<Var, Concept>, Set<Answer>> stream2InverseMap, ImmutableSet<Var> joinVars,
        boolean explanation) {
    if (joinVars.isEmpty()) {
        LazyAnswerIterator l2 = new LazyAnswerIterator(stream2);
        return stream.flatMap(a1 -> l2.stream().map(a -> a.merge(a1, explanation)));
    }
    return stream.flatMap(a1 -> {
        Iterator<Var> vit = joinVars.iterator();
        Set<Answer> matchAnswers = findMatchingAnswers(a1, stream2InverseMap, vit.next());
        while (vit.hasNext()) {
            matchAnswers = Sets.intersection(matchAnswers,
                    findMatchingAnswers(a1, stream2InverseMap, vit.next()));
        }
        return matchAnswers.stream().map(a -> a.merge(a1, explanation));
    });
}

From source file:net.lldp.checksims.ChecksimsRunner.java

/**
 * Main public entrypoint to Checksims. Runs similarity detection according to given configuration.
 *
 * @param config Configuration defining how Checksims will be run
 * @return Map containing output of all output printers requested. Keys are name of output printer.
 * @throws ChecksimsException Thrown on error performing similarity detection
 *///from  w w w .  j  a  v a  2s  .  c  o  m
public static ImmutableMap<String, String> runChecksims(ChecksimsConfig config) throws ChecksimsException {
    checkNotNull(config);

    // Create a logger to log activity
    Logger logs = LoggerFactory.getLogger(ChecksimsRunner.class);

    // Set parallelism
    int threads = config.getNumThreads();
    ParallelAlgorithm.setThreadCount(threads);
    // TODO following line may not be necessary as we no longer use parallel streams?
    System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "" + threads);

    ImmutableSet<Submission> submissions = config.getSubmissions();

    logs.info("Got " + submissions.size() + " submissions to test.");

    ImmutableSet<Submission> archiveSubmissions = config.getArchiveSubmissions();

    if (!archiveSubmissions.isEmpty()) {
        logs.info("Got " + archiveSubmissions.size() + " archive submissions to test.");
    }

    if (submissions.size() == 0) {
        throw new ChecksimsException("No student submissions were found - cannot run Checksims!");
    }

    // Apply all preprocessors
    for (SubmissionPreprocessor p : config.getPreprocessors()) {
        submissions = ImmutableSet
                .copyOf(PreprocessSubmissions.process(p, submissions, config.getStatusLogger()));

        if (!archiveSubmissions.isEmpty()) {
            archiveSubmissions = ImmutableSet
                    .copyOf(PreprocessSubmissions.process(p, archiveSubmissions, config.getStatusLogger()));
        }
    }

    if (submissions.size() < 2) {
        throw new ChecksimsException("Did not get at least 2 student submissions! Cannot run Checksims!");
    }

    // Apply algorithm to submissions
    Set<Pair<Submission, Submission>> allPairs = PairGenerator.generatePairsWithArchive(submissions,
            archiveSubmissions);
    Set<AlgorithmResults> results = AlgorithmRunner.runAlgorithm(allPairs, config.getAlgorithm(),
            config.getStatusLogger());

    if (config.isIgnoringInvalid()) {
        Set<Submission> validSubmissions = new HashSet<>();
        Set<Submission> validArchivedSubmissions = new HashSet<>();
        Set<AlgorithmResults> validResults = new HashSet<>();
        submissions.stream().filter(S -> !S.testFlag("invalid")).forEach(S -> validSubmissions.add(S));
        archiveSubmissions.stream().filter(S -> !S.testFlag("invalid"))
                .forEach(S -> validArchivedSubmissions.add(S));
        results.stream().filter(S -> S.isValid()).forEach(S -> validResults.add(S));

        submissions = ImmutableSet.copyOf(validSubmissions);
        archiveSubmissions = ImmutableSet.copyOf(validArchivedSubmissions);
        results = validResults;

    }

    SimilarityMatrix resultsMatrix = SimilarityMatrix.generateMatrix(submissions, archiveSubmissions, results);

    // All parallel jobs are done, shut down the parallel executor
    ParallelAlgorithm.shutdownExecutor();
    config.getStatusLogger().end();

    Map<String, String> outputMap = new HashMap<>();

    // Output using all output printers
    for (MatrixPrinter p : config.getOutputPrinters()) {
        logs.info("Generating " + p.getName() + " output");

        outputMap.put(p.getName(), p.printMatrix(resultsMatrix));
    }

    ChecksimsCommandLine.deleteTempFiles();

    return ImmutableMap.copyOf(outputMap);
}

From source file:com.google.caliper.runner.instrument.InstrumentModule.java

@RunScoped
@Provides/*from ww w .jav a 2  s. c  o  m*/
static ImmutableSet<Instrument> provideInstruments(CaliperOptions options, final CaliperConfig config,
        Map<Class<? extends Instrument>, Provider<Instrument>> availableInstruments,
        ImmutableSet<VmType> vmTypes, @Stderr PrintWriter stderr) throws InvalidCommandException {

    ImmutableSet.Builder<Instrument> builder = ImmutableSet.builder();
    ImmutableSet<String> configuredInstruments = config.getConfiguredInstruments();
    ImmutableSet<String> selectedInstruments = options.instrumentNames();

    if (selectedInstruments.isEmpty()) {
        selectedInstruments = config.getDefaultInstruments();
    }

    for (final String instrumentName : selectedInstruments) {
        if (!configuredInstruments.contains(instrumentName)) {
            throw new InvalidCommandException(
                    "%s is not a configured instrument (%s). "
                            + "use --print-config to see the configured instruments.",
                    instrumentName, configuredInstruments);
        }
        final InstrumentConfig instrumentConfig = config.getInstrumentConfig(instrumentName);
        String className = instrumentConfig.className();
        try {
            Class<? extends Instrument> clazz = Util.lenientClassForName(className)
                    .asSubclass(Instrument.class);
            Provider<Instrument> instrumentProvider = availableInstruments.get(clazz);
            if (instrumentProvider == null) {
                throw new InvalidInstrumentException("Instrument %s not supported", className);
            }

            if (isSupportedByAllVms(clazz, vmTypes)) {
                Instrument instrument = instrumentProvider.get();
                InstrumentInjectorModule injectorModule = new InstrumentInjectorModule(instrumentConfig,
                        instrumentName);
                InstrumentComponent instrumentComponent = DaggerInstrumentComponent.builder()
                        .instrumentInjectorModule(injectorModule).build();
                instrumentComponent.injectInstrument(instrument);
                builder.add(instrument);
            } else {
                stderr.format("Instrument %s not supported on at least one target VM; ignoring\n", className);
            }
        } catch (ClassNotFoundException e) {
            throw new InvalidCommandException("Cannot find instrument class '%s'", className);
        }
    }
    return builder.build();
}

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

private static Set<Class<?>> getStateClasses(Class<?> clazz) {
    ImmutableSet.Builder<Class<?>> builder = ImmutableSet.builder();
    for (Method inputFunction : FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(clazz,
            InputFunction.class)) {
        checkArgument(inputFunction.getParameterTypes().length > 0, "Input function has no parameters");
        Class<?> stateClass = AggregationImplementation.Parser.findAggregationStateParamType(inputFunction);

        checkArgument(AccumulatorState.class.isAssignableFrom(stateClass),
                "stateClass is not a subclass of AccumulatorState");
        builder.add(stateClass);/*from ww  w.java  2s .  c  om*/
    }
    ImmutableSet<Class<?>> stateClasses = builder.build();
    checkArgument(!stateClasses.isEmpty(), "No input functions found");

    return stateClasses;
}

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

private static void checkForUnimplementedExtensions(ImmutableList<CommandExtension> suppliedExtensionInstances,
        ImmutableSet<Class<? extends CommandExtension>> implementedExtensionClasses)
        throws UnimplementedExtensionException {
    ImmutableSet.Builder<Class<? extends CommandExtension>> unimplementedExtensionsBuilder = new ImmutableSet.Builder<>();
    for (final CommandExtension instance : suppliedExtensionInstances) {
        if (!any(implementedExtensionClasses, new Predicate<Class<? extends CommandExtension>>() {
            @Override//from  w  w  w  . j av a 2s . c o m
            public boolean apply(Class<? extends CommandExtension> implementedExtensionClass) {
                return implementedExtensionClass.isInstance(instance);
            }
        })) {
            unimplementedExtensionsBuilder.add(instance.getClass());
        }
    }
    ImmutableSet<Class<? extends CommandExtension>> unimplementedExtensions = unimplementedExtensionsBuilder
            .build();
    if (!unimplementedExtensions.isEmpty()) {
        logger.infofmt("Unimplemented extensions: %s", unimplementedExtensions);
        throw new UnimplementedExtensionException();
    }
}

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

public static Predicate<BuildTarget> containsFlavors(final FlavorDomain<?> domain) {
    return input -> {
        ImmutableSet<Flavor> flavorSet = Sets.intersection(domain.getFlavors(), input.getFlavors())
                .immutableCopy();/* ww  w . j ava 2  s  .  c o m*/
        return !flavorSet.isEmpty();
    };
}