List of usage examples for com.google.common.collect ImmutableSet size
int size();
From source file:edu.wpi.checksims.ChecksimsRunner.java
/** * Main public entrypoint to Checksims. Runs similarity detection according to given configuration. * * @param config Configuration defining how Checksims will be run *//*www.j a v a 2 s . c om*/ public static void runChecksims(ChecksimsConfig config) { checkNotNull(config); // 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."); if (submissions.size() == 0) { logs.error("No student submissions were found! Nothing to do!"); System.exit(0); } // Apply the common code handler (which may just be a pass-through operation, if there is no common code) submissions = ImmutableSet.copyOf(config.getCommonCodeHandler().handleCommonCode(submissions)); // Apply all preprocessors for (SubmissionPreprocessor p : config.getPreprocessors()) { submissions = ImmutableSet.copyOf(PreprocessSubmissions.process(p, submissions)); } if (submissions.size() < 2) { logs.error("Not enough submissions for a pairwise comparison! Nothing to do!"); System.exit(0); } // Apply algorithm to submission Set<Pair<Submission, Submission>> allPairs = PairGenerator.generatePairs(submissions); Set<AlgorithmResults> results = AlgorithmRunner.runAlgorithm(allPairs, config.getAlgorithm()); try { SimilarityMatrix resultsMatrix = SimilarityMatrix.generateMatrix(submissions, results); // All parallel jobs are done, shut down the parallel executor ParallelAlgorithm.shutdownExecutor(); // Output using all output printers OutputPrinter printer = config.getOutputMethod(); for (MatrixPrinter p : config.getOutputPrinters()) { logs.info("Generating " + p.getName() + " output"); printer.print(resultsMatrix, p); } } catch (InternalAlgorithmError e) { logs.error("Error generating Similarity Matrix!"); logs.error(e.getMessage()); e.printStackTrace(); System.exit(-1); } }
From source file:com.google.template.soy.types.aggregate.UnionType.java
/** * Create a union from a collection of types. * @param members Member types of the union. * @return Union of those types.//from w w w. ja va 2s . co m * If there is exactly one distinct type in members, then this will not be a UnionType. */ public static SoyType of(Collection<SoyType> members) { ImmutableSet<SoyType> flattenedMembers = flatten(members); if (flattenedMembers.size() == 1) { return Iterables.getOnlyElement(flattenedMembers); } return new UnionType(flattenedMembers); }
From source file:dagger2.internal.codegen.ProvidesMethodValidator.java
/** Validates that a Provides or Produces method doesn't have multiple qualifiers. */ static void validateMethodQualifiers(ValidationReport.Builder<ExecutableElement> builder, ExecutableElement methodElement) { ImmutableSet<? extends AnnotationMirror> qualifiers = getQualifiers(methodElement); if (qualifiers.size() > 1) { for (AnnotationMirror qualifier : qualifiers) { builder.addItem(PROVIDES_OR_PRODUCES_METHOD_MULTIPLE_QUALIFIERS, methodElement, qualifier); }/*from w w w . j a va2s .co m*/ } }
From source file:dagger2.internal.codegen.Binding.java
static Optional<String> bindingPackageFor(Iterable<? extends Binding> bindings) { ImmutableSet.Builder<String> bindingPackagesBuilder = ImmutableSet.builder(); for (Binding binding : bindings) { bindingPackagesBuilder.addAll(binding.bindingPackage().asSet()); }//from www .j a v a2 s.co m ImmutableSet<String> bindingPackages = bindingPackagesBuilder.build(); switch (bindingPackages.size()) { case 0: return Optional.absent(); case 1: return Optional.of(bindingPackages.iterator().next()); default: throw new IllegalArgumentException(); } }
From source file:com.palantir.atlasdb.keyvalue.cassandra.jmx.CassandraJmxCompaction.java
public static Optional<CassandraJmxCompactionManager> createJmxCompactionManager( CassandraKeyValueServiceConfigManager configManager) { Preconditions.checkNotNull(configManager); CassandraKeyValueServiceConfig config = configManager.getConfig(); CassandraJmxCompaction jmxCompaction = new CassandraJmxCompaction(config); Optional<CassandraJmxCompactionConfig> jmxConfig = config.jmx(); // need to set the property before creating the JMX compaction client if (!jmxConfig.isPresent()) { log.info("Jmx compaction is not enabled."); return Optional.absent(); }// ww w . j a v a 2 s . c o m jmxCompaction.setJmxSslProperty(jmxConfig.get()); ImmutableSet<CassandraJmxCompactionClient> clients = jmxCompaction.createCompactionClients(jmxConfig.get()); ExecutorService exec = Executors.newFixedThreadPool(clients.size(), new ThreadFactoryBuilder().setNameFormat("Cassandra-Jmx-Compaction-ThreadPool-%d").build()); return Optional.of(CassandraJmxCompactionManager.create(clients, exec)); }
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 ww w .j ava 2 s . co 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:ca.cutterslade.match.scheduler.Scheduler.java
private static ImmutableSet<Team> padWithByes(ImmutableSet<Tier> tiers, ImmutableSet<Team> realTeams, int teamsPerTier) { ImmutableSet.Builder<Team> b = ImmutableSet.builder(); for (Tier tier : tiers) { ImmutableSet<Team> tierTeams = ImmutableSet.copyOf(tier.getTeams(realTeams)); b.addAll(tierTeams);/*from w w w . j av a2s .co m*/ if (tierTeams.size() > teamsPerTier) throw new AssertionError("More than allowed number of teams"); if (tierTeams.size() < teamsPerTier) for (int i = 0, n = teamsPerTier - tierTeams.size(); i < n; i++) b.add(new Team("B" + i, tier)); } return b.build(); }
From source file:com.spectralogic.ds3autogen.utils.ConverterUtil.java
/** * Gets a set of type names used within a list of Ds3Types *///from w w w. ja v a 2 s . com protected static ImmutableSet<String> getUsedTypesFromAllTypes(final ImmutableMap<String, Ds3Type> typeMap, final ImmutableSet<String> usedTypes) { if (isEmpty(usedTypes) || isEmpty(typeMap)) { return ImmutableSet.of(); } final ImmutableSet.Builder<String> builder = ImmutableSet.builder(); builder.addAll(usedTypes); for (final String type : usedTypes) { final Ds3Type ds3Type = typeMap.get(type); if (ds3Type != null) { builder.addAll(getUsedTypesFromType(ds3Type)); } else { //Log but do not throw an exception because there are cases where a type //doesn't need to be generated. Especially true during testing. LOG.error("Could not find used type in Type Map: " + type); } } final ImmutableSet<String> newUsedTypes = builder.build(); if (newUsedTypes.size() > usedTypes.size()) { return getUsedTypesFromAllTypes(typeMap, newUsedTypes); } return newUsedTypes; }
From source file:com.facebook.buck.distributed.DistBuildState.java
public static BuildJobState dump(DistBuildCellIndexer distributedBuildCellIndexer, DistBuildFileHashes fileHashes, DistBuildTargetGraphCodec targetGraphCodec, TargetGraph targetGraph, ImmutableSet<BuildTarget> topLevelTargets) throws IOException, InterruptedException { Preconditions.checkArgument(topLevelTargets.size() > 0); BuildJobState jobState = new BuildJobState(); jobState.setFileHashes(fileHashes.getFileHashes()); jobState.setTargetGraph(targetGraphCodec.dump(targetGraph.getNodes(), distributedBuildCellIndexer)); jobState.setCells(distributedBuildCellIndexer.getState()); for (BuildTarget target : topLevelTargets) { jobState.addToTopLevelTargets(target.getFullyQualifiedName()); }//from w w w. j a v a 2s.com return jobState; }
From source file:ai.grakn.graql.Autocomplete.java
/** * @param types the graph to find types in * @param query a graql query/*from w ww .jav a 2 s. c o m*/ * @param optToken the token the cursor is on in the query * @return a set of potential autocomplete words */ private static ImmutableSet<String> findCandidates(Set<String> types, String query, Optional<? extends Token> optToken) { ImmutableSet<String> allCandidates = Stream.of(GRAQL_KEYWORDS.stream(), types.stream(), getVariables(query)) .flatMap(Function.identity()).collect(toImmutableSet()); return optToken.map(token -> { ImmutableSet<String> candidates = allCandidates.stream() .filter(candidate -> candidate.startsWith(token.getText())).collect(toImmutableSet()); if (candidates.size() == 1 && candidates.iterator().next().equals(token.getText())) { return ImmutableSet.of(" "); } else { return candidates; } }).orElse(allCandidates); }