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

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

Introduction

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

Prototype

public static int size(Iterable<?> iterable) 

Source Link

Document

Returns the number of elements in iterable .

Usage

From source file:com.nesscomputing.sequencer.HashSequencer.java

/**
 * Create a new HashSequencer with the elements of an array.
 *///www  .j a  va2 s .c o m
public static <K> HashSequencer<K> copyOf(Iterable<K> elements) {
    return new HashSequencer<>(Iterables.size(elements), elements);
}

From source file:com.github.msoliter.iroh.container.exceptions.UnexpectedImplementationCountException.java

/**
 * Constructs an exception detailing exactly the implementations identified
 * for a particular type.//from   w  w  w.  ja  va 2s.  c  o m
 * 
 * @param type The type we were attempting to resolve.
 * @param implementations A collection of all the implementing types. The
 *  size of the collection should be zero or greater than one.
 */
public UnexpectedImplementationCountException(Class<?> type, Iterable<Class<?>> implementations) {

    super((Iterables.size(implementations) == 0) ? String.format(zeroImplementationsFormat, type)
            : String.format(multipleImplementationsFormat, type, Iterables.size(implementations),
                    Joiner.on(", ").join(implementations)));
}

From source file:msi.gaml.expressions.MapExpression.java

MapExpression(final Iterable<? extends IExpression> pairs) {
    final int size = Iterables.size(pairs);
    keys = new IExpression[size];
    vals = new IExpression[size];
    int i = 0;// ww  w.j a  va  2  s  . c o m
    for (final IExpression e : pairs) {
        if (e instanceof BinaryOperator) {
            final BinaryOperator pair = (BinaryOperator) e;
            keys[i] = pair.exprs[0];
            vals[i] = pair.exprs[1];
        } else if (e instanceof ConstantExpression && e.getGamlType().getGamlType() == Types.PAIR) {
            final GamaPair pair = (GamaPair) e.getConstValue();
            final Object left = pair.key;
            final Object right = pair.value;
            keys[i] = GAML.getExpressionFactory().createConst(left, e.getGamlType().getKeyType());
            vals[i] = GAML.getExpressionFactory().createConst(right, e.getGamlType().getContentType());
        }
        i++;
    }
    final IType keyType = GamaType.findCommonType(keys, GamaType.TYPE);
    final IType contentsType = GamaType.findCommonType(vals, GamaType.TYPE);
    // values = GamaMapFactory.create(keyType, contentsType, keys.length);
    // setName(pairs.toString());
    type = Types.MAP.of(keyType, contentsType);
}

From source file:com.b2international.index.revision.DefaultRevisionSearcher.java

@Override
public <T extends Revision> Iterable<T> get(Class<T> type, Iterable<Long> storageKeys) throws IOException {
    if (Iterables.isEmpty(storageKeys)) {
        return Collections.emptySet();
    } else {//from  w  w w.j  a v a 2s.com
        final Query<T> query = Query.select(type)
                .where(Expressions.matchAnyLong(Revision.STORAGE_KEY, storageKeys))
                .limit(Iterables.size(storageKeys)).build();
        return search(query);
    }
}

From source file:com.eucalyptus.cloudwatch.common.CloudWatchResourceName.java

public static CloudWatchResourceName parse(final String resourceName, @Nullable final Type type)
        throws InvalidResourceNameException {
    if (!resourceName.startsWith(prefix)) {
        throw new InvalidResourceNameException(resourceName);
    }// w  ww. j  a va  2 s.com

    final Iterable<String> nameParts = nameSpliter.split(resourceName);
    final int namePartCount = Iterables.size(nameParts);
    if (namePartCount < MIN_PARTS || namePartCount > MAX_PARTS) {
        throw new InvalidResourceNameException(resourceName);
    }

    if (!"cloudwatch".equals(Iterables.get(nameParts, PART_SERVICE))) {
        throw new InvalidResourceNameException(resourceName);
    }

    if (type != null && !type.name().equals(Iterables.get(nameParts, PART_RELATIVE_ID_TYPE))) {
        throw new InvalidResourceNameException(resourceName);
    }

    return new CloudWatchResourceName(resourceName, Iterables.get(nameParts, PART_SERVICE),
            Iterables.get(nameParts, PART_NAMESPACE), Iterables.get(nameParts, PART_RELATIVE_ID_TYPE),
            Iterables.get(nameParts, PART_RELATIVE_NAME));
}

From source file:com.eucalyptus.auth.principal.SecurityTokenContentImpl.java

public SecurityTokenContentImpl(final Optional<String> originatingAccessKeyId,
        final Optional<String> originatingUserId, final Optional<String> originatingRoleId, final String nonce,
        final long created, final long expires) {
    Parameters.checkParam("originatingAccessKeyId", originatingAccessKeyId, notNullValue());
    Parameters.checkParam("originatingUserId", originatingUserId, notNullValue());
    Parameters.checkParam("originatingRoleId", originatingRoleId, notNullValue());
    Parameters.checkParam("nonce", nonce, not(isEmptyOrNullString()));
    if (Iterables.size(Optional.presentInstances(
            Arrays.asList(originatingAccessKeyId, originatingUserId, originatingRoleId))) != 1) {
        throw new IllegalArgumentException("One originating identifier expected");
    }//from  w  ww. j av a 2s .com
    this.originatingAccessKeyId = originatingAccessKeyId;
    this.originatingUserId = originatingUserId;
    this.originatingRoleId = originatingRoleId;
    this.nonce = nonce;
    this.created = created;
    this.expires = expires;
}

From source file:org.apache.mahout.utils.vectors.VectorHelper.java

public static List<Pair<Integer, Double>> topEntries(Vector vector, int maxEntries) {

    // Get the size of nonZero elements in the input vector
    int sizeOfNonZeroElementsInVector = Iterables.size(vector.nonZeroes());

    // If the sizeOfNonZeroElementsInVector < maxEntries then set maxEntries = sizeOfNonZeroElementsInVector
    // otherwise the call to queue.pop() returns a Pair(null, null) and the subsequent call
    // to pair.getFirst() throws a NullPointerException
    if (sizeOfNonZeroElementsInVector < maxEntries) {
        maxEntries = sizeOfNonZeroElementsInVector;
    }/*  w ww .  j a  v a2s .  com*/

    PriorityQueue<Pair<Integer, Double>> queue = new TDoublePQ<Integer>(-1, maxEntries);
    for (Element e : vector.nonZeroes()) {
        queue.insertWithOverflow(Pair.of(e.index(), e.get()));
    }
    List<Pair<Integer, Double>> entries = Lists.newArrayList();
    Pair<Integer, Double> pair;
    while ((pair = queue.pop()) != null) {
        if (pair.getFirst() > -1) {
            entries.add(pair);
        }
    }
    Collections.sort(entries, new Comparator<Pair<Integer, Double>>() {
        @Override
        public int compare(Pair<Integer, Double> a, Pair<Integer, Double> b) {
            return b.getSecond().compareTo(a.getSecond());
        }
    });
    return entries;
}

From source file:org.jclouds.trmk.vcloud_0_8.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault.java

@Override
public ReferenceType apply(Iterable<ReferenceType> referenceTypes) {
    checkNotNull(referenceTypes, "referenceTypes");
    checkArgument(Iterables.size(referenceTypes) > 0,
            "No referenceTypes corresponding to configuration key %s present", configurationKey);
    if (Iterables.size(referenceTypes) == 1)
        return Iterables.getLast(referenceTypes);
    String namingPattern = valueOfConfigurationKeyOrNull.apply(configurationKey);
    if (namingPattern != null) {
        return findReferenceTypeWithNameMatchingPattern(referenceTypes, namingPattern);
    } else {//from ww  w  .  j ava 2  s .  com
        return defaultReferenceType(referenceTypes);
    }
}

From source file:org.apache.giraph.graph.IntIntNullIntVertex.java

@Override
public void initialize(IntWritable vertexId, IntWritable vertexValue, Map<IntWritable, NullWritable> edges,
        Iterable<IntWritable> messages) {
    id = vertexId.get();//from   w w  w.  jav a  2 s .  c  om
    value = vertexValue.get();
    this.neighbors = new int[(edges != null) ? edges.size() : 0];
    int n = 0;
    if (edges != null) {
        for (IntWritable neighbor : edges.keySet()) {
            this.neighbors[n++] = neighbor.get();
        }
    }
    this.messages = new int[(messages != null) ? Iterables.size(messages) : 0];
    if (messages != null) {
        n = 0;
        for (IntWritable message : messages) {
            this.messages[n++] = message.get();
        }
    }
}

From source file:com.google.errorprone.bugpatterns.testdata.SizeGreaterThanOrEqualsZeroPositiveCases.java

public boolean collectionSize() {

    // BUG: Diagnostic contains: !intList.isEmpty()
    boolean foo = intList.size() >= 0;

    // BUG: Diagnostic contains: !intSet.isEmpty()
    foo = intSet.size() >= 0;//from  w  w  w.ja  v a  2 s  .c  o m

    // BUG: Diagnostic contains: !intSet.isEmpty()
    foo = 0 <= intSet.size();

    // BUG: Diagnostic contains: !intMap.isEmpty()
    foo = intMap.size() >= 0;

    // BUG: Diagnostic contains: !intCollection.isEmpty()
    foo = intCollection.size() >= 0;

    // Yes, that works as java code
    // BUG: Diagnostic contains: !new ArrayList<Integer>().isEmpty()
    if (new ArrayList<Integer>().size() >= 0) {
    }

    CollectionContainer baz = new CollectionContainer();

    // BUG: Diagnostic contains: !baz.intList.isEmpty()
    if (baz.intList.size() >= 0) {
    }

    // BUG: Diagnostic contains: !baz.getIntList().isEmpty()
    if (baz.getIntList().size() >= 0) {
    }

    // BUG: Diagnostic contains: !Iterables.isEmpty(baz.getIntList())
    foo = Iterables.size(baz.getIntList()) >= 0;

    return foo;
}