Example usage for com.google.common.collect Lists newArrayListWithCapacity

List of usage examples for com.google.common.collect Lists newArrayListWithCapacity

Introduction

In this page you can find the example usage for com.google.common.collect Lists newArrayListWithCapacity.

Prototype

@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayListWithCapacity(int initialArraySize) 

Source Link

Document

Creates an ArrayList instance backed by an array with the specified initial size; simply delegates to ArrayList#ArrayList(int) .

Usage

From source file:cosmos.sql.call.Fields.java

public Fields(List<String> literal) {
    fields = Lists.newArrayListWithCapacity(literal.size());

    for (String field : literal) {
        addChild(literal.toString(), new Field(field));
    }//from   w  ww . jav a2  s . c  o  m
}

From source file:blue.lapis.pore.util.PoreCollections.java

public static <F, T> List<T> transformToList(Collection<F> from, Function<? super F, ? extends T> function) {
    // If we have a list already we can transform it directly
    if (from instanceof List) {
        return Lists.transform((List<F>) from, function);
    }//from  w w  w.j a  v a  2s  .  c  o  m

    // There is no other good way than copying everything, meh
    List<T> result = Lists.newArrayListWithCapacity(from.size());
    for (F element : from) {
        result.add(function.apply(element));
    }
    return result;
}

From source file:com.github.steveash.jg2p.util.Zipper.java

public static <A, B> List<Pair<A, B>> replaceRight(List<Pair<A, B>> original, Iterable<B> newRight) {
    ArrayList<Pair<A, B>> result = Lists.newArrayListWithCapacity(original.size());
    Iterator<B> iter = newRight.iterator();
    for (Pair<A, B> pair : original) {
        Preconditions.checkArgument(iter.hasNext(), "newRight is smaller than original");
        result.add(Pair.of(pair.getLeft(), iter.next()));
    }/*from  w ww  . j a  va2s. c o m*/
    Preconditions.checkArgument(!iter.hasNext(), "newRight is bigger than original");
    return result;
}

From source file:org.terasology.polyworld.sampling.NaivePointSampling.java

@Override
public List<Vector2f> create(Rect2f bounds, int numSites, Random rng) {
    List<Vector2f> points = Lists.newArrayListWithCapacity(numSites);
    for (int i = 0; i < numSites; i++) {
        float px = bounds.minX() + rng.nextFloat() * bounds.width();
        float py = bounds.minY() + rng.nextFloat() * bounds.height();
        points.add(new Vector2f(px, py));
    }//  w ww . j  a v  a  2s .  c o  m
    return points;
}

From source file:org.terasology.classMetadata.copying.strategy.ListCopyStrategy.java

@Override
public List<T> copy(List<T> value) {
    if (value != null) {
        List<T> result = Lists.newArrayListWithCapacity(value.size());
        for (T item : value) {
            result.add(contentStrategy.copy(item));
        }//from  ww w. ja  va 2 s.co m
        return result;
    }
    return null;
}

From source file:org.gradle.plugin.use.internal.PluginRequestsSerializer.java

@Override
public PluginRequests read(Decoder decoder) throws Exception {
    int requestCount = decoder.readInt();
    List<PluginRequest> requests = Lists.newArrayListWithCapacity(requestCount);
    for (int i = 0; i < requestCount; i++) {
        PluginId pluginId = PluginId.unvalidated(decoder.readString());
        String version = decoder.readNullableString();
        int lineNumber = decoder.readInt();
        String scriptDisplayName = decoder.readString();

        requests.add(i, new DefaultPluginRequest(pluginId, version, lineNumber, scriptDisplayName));
    }//from w w  w  . j  ava  2  s .  c o m
    return new DefaultPluginRequests(requests);
}

From source file:additionalpipes.inventory.components.PropertyList.java

@Override
public void readData(DataInputStream data) throws IOException {
    byte id = data.readByte();
    int size = data.readInt();
    value = Lists.newArrayListWithCapacity(size);
    for (int i = 0; i < size; i++) {
        Property prop;/*from w  w w .  j  ava  2 s.com*/
        try {
            prop = newProp(id);
        } catch (ReflectiveOperationException e) {
            throw new IOException(e);
        }
        prop.readData(data);
        value.add(prop);
    }
}

From source file:com.opengamma.web.analytics.formatting.ValuePropertiesFormatter.java

ValuePropertiesFormatter() {
    super(ValueProperties.class);
    addFormatter(new Formatter<ValueProperties>(Format.EXPANDED) {
        @Override//from w ww  .  j  av  a  2s .  c  o  m
        Map<String, Object> format(ValueProperties properties, ValueSpecification valueSpec, Object inlineKey) {
            Set<String> names = properties.getProperties();
            List<List<String>> matrix = Lists.newArrayListWithCapacity(names.size());
            List<String> yLabels = Lists.newArrayListWithCapacity(names.size());
            for (String name : names) {
                Set<String> values = properties.getValues(name);
                boolean optional = properties.isOptional(name);
                List<String> row = Lists.newArrayListWithCapacity(2);
                row.add(StringUtils.join(values, ", "));
                row.add(optional ? "true" : "false");
                matrix.add(row);
                yLabels.add(name);
            }
            Map<String, Object> output = Maps.newHashMap();
            output.put(LabelledMatrix2DFormatter.MATRIX, matrix);
            // TODO it would be good if the UI could handle a label for the first column: "Property"
            output.put(LabelledMatrix2DFormatter.X_LABELS, Lists.newArrayList("Property", "Value", "Optional"));
            output.put(LabelledMatrix2DFormatter.Y_LABELS, yLabels);
            return output;
        }
    });
}

From source file:net.sourceforge.cilib.util.Sequence.java

/**
 * Generate a range of numbers starting at {@code from} and continuing
 * to {@code to} (inclusive).//from w  w w  .j  a v  a2s. c o  m
 * @param from starting point
 * @param to end point
 * @return {@code Sequence} representing the defined range.
 */
public static Iterable<Number> finiteRange(final int from, final int to) {
    List<Number> range = Lists.newArrayListWithCapacity(to - from);
    for (int i = from; i <= to; i++) {
        range.add(i);
    }
    return new FiniteSequence(Sequence.copyOf(range), range.size());
}

From source file:org.terasology.rendering.nui.layers.mainMenu.savedGames.GameProvider.java

public static List<GameInfo> getSavedGames() {
    Path savedGames = PathManager.getInstance().getSavesPath();
    SortedMap<FileTime, Path> savedGamePaths = Maps.newTreeMap(Collections.reverseOrder());
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(savedGames)) {
        for (Path entry : stream) {
            if (Files.isRegularFile(entry.resolve(GameManifest.DEFAULT_FILE_NAME))) {
                savedGamePaths.put(Files.getLastModifiedTime(entry.resolve(GameManifest.DEFAULT_FILE_NAME)),
                        entry);//from  w  w w  .  j av  a  2 s.c  om
            }
        }
    } catch (IOException e) {
        logger.error("Failed to read saved games path", e);
    }

    List<GameInfo> result = Lists.newArrayListWithCapacity(savedGamePaths.size());

    for (Map.Entry<FileTime, Path> world : savedGamePaths.entrySet()) {
        Path gameManifest = world.getValue().resolve(GameManifest.DEFAULT_FILE_NAME);

        if (!Files.isRegularFile(gameManifest)) {
            continue;
        }
        try {
            GameManifest info = GameManifest.load(gameManifest);
            if (!info.getTitle().isEmpty()) {
                Date date = new Date(world.getKey().toMillis());
                result.add(new GameInfo(info, date));
            }
        } catch (IOException e) {
            logger.error("Failed reading world data object.", e);
        }
    }
    return result;
}