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

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

Introduction

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

Prototype

@Deprecated
public static <E> Iterable<E> unmodifiableIterable(ImmutableCollection<E> iterable) 

Source Link

Document

Simply returns its argument.

Usage

From source file:eu.lp0.cursus.scoring.scores.impl.GenericRaceLapsData.java

protected Iterable<Pilot> extractRaceLaps(Race race, Predicate<Pilot> filter) {
    // If they aren't marked as attending the race as a pilot, they don't get scored
    Predicate<Pilot> attending = Predicates.in(filteredPilots(race));
    if (filter != null) {
        filter = Predicates.and(attending, filter);
    } else {//from   w  w w . ja va  2s .  c om
        filter = attending;
    }

    // Convert a list of race events into a list of valid pilot laps
    return Iterables.filter(Iterables.transform(Iterables.unmodifiableIterable(race.getTallies()),
            new Function<RaceTally, Pilot>() {
                boolean scoring = scoreBeforeStart;

                @Override
                public Pilot apply(@Nonnull RaceTally tally) {
                    switch (tally.getType()) {
                    case START:
                        scoring = true;
                        break;

                    case LAP:
                        if (scoring) {
                            return tally.getPilot();
                        }
                        break;

                    case INVALID_LAP:
                        break;

                    case FINISH:
                        scoring = scoreAfterFinish;
                        break;
                    }

                    return null;
                }

            }), filter);
}

From source file:org.movsim.simulator.roadnetwork.regulator.Regulator.java

public Iterable<NotifyObject> getNotifyObjects() {
    return Iterables.unmodifiableIterable(notifyObjects);
}

From source file:org.apache.beam.runners.spark.translation.SparkGlobalCombineFn.java

/**
 * Implement Spark's combOp function in:
 * <p>/*from  w w  w  .  j a va2s .  c om*/
 * {@link org.apache.spark.api.java.JavaRDD#aggregate}.
 * </p>
 */
Iterable<WindowedValue<AccumT>> combOp(Iterable<WindowedValue<AccumT>> a1, Iterable<WindowedValue<AccumT>> a2) {

    // concatenate accumulators.
    Iterable<WindowedValue<AccumT>> accumulators = Iterables.concat(a1, a2);
    // if empty, return an empty accumulators iterable.
    if (!accumulators.iterator().hasNext()) {
        return Lists.newArrayList();
    }

    // sort accumulators, no need to explode since inputs were exploded.
    Iterable<WindowedValue<AccumT>> sortedAccumulators = sortByWindows(accumulators);

    @SuppressWarnings("unchecked")
    TimestampCombiner timestampCombiner = windowingStrategy.getTimestampCombiner();

    //--- accumulators iterator, by window order.
    final Iterator<WindowedValue<AccumT>> iterator = sortedAccumulators.iterator();

    // get the first accumulator and assign it to the current window's accumulators.
    WindowedValue<AccumT> currentValue = iterator.next();
    BoundedWindow currentWindow = Iterables.getFirst(currentValue.getWindows(), null);
    List<AccumT> currentWindowAccumulators = Lists.newArrayList();
    currentWindowAccumulators.add(currentValue.getValue());

    // keep track of the timestamps assigned by the TimestampCombiner,
    // in createCombiner we already merge the timestamps assigned
    // to individual elements, here we will just merge them.
    List<Instant> windowTimestamps = Lists.newArrayList();
    windowTimestamps.add(currentValue.getTimestamp());

    // accumulate the next windows, or output.
    List<WindowedValue<AccumT>> output = Lists.newArrayList();

    // if merging, merge overlapping windows, e.g. Sessions.
    final boolean merging = !windowingStrategy.getWindowFn().isNonMerging();

    while (iterator.hasNext()) {
        WindowedValue<AccumT> nextValue = iterator.next();
        BoundedWindow nextWindow = Iterables.getOnlyElement(nextValue.getWindows());

        boolean mergingAndIntersecting = merging
                && isIntersecting((IntervalWindow) currentWindow, (IntervalWindow) nextWindow);

        if (mergingAndIntersecting || nextWindow.equals(currentWindow)) {
            if (mergingAndIntersecting) {
                // merge intersecting windows.
                currentWindow = merge((IntervalWindow) currentWindow, (IntervalWindow) nextWindow);
            }
            // add to window accumulators.
            currentWindowAccumulators.add(nextValue.getValue());
            windowTimestamps.add(nextValue.getTimestamp());
        } else {
            // before moving to the next window,
            // add the current accumulation to the output and initialize the accumulation.

            // merge the timestamps of all accumulators to merge.
            Instant mergedTimestamp = timestampCombiner.merge(currentWindow, windowTimestamps);

            // merge accumulators.
            // transforming a KV<K, Iterable<AccumT>> into a KV<K, Iterable<AccumT>>.
            // for the (possibly merged) window.
            Iterable<AccumT> accumsToMerge = Iterables.unmodifiableIterable(currentWindowAccumulators);
            WindowedValue<Iterable<AccumT>> preMergeWindowedValue = WindowedValue.of(accumsToMerge,
                    mergedTimestamp, currentWindow, PaneInfo.NO_FIRING);
            // applying the actual combiner onto the accumulators.
            AccumT accumulated = combineFn.mergeAccumulators(accumsToMerge,
                    ctxtForInput(preMergeWindowedValue));
            WindowedValue<AccumT> postMergeWindowedValue = preMergeWindowedValue.withValue(accumulated);
            // emit the accumulated output.
            output.add(postMergeWindowedValue);

            // re-init accumulator, window and timestamps.
            currentWindowAccumulators.clear();
            currentWindowAccumulators.add(nextValue.getValue());
            currentWindow = nextWindow;
            windowTimestamps.clear();
            windowTimestamps.add(nextValue.getTimestamp());
        }
    }

    // merge the last chunk of accumulators.
    Instant mergedTimestamp = timestampCombiner.merge(currentWindow, windowTimestamps);
    Iterable<AccumT> accumsToMerge = Iterables.unmodifiableIterable(currentWindowAccumulators);
    WindowedValue<Iterable<AccumT>> preMergeWindowedValue = WindowedValue.of(accumsToMerge, mergedTimestamp,
            currentWindow, PaneInfo.NO_FIRING);
    AccumT accumulated = combineFn.mergeAccumulators(accumsToMerge, ctxtForInput(preMergeWindowedValue));
    WindowedValue<AccumT> postMergeWindowedValue = preMergeWindowedValue.withValue(accumulated);
    output.add(postMergeWindowedValue);

    return output;
}

From source file:org.apache.abdera2.common.protocol.ClientResponseImpl.java

public <T> Iterable<T> getHeaders(String name, Function<String, T> transform) {
    Iterable<Object> objs = getHeaders(name);
    List<T> list = new ArrayList<T>();
    for (Object obj : objs)
        list.add(transform.apply(obj.toString()));
    return Iterables.unmodifiableIterable(list);
}

From source file:org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleNlriRegistry.java

@Override
public Iterable<NlriSerializer> getSerializers() {
    return Iterables.unmodifiableIterable(this.serializers.values());
}

From source file:ninja.leaping.permissionsex.backend.file.FileDataStore.java

@Override
public Iterable<String> getAllRankLadders() {
    return Iterables.unmodifiableIterable(
            Iterables.transform(getRankLaddersNode().getChildrenMap().keySet(), Object::toString));
}

From source file:org.apache.beam.runners.spark.translation.SparkKeyedCombineFn.java

/**
 * Implements Spark's mergeCombiners function in:
 * <p>/*from  w ww  .  j a v a 2s . c  o m*/
 * {@link org.apache.spark.rdd.PairRDDFunctions#combineByKey}.
 * </p>
 */
Iterable<WindowedValue<KV<K, AccumT>>> mergeCombiners(Iterable<WindowedValue<KV<K, AccumT>>> a1,
        Iterable<WindowedValue<KV<K, AccumT>>> a2) {
    // concatenate accumulators.
    Iterable<WindowedValue<KV<K, AccumT>>> accumulators = Iterables.concat(a1, a2);

    // sort accumulators, no need to explode since inputs were exploded.
    Iterable<WindowedValue<KV<K, AccumT>>> sortedAccumulators = sortByWindows(accumulators);

    @SuppressWarnings("unchecked")
    TimestampCombiner timestampCombiner = windowingStrategy.getTimestampCombiner();

    //--- accumulators iterator, by window order.
    final Iterator<WindowedValue<KV<K, AccumT>>> iterator = sortedAccumulators.iterator();

    // get the first accumulator and assign it to the current window's accumulators.
    WindowedValue<KV<K, AccumT>> currentValue = iterator.next();
    K key = currentValue.getValue().getKey();
    BoundedWindow currentWindow = Iterables.getFirst(currentValue.getWindows(), null);
    List<AccumT> currentWindowAccumulators = Lists.newArrayList();
    currentWindowAccumulators.add(currentValue.getValue().getValue());

    // keep track of the timestamps assigned by the TimestampCombiner,
    // in createCombiner we already merge the timestamps assigned
    // to individual elements, here we will just merge them.
    List<Instant> windowTimestamps = Lists.newArrayList();
    windowTimestamps.add(currentValue.getTimestamp());

    // accumulate the next windows, or output.
    List<WindowedValue<KV<K, AccumT>>> output = Lists.newArrayList();

    // if merging, merge overlapping windows, e.g. Sessions.
    final boolean merging = !windowingStrategy.getWindowFn().isNonMerging();

    while (iterator.hasNext()) {
        WindowedValue<KV<K, AccumT>> nextValue = iterator.next();
        BoundedWindow nextWindow = Iterables.getOnlyElement(nextValue.getWindows());

        boolean mergingAndIntersecting = merging
                && isIntersecting((IntervalWindow) currentWindow, (IntervalWindow) nextWindow);

        if (mergingAndIntersecting || nextWindow.equals(currentWindow)) {
            if (mergingAndIntersecting) {
                // merge intersecting windows.
                currentWindow = merge((IntervalWindow) currentWindow, (IntervalWindow) nextWindow);
            }
            // add to window accumulators.
            currentWindowAccumulators.add(nextValue.getValue().getValue());
            windowTimestamps.add(nextValue.getTimestamp());
        } else {
            // before moving to the next window,
            // add the current accumulation to the output and initialize the accumulation.

            // merge the timestamps of all accumulators to merge.
            Instant mergedTimestamp = timestampCombiner.merge(currentWindow, windowTimestamps);

            // merge accumulators.
            // transforming a KV<K, Iterable<AccumT>> into a KV<K, Iterable<AccumT>>.
            // for the (possibly merged) window.
            Iterable<AccumT> accumsToMerge = Iterables.unmodifiableIterable(currentWindowAccumulators);
            WindowedValue<KV<K, Iterable<AccumT>>> preMergeWindowedValue = WindowedValue
                    .of(KV.of(key, accumsToMerge), mergedTimestamp, currentWindow, PaneInfo.NO_FIRING);
            // applying the actual combiner onto the accumulators.
            AccumT accumulated = combineFn.mergeAccumulators(accumsToMerge,
                    ctxtForInput(preMergeWindowedValue));
            WindowedValue<KV<K, AccumT>> postMergeWindowedValue = preMergeWindowedValue
                    .withValue(KV.of(key, accumulated));
            // emit the accumulated output.
            output.add(postMergeWindowedValue);

            // re-init accumulator, window and timestamps.
            currentWindowAccumulators.clear();
            currentWindowAccumulators.add(nextValue.getValue().getValue());
            currentWindow = nextWindow;
            windowTimestamps.clear();
            windowTimestamps.add(nextValue.getTimestamp());
        }
    }

    // merge the last chunk of accumulators.
    Instant mergedTimestamp = timestampCombiner.merge(currentWindow, windowTimestamps);
    Iterable<AccumT> accumsToMerge = Iterables.unmodifiableIterable(currentWindowAccumulators);
    WindowedValue<KV<K, Iterable<AccumT>>> preMergeWindowedValue = WindowedValue.of(KV.of(key, accumsToMerge),
            mergedTimestamp, currentWindow, PaneInfo.NO_FIRING);
    AccumT accumulated = combineFn.mergeAccumulators(accumsToMerge, ctxtForInput(preMergeWindowedValue));
    WindowedValue<KV<K, AccumT>> postMergeWindowedValue = preMergeWindowedValue
            .withValue(KV.of(key, accumulated));
    output.add(postMergeWindowedValue);

    return output;
}

From source file:edu.mit.streamjit.util.bytecode.types.TypeFactory.java

/**
 * Returns all the types created by this TypeFactory.  There are no
 * guarantees on iteration order.  Calling methods on this TypeFactory while
 * the iteration is in progress may result in
 * ConcurrentModificationException.  Types present during one iteration may
 * not be present during another, depending on this TypeFactory's caching
 * policy./*  w  w  w  .  j  a  va  2 s  .c  om*/
 * @return an iterator over Types created by this TypeFactory
 */
@Override
@SuppressWarnings("unchecked") //TODO: remove when Guava uses @SafeVarargs (Guava issue 1073)
public Iterator<Type> iterator() {
    return Iterables.unmodifiableIterable(Iterables.<Type>concat(typeMap.values(), methodTypes,
            staticFieldTypes, instanceFieldTypes, ImmutableList.of(basicBlockType, nullType))).iterator();
}

From source file:org.lanternpowered.server.inventory.AbstractChildrenInventory.java

@SuppressWarnings("unchecked")
@Override/*  w w  w .j a va2s.  c o m*/
public <T extends Inventory> Iterable<T> slots() {
    return (Iterable) Iterables.unmodifiableIterable(getSlotInventories());
}

From source file:org.graylog2.plugin.Message.java

public Iterable<Map.Entry<String, Object>> getFieldsEntries() {
    return Iterables.unmodifiableIterable(fields.entrySet());
}