List of usage examples for com.google.common.collect Lists newArrayListWithCapacity
@GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayListWithCapacity(int initialArraySize)
From source file:com.torodb.torod.db.backends.query.processors.ExistsProcessor.java
public static List<ProcessedQueryCriteria> process(ExistsQueryCriteria criteria, QueryCriteriaVisitor<List<ProcessedQueryCriteria>, Void> visitor, ExistRelation existRelation) { List<ProcessedQueryCriteria> childResult = callChild(criteria, visitor); List<ProcessedQueryCriteria> result = Lists.newArrayListWithCapacity(childResult.size()); for (ProcessedQueryCriteria childProcessedQueryCriteria : childResult) { result.add(processSingleResult(criteria, childProcessedQueryCriteria, existRelation)); }/*w w w. ja va 2 s .co m*/ return result; }
From source file:fr.univnantes.lina.uima.tkregex.AutomatonFactory.java
public static Automaton createNAutomaton(Automaton automaton, int n) { List<Automaton> clones = Lists.newArrayListWithCapacity(n); for (int i = 0; i < n; i++) clones.add(automaton.deepClone()); return createConcatenation(clones); }
From source file:org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.SimpleBinaryAttributeReadingStrategy.java
@Override protected Object postprocessParsedValue(String textContent) { BaseEncoding en = BaseEncoding.base64(); byte[] decode = en.decode(textContent); List<String> parsed = Lists.newArrayListWithCapacity(decode.length); for (byte b : decode) { parsed.add(Byte.toString(b)); }/*w ww.j av a 2s .co m*/ return parsed; }
From source file:org.jiemamy.eclipse.core.ui.utils.KeyConstraintUtil.java
/** * ???????//from ww w . j a v a 2 s .c o m * * @param context * @param keyConstraint ? * @return ???? * @throws IllegalArgumentException ?{@code null}??? */ public static String toStringKeyColumns(JiemamyContext context, JmKeyConstraint keyConstraint) { Validate.notNull(context); Validate.notNull(keyConstraint); List<EntityRef<? extends JmColumn>> keyColumns = keyConstraint.getKeyColumns(); List<String> columnNames = Lists.newArrayListWithCapacity(keyColumns.size()); for (EntityRef<? extends JmColumn> columnRef : keyColumns) { try { JmColumn col = context.resolve(columnRef); columnNames.add(col.getName()); } catch (EntityNotFoundException e) { // FIXME table?add???????tablestore???????? // context?columnresolve?????????????? columnNames.add("<NewColumn>"); } } return Joiner.on(", ").join(columnNames); }
From source file:com.j2swift.ast.TreeUtil.java
public static <T extends TreeNode> List<T> copyList(List<T> originalList) { List<T> newList = Lists.newArrayListWithCapacity(originalList.size()); copyList(originalList, newList);/* w w w . j a v a2 s .c o m*/ return newList; }
From source file:org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.SimpleUnionAttributeReadingStrategy.java
@Override protected Object postprocessParsedValue(String textContent) { char[] charArray = textContent.toCharArray(); List<String> chars = Lists.newArrayListWithCapacity(charArray.length); for (char c : charArray) { chars.add(Character.toString(c)); }//from w w w. j a va2 s . co m Map<String, Object> map = Maps.newHashMap(); map.put(key, chars); return map; }
From source file:co.cask.cdap.etl.common.PipelineTypeValidator.java
/** * Takes in an unresolved type list and resolves the types and verifies if the types are assignable. * Ex: An unresolved type could be : String, T, List<T>, List<String> * The above will resolve to : String, String, List<String>, List<String> * And the assignability will be checked : String --> String && List<String> --> List<String> * which is true in the case above.// w ww.ja v a 2 s . c om */ @VisibleForTesting static void validateTypes(List<Type> unresTypeList) { Preconditions.checkArgument(unresTypeList.size() % 2 == 0, "ETL Stages validation expects even number of types"); List<Type> resTypeList = Lists.newArrayListWithCapacity(unresTypeList.size()); // Add the source output to resolved type list as the first resolved type. resTypeList.add(unresTypeList.get(0)); try { // Resolve the second type using just the first resolved type. Type nType = (new TypeResolver()).where(unresTypeList.get(1), resTypeList.get(0)) .resolveType(unresTypeList.get(1)); resTypeList.add(nType); } catch (IllegalArgumentException e) { // If unable to resolve type, add the second type as is, to the resolved list. resTypeList.add(unresTypeList.get(1)); } for (int i = 2; i < unresTypeList.size(); i++) { // ActualType is previous resolved type; FormalType is previous unresolved type; // ToResolveType is current unresolved type; // Ex: Actual = String; Formal = T; ToResolve = List<T>; ==> newType = List<String> Type actualType = resTypeList.get(i - 1); Type formalType = unresTypeList.get(i - 1); Type toResolveType = unresTypeList.get(i); try { Type newType; // If the toResolveType is a TypeVariable or a Generic Array, then try to resolve // using just the previous resolved type. // Ex: Actual = List<String> ; Formal = List<T> ; ToResolve = T ==> newType = String which is not correct; // newType should be List<String>. Hence resolve only from the previous resolved type (Actual) if ((toResolveType instanceof TypeVariable) || (toResolveType instanceof GenericArrayType)) { newType = (new TypeResolver()).where(toResolveType, actualType).resolveType(toResolveType); } else { newType = (new TypeResolver()).where(formalType, actualType).resolveType(toResolveType); } resTypeList.add(newType); } catch (IllegalArgumentException e) { // If resolution failed, add the type as is to the resolved list. resTypeList.add(toResolveType); } } // Check isAssignable on the resolved list for every paired elements. 0 --> 1 | 2 --> 3 | 4 --> 5 where | is a // transform (which takes in type on its left and emits the type on its right). for (int i = 0; i < resTypeList.size(); i += 2) { Type firstType = resTypeList.get(i); Type secondType = resTypeList.get(i + 1); // Check if secondType can accept firstType Preconditions.checkArgument(TypeToken.of(secondType).isAssignableFrom(firstType), "Types between stages didn't match. Mismatch between {} -> {}", firstType, secondType); } }
From source file:com.cloudera.oryx.common.settings.InboundSettings.java
public static InboundSettings create(Config config) { Config inbound = config.getConfig("inbound"); List<String> columnNames; if (inbound.hasPath("column-names")) { columnNames = inbound.getStringList("column-names"); } else {/*from ww w.ja v a 2 s. co m*/ int numColumns = inbound.getInt("num-columns"); columnNames = Lists.newArrayListWithCapacity(numColumns); for (int i = 0; i < numColumns; i++) { columnNames.add(String.valueOf(i)); } } Function<Object, Integer> lookup = new LookupFunction(columnNames); Iterable<Integer> allColumns = Collections2.transform(columnNames, lookup); Collection<Integer> idColumns; if (inbound.hasPath("id-columns")) { idColumns = ImmutableSet.copyOf(Collections2.transform(inbound.getAnyRefList("id-columns"), lookup)); } else { idColumns = ImmutableSet.of(); } Collection<Integer> ignoredColumns; if (inbound.hasPath("ignored-columns")) { ignoredColumns = ImmutableSet .copyOf(Collections2.transform(inbound.getAnyRefList("ignored-columns"), lookup)); } else { ignoredColumns = ImmutableSet.of(); } Collection<Integer> categoricalColumns; Collection<Integer> numericColumns; if (inbound.hasPath("categorical-columns")) { Preconditions.checkState(!inbound.hasPath("numeric-columns")); categoricalColumns = Sets .newHashSet(Collections2.transform(inbound.getAnyRefList("categorical-columns"), lookup)); numericColumns = Sets.newHashSet(allColumns); numericColumns.removeAll(categoricalColumns); } else if (inbound.hasPath("numeric-columns")) { Preconditions.checkState(!inbound.hasPath("categorical-columns")); numericColumns = Sets .newHashSet(Collections2.transform(inbound.getAnyRefList("numeric-columns"), lookup)); categoricalColumns = Sets.newHashSet(allColumns); categoricalColumns.removeAll(numericColumns); } else { throw new IllegalArgumentException("No categorical-columns or numeric-columns set"); } numericColumns.removeAll(idColumns); numericColumns.removeAll(ignoredColumns); categoricalColumns.removeAll(idColumns); categoricalColumns.removeAll(ignoredColumns); Integer targetColumn = null; if (inbound.hasPath("target-column")) { targetColumn = lookup.apply(inbound.getAnyRef("target-column")); Preconditions.checkState( categoricalColumns.contains(targetColumn) || numericColumns.contains(targetColumn), "Target column not specified as numeric or categorical"); } return new InboundSettings(columnNames, idColumns, categoricalColumns, numericColumns, ignoredColumns, targetColumn); }
From source file:org.geogit.rest.repository.RepositoryListResource.java
@Override protected List<DataFormat> createSupportedFormats(Request request, Response response) { List<DataFormat> formats = Lists.newArrayListWithCapacity(3); formats.add(new FreemarkerFormat(RepositoryListResource.class.getSimpleName() + ".ftl", getClass(), MediaType.TEXT_HTML)); return formats; }
From source file:com.facebook.buck.util.MoreIterables.java
/** * Combine the given iterables by peeling off items one at a time from each of the input * iterables until any one of the iterables are exhausted. *///from ww w. jav a 2 s. c om @SafeVarargs public static <T> Iterable<T> zipAndConcat(Iterable<T>... inputs) { // If no inputs were seen, just return an empty list. if (inputs.length == 0) { return ImmutableList.of(); } ImmutableList.Builder<T> result = ImmutableList.builder(); ImmutableList<Iterator<T>> iterators = iterators(inputs); // Keep grabbing rounds from the input iterators until we've exhausted one // of them, then return. List<T> round = Lists.newArrayListWithCapacity(inputs.length); while (true) { for (Iterator<T> iterator : iterators) { if (!iterator.hasNext()) { return result.build(); } round.add(iterator.next()); } result.addAll(round); round.clear(); } }