Example usage for com.google.common.collect ImmutableList builder

List of usage examples for com.google.common.collect ImmutableList builder

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableList builder.

Prototype

public static <E> Builder<E> builder() 

Source Link

Usage

From source file:com.google.errorprone.matchers.ConstructorOfClass.java

@Override
protected Iterable<? extends MethodTree> getChildNodes(ClassTree classTree, VisitorState state) {
    ImmutableList.Builder<MethodTree> result = ImmutableList.builder();
    // Iterate over members of class (methods and fields).
    for (Tree member : classTree.getMembers()) {
        // If this member is a constructor...
        if (member instanceof MethodTree && ASTHelpers.getSymbol(member).isConstructor()) {
            result.add((MethodTree) member);
        }//from w ww .j  av a  2 s  .  com
    }
    return result.build();
}

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

/**
 * Creates a {@link TargetSources} given a list of {@link AppleSource}s.
 *//*from  w w w .ja  va 2  s .c o  m*/
public static TargetSources ofAppleSources(SourcePathResolver resolver, Collection<AppleSource> appleSources) {
    ImmutableList.Builder<GroupedSource> srcsBuilder = ImmutableList.builder();
    ImmutableSortedMap.Builder<SourcePath, String> perFileFlagsBuilder = ImmutableSortedMap.naturalOrder();
    ImmutableSortedSet.Builder<SourcePath> srcPathsBuilder = ImmutableSortedSet.naturalOrder();
    ImmutableSortedSet.Builder<SourcePath> headerPathsBuilder = ImmutableSortedSet.naturalOrder();
    RuleUtils.extractSourcePaths(resolver, srcsBuilder, perFileFlagsBuilder, srcPathsBuilder,
            headerPathsBuilder, appleSources);
    return new TargetSources(srcsBuilder.build(), perFileFlagsBuilder.build(), srcPathsBuilder.build(),
            headerPathsBuilder.build());
}

From source file:com.spectralogic.ds3autogen.utils.Ds3ElementUtil.java

/**
 * Gets the Xml tag name for an element from its list of Ds3Annotations, if one
 * exists. If multiple Xml tag names are found, an exception is thrown.
 *//*w  ww  .  j  ava2 s .co  m*/
protected static String getXmlTagFromAllAnnotations(final ImmutableList<Ds3Annotation> annotations,
        final String elementName) {
    if (isEmpty(annotations)) {
        return "";
    }
    final ImmutableList.Builder<String> builder = ImmutableList.builder();
    for (final Ds3Annotation annotation : annotations) {
        final String curXmlName = getXmlTagFromAnnotation(annotation);
        if (hasContent(curXmlName)) {
            builder.add(curXmlName);
        }
    }
    final ImmutableList<String> xmlNames = builder.build();
    switch (xmlNames.size()) {
    case 0:
        return "";
    case 1:
        return xmlNames.get(0);
    default:
        throw new IllegalArgumentException(
                "There are multiple xml tag names described within the annotations for the element "
                        + elementName + ": " + xmlNames.toString());
    }
}

From source file:com.sun.tools.hat.internal.lang.openjdk6.JavaLinkedList.java

public static JavaLinkedList make(JavaObject list) {
    JavaObject header = Models.getFieldObject(list, "header");
    if (header == null)
        return null;
    ImmutableList.Builder<JavaThing> builder = ImmutableList.builder();
    for (JavaObject entry = Models.getFieldObject(header, "next"); entry != header; entry = Models
            .getFieldObject(entry, "next")) {
        if (entry == null)
            return null;
        builder.add(entry.getField("element"));
    }/*from   ww  w .j av a2 s .  c om*/
    return new JavaLinkedList(builder.build());
}

From source file:com.spotify.heroic.aggregation.AbstractAggregationDSL.java

protected List<Aggregation> flatten(final AggregationArguments args) {
    final ImmutableList.Builder<Aggregation> aggregations = ImmutableList.builder();
    args.takeArguments(Value.class).stream().map(this::flatten).forEach(aggregations::addAll);
    return aggregations.build();
}

From source file:ru.org.linux.spring.SectionStore.java

public SectionStore() throws SQLException {
    Connection db = LorDataSource.getConnection();

    try {/*from ww w.  j a v a2 s .c  o  m*/
        ImmutableMap.Builder<Integer, Section> sections = ImmutableMap.builder();
        ImmutableList.Builder<Section> sectionsList = ImmutableList.builder();

        Statement st = db.createStatement();

        ResultSet rs = st.executeQuery("SELECT id, name, imagepost, vote, moderate FROM sections ORDER BY id");

        while (rs.next()) {
            Section section = new Section(rs);

            sections.put(section.getId(), section);
            sectionsList.add(section);
        }

        this.sections = sections.build();
        this.sectionsList = sectionsList.build();
    } finally {
        db.close();
    }
}

From source file:com.squareup.wire.schema.EnumConstant.java

static ImmutableList<EnumConstant> fromElements(ImmutableList<EnumConstantElement> elements) {
    ImmutableList.Builder<EnumConstant> constants = ImmutableList.builder();
    for (EnumConstantElement element : elements) {
        constants.add(fromElement(element));
    }//from   ww  w.j  a v a2 s  .  c o  m
    return constants.build();
}

From source file:ru.org.linux.section.SectionService.java

/**
 * ? ?? ?  ./*  w ww.j a  va2 s  . c o  m*/
 *  ?? ? ? ? ?? .
 */
@PostConstruct
private void initializeSectionList() {
    Builder<Section> sectionListBuilder = ImmutableList.builder();
    List<Section> sections = sectionDao.getAllSections();
    sectionListBuilder.addAll(sections);
    sectionList = sectionListBuilder.build();
}

From source file:be.woutdev.tribes.squirrelid.resolver.SingleRequestService.java

@Override
public final ImmutableList<Profile> findAllByName(Iterable<String> names)
        throws IOException, InterruptedException {
    Builder<Profile> builder = ImmutableList.builder();
    for (String name : names) {
        Profile profile = findByName(name);
        if (profile != null) {
            builder.add(profile);/*www  .j  ava2 s.c om*/
        }
    }
    return builder.build();
}

From source file:io.prestosql.plugin.blackhole.BlackHoleSplitManager.java

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session,
        ConnectorTableLayoutHandle layoutHandle, SplitSchedulingStrategy splitSchedulingStrategy) {
    BlackHoleTableLayoutHandle layout = (BlackHoleTableLayoutHandle) layoutHandle;

    ImmutableList.Builder<BlackHoleSplit> builder = ImmutableList.builder();

    for (int i = 0; i < layout.getSplitCount(); i++) {
        builder.add(new BlackHoleSplit(layout.getPagesPerSplit(), layout.getRowsPerPage(),
                layout.getFieldsLength(), layout.getPageProcessingDelay()));
    }//from   ww  w  .  j  av  a  2s . c o m
    return new FixedSplitSource(builder.build());
}