List of usage examples for java.util Vector.Builder add
public synchronized boolean add(E e)
From source file:org.briljantframework.data.vector.Vector.java
/** * Creates a vector of the values in the iterable * * @param values the specified values// ww w.j ava2s . co m * @return a new vector with the specified values */ static <T> Vector fromIterable(Class<T> cls, Iterable<T> values) { Iterator<T> it = values.iterator(); if (!it.hasNext()) { return singleton(null); } Vector.Builder builder = new GenericVector.Builder(cls); while (it.hasNext()) { builder.add(it.next()); } return builder.build(); }
From source file:org.briljantframework.data.vector.Vector.java
/** * Creates a vector with the specified size consisting of the values given by the supplier * * <pre>// www .j a v a 2s .c om * { * @code * Vector.Builder b; * for (int i = 0; i < size; i++) { * b.plus(supplier.get()); * } * } * </pre> */ static Vector fromSupplier(Supplier<Object> supplier, int size) { if (size < 1) { throw new UnsupportedOperationException(); } Object value = supplier.get(); Vector.Builder builder = VectorType.of(value).newBuilder().add(value); for (int i = 1; i < size; i++) { builder.add(supplier.get()); } return builder.build(); }
From source file:org.briljantframework.data.vector.Vectors.java
public static Vector range(int size) { Vector.Builder builder = Vector.Builder.of(Integer.class); for (int i = 0; i < size; i++) { builder.add(i); }/*from w w w .j a v a 2s . c o m*/ return builder.build(); }
From source file:org.renjin.primitives.Types.java
@Generic @Primitive("as.vector") public static SEXP asVector(PairList x, String mode) { Vector.Builder result; NamesBuilder names = NamesBuilder.withInitialCapacity(x.length()); if ("character".equals(mode)) { result = new StringVector.Builder(); } else if ("logical".equals(mode)) { result = new LogicalArrayVector.Builder(x.length()); } else if ("numeric".equals(mode)) { result = new DoubleArrayVector.Builder(x.length()); } else if ("list".equals(mode)) { result = new ListVector.Builder(); } else if ("raw".equals(mode)) { result = new RawVector.Builder(); } else {/*from w ww.j av a 2s. c o m*/ throw new EvalException("invalid 'mode' argument"); } for (PairList.Node node : x.nodes()) { if (node.hasTag()) { names.add(node.getTag().getPrintName()); } else { names.addNA(); } result.add(node.getValue()); } result.setAttribute(Symbols.NAMES.getPrintName(), names.build(result.length())); return result.build(); }
From source file:r.base.Types.java
@Generic @Primitive("as.vector") public static SEXP asVector(PairList x, String mode) { Vector.Builder result; NamesBuilder names = NamesBuilder.withInitialCapacity(x.length()); if ("character".equals(mode)) { result = new StringVector.Builder(); } else if ("logical".equals(mode)) { result = new LogicalVector.Builder(x.length()); } else if ("numeric".equals(mode)) { result = new DoubleVector.Builder(x.length()); } else if ("list".equals(mode)) { result = new ListVector.Builder(); } else if ("raw".equals(mode)) { result = new RawVector.Builder(); } else {/* ww w . ja v a 2 s.c o m*/ throw new EvalException("invalid 'mode' argument"); } for (PairList.Node node : x.nodes()) { if (node.hasTag()) { names.add(node.getTag().getPrintName()); } else { names.addNA(); } result.add(node.getValue()); } result.setAttribute(Symbols.NAMES.getPrintName(), names.build(result.length())); return result.build(); }