List of usage examples for com.google.common.collect ImmutableList builder
public static <E> Builder<E> builder()
From source file:org.onosproject.net.resource.Resources.java
/** * Creates a factory for discrete-type with the specified parent ID and child. * * @param parent ID of the parent//from w w w. j a v a 2s. c om * @param child child * @return {@link DiscreteFactory} */ public static DiscreteFactory discrete(DiscreteResourceId parent, Object child) { checkNotNull(parent); checkNotNull(child); checkArgument(!(child instanceof Class<?>)); return new DiscreteFactory( new DiscreteResourceId(ImmutableList.builder().addAll(parent.components()).add(child).build())); }
From source file:org.sonar.plugins.scm.tfs.TfsPlugin.java
@Override public List getExtensions() { ImmutableList.Builder builder = ImmutableList.builder(); builder.add(TfsScmProvider.class, TfsBlameCommand.class, TfsConfiguration.class); builder.addAll(TfsConfiguration.getProperties()); return builder.build(); }
From source file:io.prestosql.server.ThreadResource.java
private static List<StackLine> toStackTrace(StackTraceElement[] stackTrace) { ImmutableList.Builder<StackLine> builder = ImmutableList.builder(); for (StackTraceElement item : stackTrace) { builder.add(new StackLine(item.getFileName(), item.getLineNumber(), item.getClassName(), item.getMethodName()));//from w w w . ja v a 2 s .co m } return builder.build(); }
From source file:io.prestosql.operator.scalar.annotations.ScalarFromAnnotationsParser.java
public static List<SqlScalarFunction> parseFunctionDefinition(Class<?> clazz) { ImmutableList.Builder<SqlScalarFunction> builder = ImmutableList.builder(); for (ScalarHeaderAndMethods scalar : findScalarsInFunctionDefinitionClass(clazz)) { builder.add(parseParametricScalar(scalar, FunctionsParserHelper.findConstructor(clazz))); }//from w w w .ja v a2s. c om return builder.build(); }
From source file:com.spectralogic.ds3contractcomparator.print.htmlprinter.generators.row.HtmlRowGenerator.java
/** * Recursively traverse an object using reflection and constructs the rows that * represent the object using the specified function. */// w w w . j a v a2s. c om public static <T> ImmutableList<Row> createRows(final T object, final int indent, Function<RowAttributes, Row> function) { final Field[] fields = object.getClass().getDeclaredFields(); final ImmutableList.Builder<Row> builder = ImmutableList.builder(); for (final Field field : fields) { final String property = field.getName(); final Optional<String> value = getPropertyValue(object, property); final int fieldIndent = toFieldIndent(indent, object, field); if (value.isPresent()) { if (field.getType() == ImmutableList.class) { builder.add(new NoChangeRow(fieldIndent, property, "")); final ImmutableList<?> objList = getListPropertyFromObject(field, object); objList.forEach(obj -> builder.addAll(createRows(obj, fieldIndent + 1, function))); } else { final RowAttributes attributes = new RowAttributes(fieldIndent, property, value.get()); builder.add(function.apply(attributes)); } } } return builder.build(); }
From source file:com.freiheit.fuava.simplebatch.processor.AbstractSingleItemProcessor.java
@Override public final Iterable<Result<OriginalItem, Output>> process( final Iterable<Result<OriginalItem, Input>> iterable) { final ImmutableList.Builder<Result<OriginalItem, Output>> b = ImmutableList.builder(); for (final Result<OriginalItem, Input> input : iterable) { b.add(processItem(input));/*from w ww. ja v a2s. c o m*/ } return b.build(); }
From source file:org.apache.abdera2.activities.io.gson.MultimapAdapter.java
protected static ImmutableList<Object> arraydes(JsonArray array, JsonDeserializationContext context) { ImmutableList.Builder<Object> builder = ImmutableList.builder(); for (JsonElement child : array) if (child.isJsonArray()) builder.add(arraydes(child.getAsJsonArray(), context)); else if (child.isJsonObject()) builder.add(context.deserialize(child, ASBase.class)); else if (child.isJsonPrimitive()) builder.add(primdes(child.getAsJsonPrimitive())); return builder.build(); }
From source file:com.google.cloud.genomics.dataflow.functions.verifybamid.ReadFunctions.java
/** * Use the given read to build a list of aligned read and reference base * information.// ww w . j a va2 s. c o m * * @param read The read with the alignment information * @return read and reference information. For a read without an alignment * or cigar units, null is returned. */ public static List<ReadBaseWithReference> extractReadBases(Read read) { // Make sure this read has a valid alignment with Cigar Units if (!read.hasAlignment() || (read.getAlignment().getCigarCount() == 0)) { return null; } ImmutableList.Builder<ReadBaseWithReference> bases = ImmutableList.builder(); String readSeq = read.getAlignedSequence(); List<Integer> readQual = read.getAlignedQualityList(); String refSeq = UNINITIALIZED_REFERENCE_SEQUENCE; int refPosAbsoluteOffset = 0; int readOffset = 0; for (CigarUnit unit : read.getAlignment().getCigarList()) { switch (unit.getOperation()) { case ALIGNMENT_MATCH: case SEQUENCE_MISMATCH: case SEQUENCE_MATCH: for (int i = 0; i < unit.getOperationLength(); i++) { String refBase = ""; if (unit.getOperation().equals(CigarUnit.Operation.SEQUENCE_MATCH)) { refBase = readSeq.substring(readOffset, readOffset + 1); } else if (!unit.getReferenceSequence().isEmpty()) { // try to get the ref sequence from the Cigar unit refBase = unit.getReferenceSequence().substring(i, i + 1); } else { // try to get the ref sequence by fully parsing the MD tag if not already cached if (refSeq != null && refSeq.equals(UNINITIALIZED_REFERENCE_SEQUENCE)) { refSeq = com.google.cloud.genomics.utils.grpc.ReadUtils .inferReferenceSequenceByParsingMdFlag(read); } if (refSeq != null) { refBase = refSeq.substring(readOffset, readOffset + 1); } } String name = read.getAlignment().getPosition().getReferenceName(); Matcher m = Pattern.compile("^(chr)?(X|Y|([12]?\\d))$").matcher(name); if (m.matches()) { name = m.group(m.groupCount() - 1); } Position refPosition = Position.newBuilder().setReferenceName(name) .setPosition(read.getAlignment().getPosition().getPosition() + refPosAbsoluteOffset) .build(); bases.add(new ReadBaseWithReference( new ReadBaseQuality(readSeq.substring(readOffset, readOffset + 1), readQual.get(readOffset)), refBase, refPosition)); refPosAbsoluteOffset++; readOffset++; } break; case PAD: // padding (silent deletion from padded reference) case CLIP_HARD: // hard clipping (clipped sequences NOT present in seq) break; case CLIP_SOFT: // soft clipping (clipped sequences present in SEQ) case INSERT: // insertion to the reference readOffset += unit.getOperationLength(); break; case DELETE: // deletion from the reference case SKIP: // intron (mRNA-to-genome alignment only) refPosAbsoluteOffset += unit.getOperationLength(); break; default: throw new IllegalArgumentException("Illegal cigar code: " + unit.getOperation()); } } return bases.build(); }
From source file:de.flapdoodle.guava.Merger.java
public static <T> ImmutableList<T> remove(Iterable<? extends T> src, Predicate<? super T> matcher, Function<T, Optional<T>> transformation) { ImmutableList.Builder<T> builder = ImmutableList.builder(); for (T s : src) { if (matcher.apply(s)) { builder.addAll(transformation.apply(s).asSet()); } else {/*from w w w .j a v a 2 s . com*/ builder.add(s); } } return builder.build(); }
From source file:com.squareup.wire.schema.Reserved.java
static ImmutableList<Reserved> fromElements(ImmutableList<ReservedElement> reserveds) { ImmutableList.Builder<Reserved> builder = ImmutableList.builder(); for (ReservedElement reserved : reserveds) { builder.add(new Reserved(reserved.location(), reserved.documentation(), reserved.values())); }/*from ww w. ja v a 2s. c o m*/ return builder.build(); }