Example usage for com.google.common.collect ImmutableList size

List of usage examples for com.google.common.collect ImmutableList size

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableList size.

Prototype

int size();

Source Link

Document

Returns the number of elements in this list.

Usage

From source file:org.apache.hadoop.hive.ql.optimizer.calcite.cost.HiveAlgorithmsUtil.java

public static double computeMapJoinCPUCost(ImmutableList<Double> cardinalities, ImmutableBitSet streaming) {
    // Hash-join/*from w w w.  j  a  va2s  .c  o m*/
    double cpuCost = 0.0;
    for (int i = 0; i < cardinalities.size(); i++) {
        double cardinality = cardinalities.get(i);
        if (!streaming.get(i)) {
            cpuCost += cardinality;
        }
        cpuCost += cardinality * cpuCost;
    }
    return cpuCost;
}

From source file:com.google.jimfs.AttributeService.java

private static String getSingleAttribute(String attribute) {
    ImmutableList<String> attributeNames = getAttributeNames(attribute);

    if (attributeNames.size() != 1 || ALL_ATTRIBUTES.equals(attributeNames.get(0))) {
        throw new IllegalArgumentException("must specify a single attribute: " + attribute);
    }//from  ww  w.  ja va2s. c o m

    return attributeNames.get(0);
}

From source file:com.google.devtools.build.lib.skyframe.serialization.ObjectCodecRegistry.java

private static IdentityHashMap<String, Supplier<CodecDescriptor>> createDynamicCodecs(
        ImmutableList<String> classNames, int nextTag) {
    IdentityHashMap<String, Supplier<CodecDescriptor>> dynamicCodecs = new IdentityHashMap<>(classNames.size());
    for (String className : classNames) {
        int tag = nextTag++;
        dynamicCodecs.put(className, Suppliers.memoize(() -> createDynamicCodecDescriptor(tag, className)));
    }/*from   w  ww .j a  v  a 2s  .c  o  m*/
    return dynamicCodecs;
}

From source file:com.spectralogic.ds3autogen.c.helpers.StructHelper.java

public static String generateResponseAttributesParser(final String structName,
        final ImmutableList<StructMember> structMembers) throws ParseException {
    boolean firstElement = true;
    final StringBuilder outputBuilder = new StringBuilder();

    for (int structMemberIndex = 0; structMemberIndex < structMembers.size(); structMemberIndex++) {
        final StructMember currentStructMember = structMembers.get(structMemberIndex);
        if (!currentStructMember.isAttribute())
            continue; // only parsing attributes for a specific node

        outputBuilder.append(indent(2));

        if (!firstElement) {
            outputBuilder.append("} else ");
        } else {//from   w w w. jav  a  2s.c  o  m
            firstElement = false;
        }

        outputBuilder.append("if (attribute_equal(attribute, \"")
                .append(Helper.capFirst(currentStructMember.getNameToMarshall())).append("\") == true) {")
                .append("\n");
        outputBuilder.append(StructMemberHelper.getParseStructMemberAttributeBlock(currentStructMember));
    }

    outputBuilder.append(indent(2)).append("} else {").append("\n");
    outputBuilder.append(indent(3)).append("ds3_log_message(client->log, DS3_ERROR, \"Unknown attribute[%s] of "
            + structName + " [%s]\\n\", attribute->name, root->name);").append("\n");
    outputBuilder.append(indent(2)).append("}").append("\n");
    outputBuilder.append("\n");
    outputBuilder.append(indent(2)).append("if (error != NULL) {\n");
    outputBuilder.append(indent(3)).append("break;\n");
    outputBuilder.append(indent(2)).append("}\n");

    return outputBuilder.toString();
}

From source file:org.glowroot.agent.embedded.repo.GaugeValueDao.java

private static AtomicLongArray initData(ImmutableList<RollupConfig> rollupConfigs, DataSource dataSource)
        throws Exception {
    List<String> columnNames = Lists.newArrayList();
    for (int i = 1; i <= rollupConfigs.size(); i++) {
        columnNames.add("last_rollup_" + i + "_time");
    }// w w  w.j  a v a2s  . c  o  m
    Joiner joiner = Joiner.on(", ");
    String selectClause = castUntainted(joiner.join(columnNames));
    long[] lastRollupTimes = dataSource.query(new LastRollupTimesQuery(selectClause));
    if (lastRollupTimes.length == 0) {
        long[] values = new long[rollupConfigs.size()];
        String valueClause = castUntainted(joiner.join(Longs.asList(values)));
        dataSource.update("insert into gauge_value_last_rollup_times (" + selectClause + ") values ("
                + valueClause + ")");
        return new AtomicLongArray(values);
    } else {
        return new AtomicLongArray(lastRollupTimes);
    }
}

From source file:com.spectralogic.ds3autogen.c.helpers.StructHelper.java

public static String generateResponseParser(final String structName,
        final ImmutableList<StructMember> structMembers) throws ParseException {
    boolean firstElement = true;
    final StringBuilder outputBuilder = new StringBuilder();

    for (int structMemberIndex = 0; structMemberIndex < structMembers.size(); structMemberIndex++) {
        final StructMember currentStructMember = structMembers.get(structMemberIndex);
        if (currentStructMember.isAttribute())
            continue; // only parsing child nodes for a specific node
        if (currentStructMember.getName().startsWith("num_"))
            continue; // skip - these are used for array iteration and are not a part of the response
        if (currentStructMember.getName().equals("paging"))
            continue; // skip - parsed from pagination headers

        outputBuilder.append(indent(2));

        if (!firstElement) {
            outputBuilder.append("} else ");
        } else {/*  w w w.  j av a2 s  .  c  o m*/
            firstElement = false;
        }

        outputBuilder.append("if (element_equal(child_node, \"").append(getXmlTag(currentStructMember))
                .append("\")) {").append("\n");
        outputBuilder.append(StructMemberHelper.getParseStructMemberBlock(currentStructMember));
    }

    outputBuilder.append(indent(2)).append("} else {").append("\n");
    outputBuilder.append(indent(3)).append("ds3_log_message(client->log, DS3_ERROR, \"Unknown node[%s] of "
            + structName + " [%s]\\n\", child_node->name, root->name);").append("\n");
    outputBuilder.append(indent(2)).append("}").append("\n");
    outputBuilder.append("\n");
    outputBuilder.append(indent(2)).append("if (error != NULL) {\n");
    outputBuilder.append(indent(3)).append("break;\n");
    outputBuilder.append(indent(2)).append("}\n");

    return outputBuilder.toString();
}

From source file:com.google.template.soy.jbcsrc.Expression.java

/**
 * Checks that the given expressions are compatible with the given types.
 */// w  w  w .j  a  v a  2  s.  c  o  m
static void checkTypes(ImmutableList<Type> types, Iterable<? extends Expression> exprs) {
    int size = Iterables.size(exprs);
    checkArgument(size == types.size(), "Supplied the wrong number of parameters. Expected %s, got %s",
            types.size(), size);
    int i = 0;
    for (Expression expr : exprs) {
        expr.checkAssignableTo(types.get(i), "Parameter %s", i);
        i++;
    }
}

From source file:net.techcable.sonarpet.utils.ProfileUtils.java

public static ImmutableList<PlayerProfile> lookupAll(Iterable<String> iterable) {
    ImmutableList<String> names = ImmutableList.copyOf(Preconditions.checkNotNull(iterable, "Null collection"));
    PlayerProfile[] profiles = new PlayerProfile[names.size()];
    int profilesSize = 0;
    int requests = MathMagic.divideRoundUp(names.size(), PROFILES_PER_REQUEST);
    int nameIndex = 0;
    List<String> toRequest = new ArrayList<>(PROFILES_PER_REQUEST);
    for (int requestId = 0; requestId < requests; requestId++) {
        toRequest.clear();/*  w  ww .  jav  a 2  s  .  co  m*/
        for (int start = nameIndex; nameIndex < names.size() && nameIndex < start + 100; nameIndex++) {
            String name = names.get(nameIndex);
            PlayerProfile profile;
            if ((profile = nameCache.get(name)) != null) {
                profiles[profilesSize++] = profile;
            } else {
                toRequest.add(name);
            }
        }
        for (PlayerProfile profile : postNames(toRequest)) {
            profiles[profilesSize++] = profile;
        }
    }
    profiles = Arrays.copyOf(profiles, profilesSize); // Trim
    return ImmutableList.copyOf(profiles);
}

From source file:com.google.javascript.rhino.jstype.TemplateTypeMap.java

private static boolean checkEquivalenceHelper(EquivalenceMethod eqMethod, TemplateTypeMap thisMap,
        TemplateTypeMap thatMap) {//w  w  w  . j av a 2  s .  co  m
    ImmutableList<TemplateType> thisKeys = thisMap.getTemplateKeys();
    ImmutableList<TemplateType> thatKeys = thatMap.getTemplateKeys();

    for (int i = 0; i < thisKeys.size(); i++) {
        TemplateType thisKey = thisKeys.get(i);
        JSType thisType = thisMap.getResolvedTemplateType(thisKey);
        EquivalenceMatch thisMatch = EquivalenceMatch.NO_KEY_MATCH;

        for (int j = 0; j < thatKeys.size(); j++) {
            TemplateType thatKey = thatKeys.get(j);
            JSType thatType = thatMap.getResolvedTemplateType(thatKey);

            // Cross-compare every key-value pair in this TemplateTypeMap with
            // those in that TemplateTypeMap. Update the Equivalence match for both
            // key-value pairs involved.
            if (thisKey == thatKey) {
                EquivalenceMatch newMatchType = EquivalenceMatch.VALUE_MISMATCH;
                if (thisType.checkEquivalenceHelper(thatType, eqMethod)) {
                    newMatchType = EquivalenceMatch.VALUE_MATCH;
                }

                if (thisMatch != EquivalenceMatch.VALUE_MATCH) {
                    thisMatch = newMatchType;
                }
            }
        }

        if (failedEquivalenceCheck(thisMatch, eqMethod)) {
            return false;
        }
    }
    return true;
}

From source file:com.opengamma.strata.collect.io.CsvFile.java

static ImmutableMap<String, Integer> buildSearchHeaders(ImmutableList<String> headers) {
    // need to allow duplicate headers and only store the first instance
    Map<String, Integer> searchHeaders = new HashMap<>();
    for (int i = 0; i < headers.size(); i++) {
        String searchHeader = headers.get(i).toLowerCase(Locale.ENGLISH);
        searchHeaders.putIfAbsent(searchHeader, i);
    }//from  w w  w. j  a v  a  2 s . c om
    return ImmutableMap.copyOf(searchHeaders);
}