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

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

Introduction

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

Prototype

int size();

Source Link

Document

Returns the number of elements in this set (its cardinality).

Usage

From source file:com.github.jsdossier.tools.Compile.java

public static void main(String[] args) throws Exception {
    Flags flags = new Flags();

    CmdLineParser parser = new CmdLineParser(flags);
    parser.setUsageWidth(79);//from  ww w .  j a va  2  s  .com
    parser.parseArgument(args);

    FileSystem fs = FileSystems.getDefault();
    final Path closure = fs.getPath(flags.closure).toAbsolutePath();

    ErrorManager errorManager = new PrintStreamErrorManager(System.err);
    JsFileParser jsFileParser = new JsFileParser(errorManager);

    List<DependencyInfo> info = new ArrayList<>(flags.inputs.size());
    for (String path : flags.inputs) {
        Path absPath = fs.getPath(path).toAbsolutePath();
        Path closureRelativePath = closure.relativize(absPath);
        info.add(jsFileParser.parseFile(absPath.toString(), closureRelativePath.toString(),
                new String(Files.readAllBytes(absPath), UTF_8)));
    }

    List<DependencyInfo> allDeps = new LinkedList<>(info);
    allDeps.addAll(new DepsFileParser(errorManager).parseFile(closure.resolve("deps.js").toString()));
    List<DependencyInfo> sortedDeps = new SortedDependencies<>(allDeps).getSortedDependenciesOf(info);

    ImmutableSet<String> compilerFlags = FluentIterable.from(sortedDeps)
            .transform(new Function<DependencyInfo, String>() {
                @Override
                public String apply(DependencyInfo input) {
                    return "--js=" + closure.resolve(input.getPathRelativeToClosureBase()).toAbsolutePath()
                            .normalize().toString();
                }
            }).append("--js=" + closure.resolve("base.js")).append(flags.flags).toSet();

    CommandLineRunner.main(compilerFlags.toArray(new String[compilerFlags.size()]));
}

From source file:com.google.cloud.genomics.examples.TransformNonVariantSegmentData.java

public static void main(String[] args) throws IOException, GeneralSecurityException {
    // Register the options so that they show up via --help.
    PipelineOptionsFactory.register(TransformNonVariantSegmentData.Options.class);
    TransformNonVariantSegmentData.Options options = PipelineOptionsFactory.fromArgs(args).withValidation()
            .as(TransformNonVariantSegmentData.Options.class);

    // Option validation is not yet automatic, we make an explicit call here.
    GenomicsDatasetOptions.Methods.validateOptions(options);
    Preconditions.checkState(options.getHasNonVariantSegments(),
            "This job is only valid for data containing non-variant segments. "
                    + "Set the --hasNonVariantSegments command line option accordingly.");

    // Grab and parse our optional list of genomes to skip.
    ImmutableSet<String> callSetNamesToExclude = null;
    String skipFilepath = options.getCallSetNamesToExclude();
    if (null != skipFilepath) {
        Iterable<String> callSetNames = Splitter.on(CharMatcher.BREAKING_WHITESPACE).omitEmptyStrings()
                .trimResults().split(Files.toString(new File(skipFilepath), Charset.defaultCharset()));
        callSetNamesToExclude = ImmutableSet.<String>builder().addAll(callSetNames).build();
        LOG.info("The pipeline will skip " + callSetNamesToExclude.size() + " genomes with callSetNames: "
                + callSetNamesToExclude);
    }/*ww w. j av a  2 s .  c o m*/

    GenomicsFactory.OfflineAuth auth = GenomicsOptions.Methods.getGenomicsAuth(options);
    List<SearchVariantsRequest> requests = GenomicsDatasetOptions.Methods.getVariantRequests(options, auth,
            SexChromosomeFilter.INCLUDE_XY);

    Pipeline p = Pipeline.create(options);
    DataflowWorkarounds.registerGenomicsCoders(p);

    PCollection<SearchVariantsRequest> input = p.begin().apply(Create.of(requests));

    // Create a collection of data with non-variant segments omitted but calls from overlapping
    // non-variant segments added to SNPs.
    PCollection<Variant> variants = JoinNonVariantSegmentsWithVariants.joinVariantsTransform(input, auth);

    // For each variant flag whether or not it has ambiguous calls for a particular sample and
    // optionally filter calls.
    PCollection<Variant> flaggedVariants = callSetNamesToExclude == null
            ? variants.apply(ParDo.of(new FlagVariantsWithAmbiguousCallsFn()))
            : variants.apply(ParDo.of(new FilterCallsFn(callSetNamesToExclude)))
                    .apply(ParDo.of(new FlagVariantsWithAmbiguousCallsFn()));

    // Emit the variants to BigQuery.
    flaggedVariants.apply(ParDo.of(new FormatVariantsFn()))
            .apply(BigQueryIO.Write.to(options.getOutputTable()).withSchema(getTableSchema())
                    .withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED)
                    .withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_TRUNCATE));

    p.run();
}

From source file:google.registry.monitoring.metrics.CustomFitter.java

/**
 * Create a new {@link CustomFitter} with the given interval boundaries.
 *
 * @param boundaries is a sorted list of interval boundaries
 * @throws IllegalArgumentException if {@code boundaries} is empty or not sorted in ascending
 *     order, or if a value in the set is infinite, {@code NaN}, or {@code -0.0}.
 *///from ww  w .j  a v a 2 s.  c om
public static CustomFitter create(ImmutableSet<Double> boundaries) {
    checkArgument(boundaries.size() > 0, "boundaries must not be empty");
    checkArgument(Ordering.natural().isOrdered(boundaries), "boundaries must be sorted");
    for (Double d : boundaries) {
        checkDouble(d);
    }

    return new AutoValue_CustomFitter(ImmutableSortedSet.copyOf(boundaries));
}

From source file:dagger2.internal.codegen.InjectionAnnotations.java

static Optional<AnnotationMirror> getScopeAnnotation(Element e) {
    checkNotNull(e);/*from w w w  .  ja  v  a 2  s.  c  om*/
    ImmutableSet<? extends AnnotationMirror> scopeAnnotations = getScopes(e);
    switch (scopeAnnotations.size()) {
    case 0:
        return Optional.absent();
    case 1:
        return Optional.<AnnotationMirror>of(scopeAnnotations.iterator().next());
    default:
        throw new IllegalArgumentException(e + " was annotated with more than one @Scope annotation");
    }
}

From source file:dagger2.internal.codegen.InjectionAnnotations.java

static Optional<AnnotationMirror> getQualifier(Element e) {
    checkNotNull(e);/*from ww  w.j a  v  a  2 s. c  o  m*/
    ImmutableSet<? extends AnnotationMirror> qualifierAnnotations = getQualifiers(e);
    switch (qualifierAnnotations.size()) {
    case 0:
        return Optional.absent();
    case 1:
        return Optional.<AnnotationMirror>of(qualifierAnnotations.iterator().next());
    default:
        throw new IllegalArgumentException(e + " was annotated with more than one @Qualifier annotation");
    }
}

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

static Optional<AnnotationMirror> getQualifier(Element e) {
    checkNotNull(e);//from   w w w. j  a va 2s.  c om
    ImmutableSet<? extends AnnotationMirror> qualifierAnnotations = getQualifiers(e);
    switch (qualifierAnnotations.size()) {
    case 0:
        return Optional.empty();
    case 1:
        return Optional.<AnnotationMirror>of(qualifierAnnotations.iterator().next());
    default:
        throw new IllegalArgumentException(e + " was annotated with more than one @Qualifier annotation");
    }
}

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

/** Validates that a Provides, Produces or Bind 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.addError(BINDING_METHOD_MULTIPLE_QUALIFIERS, methodElement, qualifier);
        }// w  ww  . j  a va  2s.  c o  m
    }
}

From source file:se.kth.id2203.overlay.LookupTable.java

/** Generates the initial node assignments, divides nodes into replication groups */
static LookupTable generate(ImmutableSet<NetAddress> nodes) {
    LookupTable lut = new LookupTable();
    int numNodes = nodes.size(); //number of nodes
    int numGroups = Math.floorDiv(numNodes, replicationDegree); //number of groups
    int range = keySpace / numGroups; //key range of each group
    int j = 0;/*w  w  w  .j a v  a  2  s  . c  o m*/
    //divide nodes into groups
    for (int i = 0; i < numNodes; i++) {
        if (j == keySpace) {
            j = 0;
        }
        lut.partitions.put(j, nodes.asList().get(i));
        j += range;
    }
    return lut;
}

From source file:com.google.auto.factory.processor.Parameter.java

static ImmutableSet<Parameter> forParameterList(List<? extends VariableElement> variables,
        List<? extends TypeMirror> variableTypes) {
    checkArgument(variables.size() == variableTypes.size());
    ImmutableSet.Builder<Parameter> builder = ImmutableSet.builder();
    Set<String> names = Sets.newHashSetWithExpectedSize(variables.size());
    for (int i = 0; i < variables.size(); i++) {
        Parameter parameter = forVariableElement(variables.get(i), variableTypes.get(i));
        checkArgument(names.add(parameter.name));
        builder.add(parameter);/*from  w w  w. j  ava  2  s . c o  m*/
    }
    ImmutableSet<Parameter> parameters = builder.build();
    checkArgument(variables.size() == parameters.size());
    return parameters;
}

From source file:com.google.template.soy.types.UnionType.java

/**
 * Create a union from a collection of types.
 *
 * @param members Member types of the union.
 * @return Union of those types. If there is exactly one distinct type in members, then this will
 *     not be a UnionType./*from   w w  w  .  j  a v a 2  s  . c  o  m*/
 */
public static SoyType of(Collection<SoyType> members) {
    ImmutableSet<SoyType> flattenedMembers = flatten(members);
    if (flattenedMembers.size() == 1) {
        return Iterables.getOnlyElement(flattenedMembers);
    }
    // unions with the error type should just resolve to the error type to simplify analysis.
    if (flattenedMembers.contains(ErrorType.getInstance())) {
        return ErrorType.getInstance();
    }
    return new UnionType(flattenedMembers);
}