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:com.google.javascript.jscomp.PolymerClassDefinition.java

/**
 * Validates the class definition and if valid, destructively extracts the class definition from
 * the AST.//from   w  w  w  .j a v  a2s. c  o m
 */
@Nullable
static PolymerClassDefinition extractFromCallNode(Node callNode, AbstractCompiler compiler,
        GlobalNamespace globalNames) {
    Node descriptor = NodeUtil.getArgumentForCallOrNew(callNode, 0);
    if (descriptor == null || !descriptor.isObjectLit()) {
        // report bad class definition
        compiler.report(JSError.make(callNode, PolymerPassErrors.POLYMER_DESCRIPTOR_NOT_VALID));
        return null;
    }

    int paramCount = callNode.getChildCount() - 1;
    if (paramCount != 1) {
        compiler.report(JSError.make(callNode, PolymerPassErrors.POLYMER_UNEXPECTED_PARAMS));
        return null;
    }

    Node elName = NodeUtil.getFirstPropMatchingKey(descriptor, "is");
    if (elName == null) {
        compiler.report(JSError.make(callNode, PolymerPassErrors.POLYMER_MISSING_IS));
        return null;
    }

    Node target;
    if (NodeUtil.isNameDeclaration(callNode.getGrandparent())) {
        target = IR.name(callNode.getParent().getString());
    } else if (callNode.getParent().isAssign()) {
        target = callNode.getParent().getFirstChild().cloneTree();
    } else {
        String elNameStringBase = elName.isQualifiedName() ? elName.getQualifiedName().replace('.', '$')
                : elName.getString();
        String elNameString = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, elNameStringBase);
        elNameString += "Element";
        target = IR.name(elNameString);
    }

    JSDocInfo classInfo = NodeUtil.getBestJSDocInfo(target);

    JSDocInfo ctorInfo = null;
    Node constructor = NodeUtil.getFirstPropMatchingKey(descriptor, "factoryImpl");
    if (constructor == null) {
        constructor = NodeUtil.emptyFunction();
        compiler.reportChangeToChangeScope(constructor);
        constructor.useSourceInfoFromForTree(callNode);
    } else {
        ctorInfo = NodeUtil.getBestJSDocInfo(constructor);
    }

    Node baseClass = NodeUtil.getFirstPropMatchingKey(descriptor, "extends");
    String nativeBaseElement = baseClass == null ? null : baseClass.getString();

    Node behaviorArray = NodeUtil.getFirstPropMatchingKey(descriptor, "behaviors");
    PolymerBehaviorExtractor behaviorExtractor = new PolymerBehaviorExtractor(compiler, globalNames);
    ImmutableList<BehaviorDefinition> behaviors = behaviorExtractor.extractBehaviors(behaviorArray);
    List<MemberDefinition> allProperties = new ArrayList<>();
    for (BehaviorDefinition behavior : behaviors) {
        overwriteMembersIfPresent(allProperties, behavior.props);
    }
    overwriteMembersIfPresent(allProperties,
            PolymerPassStaticUtils.extractProperties(descriptor, DefinitionType.ObjectLiteral, compiler,
                    /** constructor= */
                    null));

    FeatureSet newFeatures = null;
    if (!behaviors.isEmpty()) {
        newFeatures = behaviors.get(0).features;
        for (int i = 1; i < behaviors.size(); i++) {
            newFeatures = newFeatures.union(behaviors.get(i).features);
        }
    }

    List<MemberDefinition> methods = new ArrayList<>();
    for (Node keyNode : descriptor.children()) {
        boolean isFunctionDefinition = keyNode.isMemberFunctionDef()
                || (keyNode.isStringKey() && keyNode.getFirstChild().isFunction());
        if (isFunctionDefinition) {
            methods.add(
                    new MemberDefinition(NodeUtil.getBestJSDocInfo(keyNode), keyNode, keyNode.getFirstChild()));
        }
    }

    return new PolymerClassDefinition(DefinitionType.ObjectLiteral, callNode, target, descriptor, classInfo,
            new MemberDefinition(ctorInfo, null, constructor), nativeBaseElement, allProperties, methods,
            behaviors, newFeatures);
}

From source file:com.facebook.buck.parser.PythonDslProjectBuildFileParser.java

private static ImmutableMap<String, Map<String, Object>> indexTargetsByName(
        ImmutableList<Map<String, Object>> targets) {
    ImmutableMap.Builder<String, Map<String, Object>> builder = ImmutableMap
            .builderWithExpectedSize(targets.size());
    targets.forEach(target -> builder.put((String) target.get("name"), convertSelectableAttributes(target)));
    return builder.build();
}

From source file:com.opengamma.strata.pricer.calibration.CurveCalibrator.java

private static DoubleMatrix jacobianIndirect(DoubleMatrix res, DoubleMatrix pDmCurrentMatrix, int nbTrades,
        int totalParamsGroup, int totalParamsPrevious, ImmutableList<CurveParameterSize> orderPrevious,
        ImmutableMap<CurveName, JacobianCalibrationMatrix> jacobiansPrevious) {

    if (totalParamsPrevious == 0) {
        return DoubleMatrix.EMPTY;
    }/*  w  w  w .  j a v  a 2  s . c  o m*/
    double[][] nonDirect = new double[totalParamsGroup][totalParamsPrevious];
    for (int i = 0; i < nbTrades; i++) {
        System.arraycopy(res.rowArray(i), 0, nonDirect[i], 0, totalParamsPrevious);
    }
    DoubleMatrix pDpPreviousMatrix = (DoubleMatrix) MATRIX_ALGEBRA
            .scale(MATRIX_ALGEBRA.multiply(pDmCurrentMatrix, DoubleMatrix.copyOf(nonDirect)), -1d);
    // all curves: order and size
    int[] startIndexBefore = new int[orderPrevious.size()];
    for (int i = 1; i < orderPrevious.size(); i++) {
        startIndexBefore[i] = startIndexBefore[i - 1] + orderPrevious.get(i - 1).getParameterCount();
    }
    // transition Matrix: all curves from previous groups
    double[][] transition = new double[totalParamsPrevious][totalParamsPrevious];
    for (int i = 0; i < orderPrevious.size(); i++) {
        int paramCountOuter = orderPrevious.get(i).getParameterCount();
        JacobianCalibrationMatrix thisInfo = jacobiansPrevious.get(orderPrevious.get(i).getName());
        DoubleMatrix thisMatrix = thisInfo.getJacobianMatrix();
        int startIndexInner = 0;
        for (int j = 0; j < orderPrevious.size(); j++) {
            int paramCountInner = orderPrevious.get(j).getParameterCount();
            if (thisInfo.containsCurve(orderPrevious.get(j).getName())) { // If not, the matrix stay with 0
                for (int k = 0; k < paramCountOuter; k++) {
                    System.arraycopy(thisMatrix.rowArray(k), startIndexInner,
                            transition[startIndexBefore[i] + k], startIndexBefore[j], paramCountInner);
                }
            }
            startIndexInner += paramCountInner;
        }
    }
    DoubleMatrix transitionMatrix = DoubleMatrix.copyOf(transition);
    return (DoubleMatrix) MATRIX_ALGEBRA.multiply(pDpPreviousMatrix, transitionMatrix);
}

From source file:com.github.kryptohash.kryptohashj.crypto.DeterministicEd25519Key.java

public static DeterministicEd25519Key deserialize(@Nullable DeterministicEd25519Key parent,
        byte[] serializedKey) {
    ByteBuffer buffer = ByteBuffer.wrap(serializedKey);
    int header = buffer.getInt();
    if (header != HEADER_PRIV && header != HEADER_PUB)
        throw new IllegalArgumentException("Unknown header bytes: " + toBase58(serializedKey).substring(0, 4));

    boolean pub = header == HEADER_PUB;
    byte depth = buffer.get();
    byte[] parentFingerprint = new byte[4];
    buffer.get(parentFingerprint);//from   w  w  w  .j av a 2  s.  c  o  m
    final int i = buffer.getInt();
    final ChildNumber childNumber = new ChildNumber(i);
    ImmutableList<ChildNumber> path;
    if (parent != null) {
        if (Arrays.equals(parentFingerprint, HDUtils.longTo4ByteArray(0)))
            throw new IllegalArgumentException("Parent was provided but this key doesn't have one");
        if (!Arrays.equals(parent.getFingerprint(), parentFingerprint))
            throw new IllegalArgumentException("Parent fingerprints don't match");
        path = HDUtils.append(parent.getPath(), childNumber);
        if (path.size() != depth)
            throw new IllegalArgumentException("Depth does not match");
    } else {
        if (depth == 0) {
            path = ImmutableList.of();
        } else if (depth == 1) {
            // We have been given a key that is not a root key, yet we also don't have any object representing
            // the parent. This can happen when deserializing an account key for a watching wallet. In this case,
            // we assume that the parent has a path of zero.
            path = ImmutableList.of(childNumber);
        } else {
            throw new IllegalArgumentException("Depth is " + depth + " and no parent key was provided, so we "
                    + "cannot reconstruct the key path from the provided data.");
        }
    }
    byte[] chainCode = new byte[32];
    buffer.get(chainCode);
    if (pub) {
        byte[] data = new byte[33];
        buffer.get(data);
        checkArgument(!buffer.hasRemaining(), "Found unexpected data in pub key");
        return new DeterministicEd25519Key(path, chainCode, new BigInteger(1, data), null, parent);
    } else {
        byte[] data = new byte[65];
        buffer.get(data);
        checkArgument(!buffer.hasRemaining(), "Found unexpected data in priv key");
        return new DeterministicEd25519Key(path, chainCode, new BigInteger(1, data), parent);
    }
}

From source file:li.klass.fhem.testsuite.category.CategorySuite.java

private static Class[] getSuiteClasses() {
    final String basePath = getBasePath();
    File basePathFile = new File(basePath);

    ImmutableList<Class<?>> classes = Files.fileTreeTraverser().breadthFirstTraversal(basePathFile)
            .filter(new Predicate<File>() {
                @Override/*  w  w  w  .  ja v  a2s. co  m*/
                public boolean apply(File input) {
                    return input.getName().endsWith(".java");
                }
            }).transform(new Function<File, Class<?>>() {
                @Override
                public Class<?> apply(File input) {
                    return toClass(input, basePath);
                }
            }).filter(new Predicate<Class<?>>() {
                @Override
                public boolean apply(Class<?> input) {
                    return input != null && !Modifier.isAbstract(input.getModifiers());
                }
            }).toList();
    return (classes.toArray(new Class[classes.size()]));

}

From source file:org.bitcoinj.crypto.DeterministicKey.java

/**
  * Deserialize an HD Key.//from w w  w  . jav a  2 s  .  co  m
 * @param parent The parent node in the given key's deterministic hierarchy.
 */
public static DeterministicKey deserialize(NetworkParameters params, byte[] serializedKey,
        @Nullable DeterministicKey parent) {
    ByteBuffer buffer = ByteBuffer.wrap(serializedKey);
    int header = buffer.getInt();
    if (header != params.getBip32HeaderPriv() && header != params.getBip32HeaderPub())
        throw new IllegalArgumentException("Unknown header bytes: " + toBase58(serializedKey).substring(0, 4));
    boolean pub = header == params.getBip32HeaderPub();
    int depth = buffer.get() & 0xFF; // convert signed byte to positive int since depth cannot be negative
    final int parentFingerprint = buffer.getInt();
    final int i = buffer.getInt();
    final ChildNumber childNumber = new ChildNumber(i);
    ImmutableList<ChildNumber> path;
    if (parent != null) {
        if (parentFingerprint == 0)
            throw new IllegalArgumentException("Parent was provided but this key doesn't have one");
        if (parent.getFingerprint() != parentFingerprint)
            throw new IllegalArgumentException("Parent fingerprints don't match");
        path = HDUtils.append(parent.getPath(), childNumber);
        if (path.size() != depth)
            throw new IllegalArgumentException("Depth does not match");
    } else {
        if (depth >= 1)
            // We have been given a key that is not a root key, yet we lack the object representing the parent.
            // This can happen when deserializing an account key for a watching wallet.  In this case, we assume that
            // the client wants to conceal the key's position in the hierarchy.  The path is truncated at the
            // parent's node.
            path = ImmutableList.of(childNumber);
        else
            path = ImmutableList.of();
    }
    byte[] chainCode = new byte[32];
    buffer.get(chainCode);
    byte[] data = new byte[33];
    buffer.get(data);
    checkArgument(!buffer.hasRemaining(), "Found unexpected data in key");
    if (pub) {
        return new DeterministicKey(path, chainCode, new LazyECPoint(ECKey.CURVE.getCurve(), data), parent,
                depth, parentFingerprint);
    } else {
        return new DeterministicKey(path, chainCode, new BigInteger(1, data), parent, depth, parentFingerprint);
    }
}

From source file:it.unibz.inf.ontop.ontology.impl.NaryAxiomImpl.java

NaryAxiomImpl(ImmutableList<T> components) {
    if (components.size() < 2)
        throw new IllegalArgumentException("At least two components are expected in NaryAxiom");

    this.components = components;
}

From source file:com.google.devtools.build.android.desugar.BytecodeTypeInference.java

private static ImmutableList<InferredType> removeBackFromList(ImmutableList<InferredType> list,
        int countToRemove) {
    int origSize = list.size();
    int index = origSize - 1;

    while (index >= 0 && countToRemove > 0) {
        InferredType type = list.get(index);
        if (type.equals(InferredType.TOP) && index > 0 && list.get(index - 1).isCategory2()) {
            --index; // A category 2 takes two slots.
        }/*from w w w  . j a  va 2 s . c  o  m*/
        --index; // Eat this local variable.
        --countToRemove;
    }
    checkState(countToRemove == 0, "countToRemove is %s but not 0. index=%s, list=%s", countToRemove, index,
            list);
    return list.subList(0, index + 1);
}

From source file:io.atomix.utils.serializer.serializers.ImmutableListSerializer.java

@Override
public void write(Kryo kryo, Output output, ImmutableList<?> object) {
    output.writeInt(object.size());
    for (Object e : object) {
        kryo.writeClassAndObject(output, e);
    }/* w w  w. j  a  v a  2s. c om*/
}

From source file:google.registry.rdap.RdapJsonFormatter.java

/**
 * Creates a vCard address entry: array of strings specifying the components of the address.
 *
 * @see <a href="https://tools.ietf.org/html/rfc7095">
 *        RFC 7095: jCard: The JSON Format for vCard</a>
 *//*  ww w  . ja  v a2s.  co  m*/
private static ImmutableList<Object> makeVCardAddressEntry(Address address) {
    if (address == null) {
        return null;
    }
    ImmutableList.Builder<Object> jsonBuilder = new ImmutableList.Builder<>();
    jsonBuilder.add(""); // PO box
    jsonBuilder.add(""); // extended address

    // The vCard spec allows several different ways to handle multiline street addresses. Per
    // Gustavo Lozano of ICANN, the one we should use is an embedded array of street address lines
    // if there is more than one line:
    //
    //   RFC7095 provides two examples of structured addresses, and one of the examples shows a
    //   street JSON element that contains several data elements. The example showing (see below)
    //   several data elements is the expected output when two or more <contact:street> elements
    //   exists in the contact object.
    //
    //   ["adr", {}, "text",
    //    [
    //    "", "",
    //    ["My Street", "Left Side", "Second Shack"],
    //    "Hometown", "PA", "18252", "U.S.A."
    //    ]
    //   ]
    ImmutableList<String> street = address.getStreet();
    if (street.isEmpty()) {
        jsonBuilder.add("");
    } else if (street.size() == 1) {
        jsonBuilder.add(street.get(0));
    } else {
        jsonBuilder.add(street);
    }
    jsonBuilder.add(nullToEmpty(address.getCity()));
    jsonBuilder.add(nullToEmpty(address.getState()));
    jsonBuilder.add(nullToEmpty(address.getZip()));
    jsonBuilder.add(new Locale("en", address.getCountryCode()).getDisplayCountry(new Locale("en")));
    return ImmutableList.<Object>of("adr", ImmutableMap.of(), "text", jsonBuilder.build());
}