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:org.nmdp.ngs.range.tree.CenteredRangeTree.java

/**
 * Create a new centered range tree with the specified ranges.
 *
 * @param ranges ranges, must not be null
 */// w  w w . j av a2 s. c o m
private CenteredRangeTree(final Iterable<Range<C>> ranges) {
    checkNotNull(ranges);
    // O(n) hit to cache size
    size = Iterables.size(ranges);
    root = createNode(ranges);
}

From source file:com.fredhopper.connector.query.populators.request.SearchSortPopulator.java

@Override
public void populate(final SearchQueryPageableData<FhSearchQueryData> source, final Query target)
        throws ConversionException {
    final PageableData pageableData = source.getPageableData();
    if (pageableData != null && StringUtils.isNotBlank(pageableData.getSort())) {
        final Iterable<String> split = Splitter.on('_').split(pageableData.getSort());
        if (Iterables.size(split) > 1) {
            final String attributeName = Iterables.get(split, 0);
            final String direction = Iterables.get(split, 1);

            if ("ASC".equalsIgnoreCase(direction)) {
                target.addSortingBy(attributeName, SortDirection.ASC);
            } else {
                target.addSortingBy(attributeName, SortDirection.DESC);
            }//from   w  ww. ja v  a  2  s . c om
        }
    }
}

From source file:com.vilt.minium.app.controller.ConsoleController.java

@RequestMapping(value = "/eval")
@ResponseBody/*from  w ww . ja  v  a2  s  .c  om*/
public synchronized EvalResult eval(@RequestParam("expr") final String expression,
        @RequestParam(value = "lineno", defaultValue = "1") final int lineNumber) {
    try {
        Object result = engine.eval(expression, lineNumber);
        if (result instanceof DebugWebElements) {
            DebugWebElements webElements = (DebugWebElements) result;
            webElements.highlight();
            int totalCount = Iterables.size(webElements);
            return new EvalResult(expression, totalCount);
        } else {
            return new EvalResult(result);
        }
    } catch (Exception e) {
        logger.error("Evaluation of {} failed", expression, e);
        throw new EvalException(e);
    }
}

From source file:com.notifier.desktop.notification.parsing.impl.TextNotificationParser.java

@Override
public Notification parse(byte[] msg) throws ParseException {
    byte[] msgToUse = decryptIfNecessary(msg);
    if (msgToUse == null) {
        return null;
    }//from  w  w w.  j a  va2  s  . co  m

    String s = new String(msgToUse, CHARSET);
    Iterable<String> splitted = Splitter.on(FIELD_SEPARATOR).split(s);
    if (Iterables.size(splitted) < FIELD_COUNT) {
        logger.debug("Got notification but it has less fields than expected, maybe it's encrypted, ignoring");
        return null;
    }

    Iterator<String> iterator = splitted.iterator();
    String version = iterator.next();
    if (!SUPPORTED_VERSION.equals(version)) {
        throw new ParseException("Protocol version [" + version + "] is not supported");
    }

    String deviceId = iterator.next();
    long notificationId = new BigInteger(iterator.next(), 16).longValue();
    Notification.Type type = Notification.Type.valueOf(iterator.next());
    String data = iterator.next();
    StringBuilder contents = new StringBuilder();
    while (iterator.hasNext()) {
        contents.append(iterator.next());
        if (iterator.hasNext()) {
            contents.append(FIELD_SEPARATOR);
        }
    }

    return new Notification(deviceId, notificationId, type, data, contents.substring(0, contents.length() - 1));
}

From source file:com.netxforge.netxstudio.common.model.NodeSummary.java

@Override
protected void computeForTarget(IProgressMonitor monitor) {

    // Safely case, checked by our factory.
    final Node target = getNode();

    final TreeIterator<EObject> iterator = target.eAllContents();

    // Might throw an Exception.
    int work = Iterables.size((Iterable<?>) iterator);

    final SubMonitor subMonitor = SubMonitor.convert(monitor, work);
    subMonitor.setTaskName("Computing summary for " + StudioUtils.printModelObject(target));

    while (iterator.hasNext()) {

        EObject next = iterator.next();/*  ww  w. ja  v  a 2 s.c  om*/

        if (next instanceof Function) {
            functions += 1;
        } else if (next instanceof Equipment) {
            equipments += 1;
        }

        if (next instanceof NodeType) {

            IMonitoringSummary childAdapter = getAdapter(next);

            // Guard for potentially non-adapted children.
            if (childAdapter != null) {
                childAdapter.addContextObjects(this.getContextObjects());
                childAdapter.compute(monitor);
                // Base our RAG status, on the child's status
                this.incrementRag(childAdapter.rag());
                if (childAdapter instanceof NodeTypeSummary) {
                    resources += ((ComponentSummary) childAdapter).totalResources();
                }
            }
        }
        subMonitor.worked(1);
    }
}

From source file:org.janusgraph.graphdb.types.indextype.CompositeIndexTypeWrapper.java

@Override
public IndexField[] getFieldKeys() {
    IndexField[] result = fields;/*from  ww w .j  av a 2 s  .  c o m*/
    if (result == null) {
        Iterable<SchemaSource.Entry> entries = base.getRelated(TypeDefinitionCategory.INDEX_FIELD,
                Direction.OUT);
        int numFields = Iterables.size(entries);
        result = new IndexField[numFields];
        for (SchemaSource.Entry entry : entries) {
            Integer value = ParameterType.INDEX_POSITION.findParameter((Parameter[]) entry.getModifier(), null);
            Preconditions.checkNotNull(value);
            int pos = value;
            Preconditions.checkArgument(pos >= 0 && pos < numFields, "Invalid field position: %s", pos);
            assert entry.getSchemaType() instanceof PropertyKey;
            result[pos] = IndexField.of((PropertyKey) entry.getSchemaType());
        }
        fields = result;
    }
    assert result != null;
    return result;
}

From source file:org.apache.mahout.knn.means.ThreadedKmeans.java

public static List<Iterable<MatrixSlice>> split(Iterable<MatrixSlice> data, int threads) {
    List<Iterable<MatrixSlice>> r = Lists.newArrayList();
    int size = Iterables.size(data);
    int block = (size + threads - 1) / threads;

    for (int start = 0; start < size; start += block) {
        final Iterable<MatrixSlice> split = Iterables.limit(Iterables.skip(data, start),
                (Math.min(start + block, size) - start));
        r.add(split);/*from   w ww  . ja va 2 s. com*/
    }
    return r;
}

From source file:com.vilt.minium.impl.WaitPredicates.java

/**
 * Predicate to use with {@link WaitWebElements#wait(Predicate)} methods which ensures that
 * evaluation will only be successful when this instance has a specific size.
 *
 * @param <T> the generic type// w  w w  .  ja  va 2s  .  c  o  m
 * @param size number of matched {@link WebElement} instances
 * @return predicate that returns true if it has the exact size
 */
public static <T extends WebElements> Predicate<T> untilSize(final int size) {
    return new Predicate<T>() {
        @Override
        public boolean apply(T input) {
            return Iterables.size(input) == size;
        }

        @Override
        public String toString() {
            return format("untilSize(%d)", size);
        }
    };
}

From source file:org.dishevelled.bio.range.tree.CenteredRangeTree.java

/**
 * Create a new centered range tree with the specified ranges.
 *
 * @param ranges ranges, must not be null
 *///from w w w  .j  a  v  a 2s  . c o  m
private CenteredRangeTree(final Iterable<Range<C>> ranges) {
    checkNotNull(ranges);
    size = Iterables.size(ranges);
    root = createNode(ranges);
}

From source file:org.vclipse.constraint.validation.ConstraintJavaValidator.java

@Check(CheckType.FAST)
public void checkConstraint(ConstraintSource source) {
    if (source != null) {
        List<ConstraintRestriction> restrictions = source.getRestrictions();
        int size = Iterables.size(Iterables.filter(restrictions, ConditionalConstraintRestriction.class));
        if (size > 0 && restrictions.size() > size) {
            error("Mix of conditional and unconditional restrictions is not allowed in a constraint",
                    VcmlPackage.Literals.CONSTRAINT_SOURCE__RESTRICTIONS);
            // TODO possible quickfix: split this constraint
        }//www .j a  va2  s . c o m
    }
}