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

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

Introduction

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

Prototype

@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayListWithExpectedSize(int estimatedSize) 

Source Link

Document

Creates an ArrayList instance to hold estimatedSize elements, plus an unspecified amount of padding; you almost certainly mean to call #newArrayListWithCapacity (see that method for further advice on usage).

Usage

From source file:com.google.gxp.compiler.dot.DotWriter.java

public void recordNode(String nodeId, Map<String, String> properties) {
    List<String> names = Lists.newArrayListWithExpectedSize(properties.size());
    List<String> values = Lists.newArrayListWithExpectedSize(properties.size());
    for (Map.Entry<String, String> entry : properties.entrySet()) {
        names.add(dotEscape(entry.getKey()));
        values.add(dotEscape(entry.getValue()));
    }//from   w  ww. j  av a 2  s.  c o  m
    out.appendLine(String.format("node%s [label=\"{%s} | {%s}\",shape=Mrecord];", nodeId,
            Joiner.on(" | ").join(names), Joiner.on(" | ").join(values)));
}

From source file:com.google.gerrit.server.ssh.SshAddressesModule.java

@Provides
@Singleton/* w w w.j  a v  a2  s  .  c o m*/
@SshListenAddresses
List<SocketAddress> getListenAddresses(@GerritServerConfig Config cfg) {
    List<SocketAddress> listen = Lists.newArrayListWithExpectedSize(2);
    String[] want = cfg.getStringList("sshd", null, "listenaddress");
    if (want == null || want.length == 0) {
        listen.add(new InetSocketAddress(DEFAULT_PORT));
        return listen;
    }

    if (want.length == 1 && isOff(want[0])) {
        return listen;
    }

    for (final String desc : want) {
        try {
            listen.add(SocketUtil.resolve(desc, DEFAULT_PORT));
        } catch (IllegalArgumentException e) {
            log.error("Bad sshd.listenaddress: " + desc + ": " + e.getMessage());
        }
    }
    return listen;
}

From source file:net.sourceforge.ganttproject.document.DocumentsMRU.java

public DocumentsMRU(int maxSize) {
    assert maxSize > 0 : "maxSize must be larger than zero (" + maxSize + ")";
    this.maxSize = maxSize;
    documents = Lists.newArrayListWithExpectedSize(maxSize);
}

From source file:com.android.tools.idea.lint.AndroidLintTyposInspection.java

@NotNull
@Override/* ww  w . ja v  a2  s .c o  m*/
public AndroidLintQuickFix[] getQuickFixes(@NotNull String message) {
    TypoDetector.TypoSuggestionInfo info = TypoDetector.getSuggestions(message, RAW);
    final List<String> suggestions = info.getReplacements();
    if (!suggestions.isEmpty()) {
        List<AndroidLintQuickFix> fixes = Lists.newArrayListWithExpectedSize(suggestions.size());
        final String originalPattern = '(' + Pattern.quote(info.getOriginal()) + ')';
        for (String suggestion : suggestions) {
            fixes.add(new ReplaceStringQuickFix("Replace with \"" + suggestion + "\"", originalPattern,
                    suggestion));
        }
        return fixes.toArray(new AndroidLintQuickFix[fixes.size()]);
    }

    return AndroidLintQuickFix.EMPTY_ARRAY;
}

From source file:org.apache.impala.catalog.RolePrivilege.java

/**
 * Builds a privilege name for the given TPrivilege object. For simplicity, this name is
 * generated in a format that can be sent to the Sentry client to perform authorization
 * checks.//from w  w  w  .  j  a  va 2s  .  c  o  m
 */
public static String buildRolePrivilegeName(TPrivilege privilege) {
    List<String> authorizable = Lists.newArrayListWithExpectedSize(4);
    try {
        Preconditions.checkNotNull(privilege);
        TPrivilegeScope scope = privilege.getScope();
        Preconditions.checkNotNull(scope);
        switch (scope) {
        case SERVER: {
            authorizable.add(KV_JOINER.join("server", privilege.getServer_name()));
            break;
        }
        case URI: {
            authorizable.add(KV_JOINER.join("server", privilege.getServer_name()));
            authorizable.add(KV_JOINER.join("uri", privilege.getUri()));
            break;
        }
        case DATABASE: {
            authorizable.add(KV_JOINER.join("server", privilege.getServer_name()));
            authorizable.add(KV_JOINER.join("db", privilege.getDb_name()));
            break;
        }
        case TABLE: {
            authorizable.add(KV_JOINER.join("server", privilege.getServer_name()));
            authorizable.add(KV_JOINER.join("db", privilege.getDb_name()));
            authorizable.add(KV_JOINER.join("table", privilege.getTable_name()));
            break;
        }
        case COLUMN: {
            authorizable.add(KV_JOINER.join("server", privilege.getServer_name()));
            authorizable.add(KV_JOINER.join("db", privilege.getDb_name()));
            authorizable.add(KV_JOINER.join("table", privilege.getTable_name()));
            authorizable.add(KV_JOINER.join("column", privilege.getColumn_name()));
            break;
        }
        default: {
            throw new UnsupportedOperationException("Unknown privilege scope: " + scope.toString());
        }
        }

        // The ALL privilege is always implied and does not need to be included as part
        // of the name.
        if (privilege.getPrivilege_level() != TPrivilegeLevel.ALL) {
            authorizable.add(KV_JOINER.join("action", privilege.getPrivilege_level().toString()));
        }
        return AUTHORIZABLE_JOINER.join(authorizable);
    } catch (Exception e) {
        // Should never make it here unless the privilege is malformed.
        LOG.error("ERROR: ", e);
        return null;
    }
}

From source file:com.yahoo.yqlplus.engine.internal.plan.streams.RecordsBuiltinsModule.java

@Override
public OperatorNode<PhysicalExprOperator> callInRowContext(Location location, ContextPlanner context,
        String name, List<OperatorNode<ExpressionOperator>> arguments, OperatorNode<PhysicalExprOperator> row) {
    DynamicExpressionEvaluator eval = new DynamicExpressionEvaluator(context, row);
    if ("merge".equals(name)) {
        List<OperatorNode<PhysicalExprOperator>> args = eval.applyAll(arguments);
        List<OperatorNode<PhysicalProjectOperator>> ops = Lists.newArrayListWithExpectedSize(args.size());
        for (OperatorNode<PhysicalExprOperator> arg : args) {
            ops.add(OperatorNode.create(arg.getLocation(), PhysicalProjectOperator.MERGE, arg));
        }//from  ww  w  .j  a v a 2  s.com
        return OperatorNode.create(PhysicalExprOperator.PROJECT, ops);
    } else if ("map".equals(name)) {
        List<OperatorNode<PhysicalExprOperator>> args = eval.applyAll(arguments);
        List<OperatorNode<PhysicalProjectOperator>> ops = Lists.newArrayListWithExpectedSize(args.size());
        for (OperatorNode<PhysicalExprOperator> arg : args) {
            ops.add(OperatorNode.create(arg.getLocation(), PhysicalProjectOperator.MERGE, arg));
        }
        OperatorNode<PhysicalExprOperator> projectNode = OperatorNode.create(PhysicalExprOperator.PROJECT, ops);
        projectNode.putAnnotation("project:type", "map");
        return projectNode;
    }
    throw new ProgramCompileException(location, "Unknown records function '%s'", name);
}

From source file:io.pengyuc.jackson.versioning.Version.java

@JsonCreator
public static Version fromString(String versionStr) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(versionStr));
    Preconditions.checkArgument(!versionStr.startsWith("."), "Version string must not start with dot: {}",
            versionStr);/*w w  w .j a v  a  2s  .c  o  m*/

    List<String> subVersionStrs = Splitter.on(".").omitEmptyStrings().trimResults().splitToList(versionStr);
    List<Integer> subVersionNumbers = Lists.newArrayListWithExpectedSize(subVersionStrs.size());
    for (String subVersionStr : subVersionStrs) {
        Integer integer = Integer.valueOf(subVersionStr);
        if (integer < 0)
            throw new IllegalArgumentException("Input string value cannot be negative: " + subVersionStr);
        subVersionNumbers.add(integer);
    }
    if (subVersionNumbers.size() == 0) {
        throw new IllegalArgumentException("Cannot convert the version correctly: " + versionStr);
    }
    return new Version(subVersionNumbers);
}

From source file:org.carrot2.core.ClusterWithParent.java

/**
 * Private method that does the actual wrapping.
 *///from w  w w  .  ja  v a2 s  . com
private static ClusterWithParent wrap(ClusterWithParent parent, Cluster root) {
    final List<Cluster> actualSubclusters = root.getSubclusters();
    final List<ClusterWithParent> subclustersWithParent = Lists
            .newArrayListWithExpectedSize(actualSubclusters.size());

    final ClusterWithParent rootWithParent = new ClusterWithParent(parent, root,
            Collections.unmodifiableList(subclustersWithParent));

    for (Cluster actualCluster : actualSubclusters) {
        subclustersWithParent.add(wrap(rootWithParent, actualCluster));
    }

    return rootWithParent;
}

From source file:org.apache.druid.java.util.common.io.smoosh.SmooshedFileMapper.java

public static SmooshedFileMapper load(File baseDir) throws IOException {
    File metaFile = FileSmoosher.metaFile(baseDir);

    BufferedReader in = null;//from  w ww. j a  va  2  s . co  m
    try {
        in = new BufferedReader(new InputStreamReader(new FileInputStream(metaFile), StandardCharsets.UTF_8));

        String line = in.readLine();
        if (line == null) {
            throw new ISE("First line should be version,maxChunkSize,numChunks, got null.");
        }

        String[] splits = line.split(",");
        if (!"v1".equals(splits[0])) {
            throw new ISE("Unknown version[%s], v1 is all I know.", splits[0]);
        }
        if (splits.length != 3) {
            throw new ISE("Wrong number of splits[%d] in line[%s]", splits.length, line);
        }
        final Integer numFiles = Integer.valueOf(splits[2]);
        List<File> outFiles = Lists.newArrayListWithExpectedSize(numFiles);

        for (int i = 0; i < numFiles; ++i) {
            outFiles.add(FileSmoosher.makeChunkFile(baseDir, i));
        }

        Map<String, Metadata> internalFiles = Maps.newTreeMap();
        while ((line = in.readLine()) != null) {
            splits = line.split(",");

            if (splits.length != 4) {
                throw new ISE("Wrong number of splits[%d] in line[%s]", splits.length, line);
            }
            internalFiles.put(splits[0], new Metadata(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]),
                    Integer.parseInt(splits[3])));
        }

        return new SmooshedFileMapper(outFiles, internalFiles);
    } finally {
        Closeables.close(in, false);
    }
}

From source file:org.apache.flink.graph.examples.data.SummarizationData.java

/**
 * Creates a set of vertices with attached {@link String} values.
 *
 * @param env execution environment//  ww  w .  j  av  a  2  s . com
 * @return vertex data set with string values
 */
public static DataSet<Vertex<Long, String>> getVertices(ExecutionEnvironment env) {
    List<Vertex<Long, String>> vertices = Lists.newArrayListWithExpectedSize(6);
    vertices.add(new Vertex<>(0L, "A"));
    vertices.add(new Vertex<>(1L, "A"));
    vertices.add(new Vertex<>(2L, "B"));
    vertices.add(new Vertex<>(3L, "B"));
    vertices.add(new Vertex<>(4L, "B"));
    vertices.add(new Vertex<>(5L, "C"));

    return env.fromCollection(vertices);
}