Example usage for com.google.common.collect Maps newHashMapWithExpectedSize

List of usage examples for com.google.common.collect Maps newHashMapWithExpectedSize

Introduction

In this page you can find the example usage for com.google.common.collect Maps newHashMapWithExpectedSize.

Prototype

public static <K, V> HashMap<K, V> newHashMapWithExpectedSize(int expectedSize) 

Source Link

Document

Creates a HashMap instance, with a high enough "initial capacity" that it should hold expectedSize elements without growth.

Usage

From source file:com.google.gitiles.BlobSoyData.java

public Map<String, Object> toSoyData(String path, ObjectId blobId) throws MissingObjectException, IOException {
    Map<String, Object> data = Maps.newHashMapWithExpectedSize(4);
    data.put("sha", ObjectId.toString(blobId));

    ObjectLoader loader = walk.getObjectReader().open(blobId, Constants.OBJ_BLOB);
    String content;/* w w  w  .java2 s.com*/
    try {
        byte[] raw = loader.getCachedBytes(MAX_FILE_SIZE);
        content = !RawText.isBinary(raw) ? RawParseUtils.decode(raw) : null;
    } catch (LargeObjectException.OutOfMemory e) {
        throw e;
    } catch (LargeObjectException e) {
        content = null;
    }

    data.put("data", content);
    if (content != null) {
        data.put("lang", guessPrettifyLang(path, content));
    } else if (content == null) {
        data.put("size", Long.toString(loader.getSize()));
    }
    if (path != null && view.getRevision().getPeeledType() == OBJ_COMMIT) {
        data.put("logUrl", GitilesView.log().copyFrom(view).toUrl());
    }
    return data;
}

From source file:org.apache.phoenix.parse.IndexExpressionParseNodeRewriter.java

public IndexExpressionParseNodeRewriter(PTable index, PhoenixConnection connection,
        Map<String, UDFParseNode> udfParseNodes) throws SQLException {
    indexedParseNodeToColumnParseNodeMap = Maps.newHashMapWithExpectedSize(index.getColumns().size());
    NamedTableNode tableNode = NamedTableNode.create(null,
            TableName.create(index.getParentSchemaName().getString(), index.getParentTableName().getString()),
            Collections.<ColumnDef>emptyList());
    ColumnResolver dataResolver = FromCompiler.getResolver(tableNode, connection, udfParseNodes);
    StatementContext context = new StatementContext(new PhoenixStatement(connection), dataResolver);
    IndexStatementRewriter rewriter = new IndexStatementRewriter(dataResolver, null);
    ExpressionCompiler expressionCompiler = new ExpressionCompiler(context);
    int indexPosOffset = (index.getBucketNum() == null ? 0 : 1) + (index.isMultiTenant() ? 1 : 0)
            + (index.getViewIndexId() == null ? 0 : 1);
    List<PColumn> pkColumns = index.getPKColumns();
    for (int i = indexPosOffset; i < pkColumns.size(); ++i) {
        PColumn column = pkColumns.get(i);
        String expressionStr = IndexUtil.getIndexColumnExpressionStr(column);
        ParseNode expressionParseNode = SQLParser.parseCondition(expressionStr);
        String colName = "\"" + column.getName().getString() + "\"";
        Expression dataExpression = expressionParseNode.accept(expressionCompiler);
        PDataType expressionDataType = dataExpression.getDataType();
        ParseNode indexedParseNode = expressionParseNode.accept(rewriter);
        PDataType indexColType = IndexUtil.getIndexColumnDataType(dataExpression.isNullable(),
                expressionDataType);/*from w ww.  j  a va2s. c  o  m*/
        ParseNode columnParseNode = new ColumnParseNode(null, colName, null);
        if (indexColType != expressionDataType) {
            columnParseNode = NODE_FACTORY.cast(columnParseNode, expressionDataType, null, null);
        }
        indexedParseNodeToColumnParseNodeMap.put(indexedParseNode, columnParseNode);
    }
}

From source file:org.sosy_lab.cpachecker.cpa.automaton.Automaton.java

public Automaton(String pName, Map<String, AutomatonVariable> pVars, List<AutomatonInternalState> pStates,
        String pInitialStateName) throws InvalidAutomatonException {
    this.name = pName;
    this.initVars = pVars;
    this.states = pStates;

    Map<String, AutomatonInternalState> statesMap = Maps.newHashMapWithExpectedSize(pStates.size());
    for (AutomatonInternalState s : pStates) {
        if (statesMap.put(s.getName(), s) != null) {
            throw new InvalidAutomatonException("State " + s.getName() + " exists twice in automaton " + pName);
        }/*from w  w w  .  j ava 2 s.  co  m*/
    }

    initState = statesMap.get(pInitialStateName);
    if (initState == null) {
        throw new InvalidAutomatonException(
                "Inital state " + pInitialStateName + " not found in automaton " + pName);
    }

    // set the FollowStates of all Transitions
    for (AutomatonInternalState s : pStates) {
        s.setFollowStates(statesMap);
    }
}

From source file:tachyon.master.file.journal.AddCheckpointEntry.java

@Override
public Map<String, Object> getParameters() {
    Map<String, Object> parameters = Maps.newHashMapWithExpectedSize(5);
    parameters.put("workerId", mWorkerId);
    parameters.put("fileId", mFileId);
    parameters.put("length", mLength);
    parameters.put("checkpointPath", mCheckpointPath);
    parameters.put("operationTimeMs", mOpTimeMs);
    return parameters;
}

From source file:org.openqa.selenium.remote.server.handler.internal.ResultConverter.java

public Object apply(Object result) {
    if (result instanceof WebElement) {
        String elementId = knownElements.add((WebElement) result);
        return ImmutableMap.of("ELEMENT", elementId);
    }/*ww w.  j a  v a 2  s .  c o  m*/

    if (result instanceof List) {
        @SuppressWarnings("unchecked")
        List<Object> resultAsList = (List<Object>) result;
        return Lists.newArrayList(Iterables.transform(resultAsList, this));
    }

    if (result instanceof Map<?, ?>) {
        Map<?, ?> resultAsMap = (Map<?, ?>) result;
        Map<Object, Object> converted = Maps.newHashMapWithExpectedSize(resultAsMap.size());
        for (Map.Entry<?, ?> entry : resultAsMap.entrySet()) {
            converted.put(entry.getKey(), apply(entry.getValue()));
        }
        return converted;
    }

    return result;
}

From source file:org.opensocial.explorer.server.security.OSEAuthConfigContributor.java

@Override
public void contribute(Map<String, Object> config, String container, String host) {
    // FIXME: Shindig doesn't like feeding AnonymousSecurityTokens to the
    // BlobCrypterSecurityTokenCodec, so I fake it out by setting the authentication mode to
    // something other than UNAUTHENTICATED. Shindig needs to be fixed to remove the tight coupling
    // between codecs and token implementations.
    SecurityToken containerToken = new ContainerAnonymousSecurityToken(container, 0L, "*");

    Map<String, String> authConfig = Maps.newHashMapWithExpectedSize(2);
    try {//w ww . j a v a 2s. c  o  m
        config.put("shindig.auth", authConfig);
        authConfig.put("authToken", securityTokenCodec.encodeToken(containerToken));
    } catch (SecurityTokenException e) {
        // CONSIDER: Ignore?
    }
}

From source file:org.n52.sos.util.Activatable.java

public static <K, V> Map<K, V> filter(Map<K, Activatable<V>> map) {
    if (map == null) {
        return Maps.newHashMap();
    }//w  w w .ja  va2  s.  c o  m
    Map<K, V> filtered = Maps.newHashMapWithExpectedSize(map.size());
    for (K k : map.keySet()) {
        if (map.get(k) != null && map.get(k).get() != null) {
            filtered.put(k, map.get(k).get());
        }
    }
    return filtered;
}

From source file:com.google.devtools.depan.view_doc.layout.grid.GridLayoutRunner.java

@Override
public void layoutStep() {
    Collection<GraphNode> layoutNodes = context.getMovableNodes();
    positions = Maps.newHashMapWithExpectedSize(layoutNodes.size());
    double leftPos = -horizontalSpace * ((columns / 2.0) - 0.5);
    double topPos = verticalSpace * ((rows / 2.0) - 0.5);

    double xCurr = leftPos;
    double yCurr = topPos;
    int item = (int) columns;
    for (GraphNode node : layoutNodes) {
        positions.put(node, new Point2D.Double(xCurr, yCurr));
        item--;// w w  w  .java2 s.  c  o m
        if (item > 0) {
            xCurr += horizontalSpace;
        } else {
            item = (int) columns;
            xCurr = leftPos;
            yCurr -= verticalSpace;
        }
    }
}

From source file:com.amazon.janusgraph.diskstorage.dynamodb.builder.SingleExpectedAttributeValueBuilder.java

public Map<String, ExpectedAttributeValue> build(KCVMutation mutation) {
    Preconditions.checkState(txh != null, "Transaction must not be null");
    Preconditions.checkState(key != null, "Key must not be null");

    final Map<String, ExpectedAttributeValue> expected = Maps
            .newHashMapWithExpectedSize(mutation.getTotalMutations());

    for (Entry addedColumn : mutation.getAdditions()) {
        final StaticBuffer columnKey = addedColumn.getColumn();
        addExpectedValueIfPresent(key, columnKey, expected);
    }//from w  w w .j  a  v  a 2s . com

    for (StaticBuffer deletedKey : mutation.getDeletions()) {
        addExpectedValueIfPresent(key, deletedKey, expected);
    }

    return expected;
}

From source file:fr.xebia.cocktail.AmazonS3FileStorageService.java

@Inject
public AmazonS3FileStorageService(@Value("${aws_access_key}") String awsAccessKey,
        @Value("${aws_secret_key}") String awsSecretKey) {

    amazonS3 = new AmazonS3Client(new BasicAWSCredentials(awsAccessKey, awsSecretKey));

    contentTypeByFileExtension = Maps.newHashMapWithExpectedSize(4);
    contentTypeByFileExtension.put("jpg", "image/jpeg");
    contentTypeByFileExtension.put("jpeg", "image/jpeg");
    contentTypeByFileExtension.put("png", "image/png");
    contentTypeByFileExtension.put("gif", "image/gif");

    defaultFileExtensionByContentType = Maps.newHashMapWithExpectedSize(3);
    defaultFileExtensionByContentType.put("image/jpeg", "jpg");
    defaultFileExtensionByContentType.put("image/png", "png");
    defaultFileExtensionByContentType.put("image/gif", "gif");
}