Example usage for com.google.common.collect ImmutableList.Builder iterator

List of usage examples for com.google.common.collect ImmutableList.Builder iterator

Introduction

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

Prototype

@Override
    public UnmodifiableIterator<E> iterator() 

Source Link

Usage

From source file:com.spotify.heroic.aggregation.ChainInstance.java

@Override
public AggregationInstance distributed() {
    final Iterator<AggregationInstance> it = chain.iterator();

    final ImmutableList.Builder<AggregationInstance> chain = ImmutableList.builder();
    AggregationInstance last = it.next();

    if (!last.distributable()) {
        return EmptyInstance.INSTANCE;
    }// w w w  .jav a2  s  . c  om

    while (it.hasNext()) {
        final AggregationInstance next = it.next();

        if (!next.distributable()) {
            chain.add(last.distributed());
            return fromList(chain.build());
        }

        chain.add(last);
        last = next;
    }

    chain.add(last.distributed());
    return fromList(chain.build());
}

From source file:com.spotify.heroic.aggregation.ChainInstance.java

@Override
public AggregationInstance reducer() {
    final Iterator<AggregationInstance> it = chain.iterator();
    AggregationInstance last = it.next();

    final ImmutableList.Builder<AggregationInstance> chain = ImmutableList.builder();

    if (!last.distributable()) {
        chain.add(EmptyInstance.INSTANCE);
        chain.add(last);/*from  w ww  .ja v a  2s  .  c o  m*/

        while (it.hasNext()) {
            chain.add(it.next());
        }

        return fromList(chain.build());
    }

    while (it.hasNext()) {
        final AggregationInstance next = it.next();

        if (!next.distributable()) {
            chain.add(last.reducer());
            chain.add(next);

            while (it.hasNext()) {
                chain.add(it.next());
            }

            return fromList(chain.build());
        }

        last = next;
    }

    return last.reducer();
}