Example usage for com.google.common.collect Lists reverse

List of usage examples for com.google.common.collect Lists reverse

Introduction

In this page you can find the example usage for com.google.common.collect Lists reverse.

Prototype

@CheckReturnValue
public static <T> List<T> reverse(List<T> list) 

Source Link

Document

Returns a reversed view of the specified list.

Usage

From source file:net.sourceforge.docfetcher.util.collect.MemoryList.java

/**
 * Has the same effect as iterating <b>backwards</b> over the given
 * collection and calling {@link #add(Object)} for each element.
 * <p>/* w w  w . j a va2s  .c o  m*/
 * The purpose of iterating backwards is to allow clients to use this method
 * for initializing the receiver with the given collection, so that the
 * order of the elements in the receiver is the same as in the given
 * collection, i.e. from most to least recently accessed.
 * 
 * @see #add(Object)
 */
@SuppressWarnings("unchecked")
public boolean addAll(Collection<? extends E> c) {
    List<E> list = c instanceof List ? (List<E>) c : new ArrayList<E>(c);
    boolean changed = false;
    for (E e : Lists.reverse(list))
        changed |= add(e);
    return changed;
}

From source file:controllers.impl.proxy.api.Hocon.java

/**
 * Most specific config at the front.// ww w  .  ja  va 2  s .co m
 */
private Config combineHocons(final List<String> configs) {
    Config finalHocon = ConfigFactory.empty();
    final ConfigParseOptions parseOptions = ConfigParseOptions.defaults().setIncluder(new NoIncluder())
            .setAllowMissing(false);
    for (final String config : Lists.reverse(configs)) {
        finalHocon = ConfigFactory.parseString(config, parseOptions).withFallback(finalHocon);
    }
    return finalHocon;
}

From source file:com.puppetlabs.geppetto.ruby.jrubyparser.RubyCallFinder.java

public GenericCallNode findCall(Node root, String... qualifiedName) {
    if (qualifiedName.length < 1)
        throw new IllegalArgumentException("qualifiedName can not be empty");

    this.stack = Lists.newLinkedList();
    this.nameStack = Lists.newLinkedList();

    // OLD CODE, NOW FIXED
    // opportunity to make this better if guava a.k.a google.collect
    // 2.0 is used
    // since it has a Lists.reverse method - now this ugly construct is
    // used./*w  w w.  j  a va2s .  c  om*/
    // OLD CODE
    // this.qualifiedName = Lists.newArrayList(Iterables.reverse(Lists
    // .newArrayList(qualifiedName)));
    this.qualifiedName = Lists.reverse(Lists.newArrayList(qualifiedName));

    List<GenericCallNode> result = findCallInternal(root, true);
    return result == null || result.size() != 1 ? null : result.get(0);
}

From source file:org.sosy_lab.cpachecker.cpa.callstack.CallstackState.java

/** for logging and debugging */
private List<String> getStack() {
    final List<String> stack = new ArrayList<>();
    CallstackState state = this;
    while (state != null) {
        stack.add(state.getCurrentFunction());
        state = state.getPreviousState();
    }//from   w ww  .j a va2  s  .  c  o  m
    return Lists.reverse(stack);
}

From source file:da.RequestJpaController.java

public List<Request> getRequests(String username, int type, int status) {
    TypedQuery<Request> query = getEntityManager().createQuery(
            "SELECT r FROM Request r WHERE r.requestAccount.username = :username AND r.type=:type AND r.status=:status ORDER BY r.time DESC",
            Request.class);
    query.setParameter("username", username);
    query.setParameter("type", type);
    query.setParameter("status", status);
    return Lists.reverse(query.getResultList());
}

From source file:org.hawkular.metrics.core.impl.cassandra.BucketedOutputMapper.java

@Override
public BucketedOutput<POINT> call(List<DATA> dataList) {
    BucketedOutput<POINT> output = new BucketedOutput<>(tenantId, id.getName(), Collections.emptyMap());
    output.setData(new ArrayList<>(buckets.getCount()));

    if (!(dataList instanceof RandomAccess)) {
        dataList = new ArrayList<>(dataList);
    }//ww  w. j a  v a 2  s  .  co m
    if (isDescending) {
        dataList = Lists.reverse(dataList); // We expect input data to be sorted in descending order
    }

    int dataIndex = 0;
    DATA previous;
    for (int bucketIndex = 0; bucketIndex < buckets.getCount(); bucketIndex++) {
        long from = buckets.getStart() + bucketIndex * buckets.getStep();
        long to = buckets.getStart() + (bucketIndex + 1) * buckets.getStep();

        if (dataIndex >= dataList.size()) {
            // Reached end of data points
            output.getData().add(newEmptyPointInstance(from, to));
            continue;
        }

        DATA current = dataList.get(dataIndex);
        if (current.getTimestamp() >= to) {
            // Current data point does not belong to this bucket
            output.getData().add(newEmptyPointInstance(from, to));
            continue;
        }

        List<DATA> metricDatas = new ArrayList<>();
        do {
            // Add current value to this bucket's summary
            metricDatas.add(current);

            // Move to next data point
            previous = current;
            dataIndex++;
            current = dataIndex < dataList.size() ? dataList.get(dataIndex) : null;

            //                checkOrder(previous, current);

            // Continue until end of data points is reached or data point does not belong to this bucket
        } while (current != null && current.getTimestamp() < to);

        output.getData().add(newPointInstance(from, to, metricDatas));
    }

    return output;
}

From source file:com.github.steveash.jg2p.align.Alignment.java

Alignment finish() {
    return new Alignment(input, Lists.reverse(this.graphones), score);
}

From source file:org.lightjason.agentspeak.action.buildin.collection.list.CReverse.java

@Override
public final IFuzzyValue<Boolean> execute(final IContext p_context, final boolean p_parallel,
        final List<ITerm> p_argument, final List<ITerm> p_return, final List<ITerm> p_annotation) {
    // all arguments are list references
    p_return.addAll(Lists.reverse(CCommon.flatcollection(p_argument).collect(Collectors.toList())));
    return CFuzzyValue.from(true);
}

From source file:com.rhythm.louie.service.ServiceUtils.java

/**
 * Load the service from the layer stack, assigning the lower layers as delegates
 * to the parent layers. If layers is empty, loading a default layer configuration
 * will be attempted.//from w w w.jav  a  2  s  .c om
 * 
 * Layers must all implement T.
 * The last layer must NOT implement Delegate&lt;T&gt;.
 * All other layers MUST implement Delegate&lt;T&gt;.
 * 
 * @param <T>
 * @param layers the list of layers to be loaded, if empty loads default layers
 * @param service the target implementation of the service layers
 * @return The first layer, loaded and linked to child delegates, if present
 * @throws Exception 
 */
@SuppressWarnings("unchecked")
public static <T> T loadService(List<ServiceLayer> layers, Class<T> service) throws Exception {
    // Handle unspecified layers differently, optionally loading the defaults
    boolean optionalLayers = false;
    if (layers == null || layers.isEmpty()) {
        layers = DEFAULT_LAYERS;
        optionalLayers = true;
    }

    // Traverse through the lists in reverse order, since you need to supply 
    // the lower layers to the parent delegate
    T resultLayer = null;
    for (ServiceLayer layer : Lists.reverse(layers)) {
        T currentLayer;
        try {
            currentLayer = layer.loadLayer(service);
        } catch (Exception e) {
            // if optional, just ignore this and attempt to load the next layer
            if (optionalLayers) {
                continue;
            }
            throw e;
        }

        // Ensure that the loaded layer is compatible
        if (!service.isAssignableFrom(currentLayer.getClass())) {
            throw new Exception(currentLayer.getClass().getName() + " does not implement " + service.getName());
        }

        // A previous layer was loaded, so this layer must be a delagate
        if (resultLayer != null) {
            if (!Delegate.class.isAssignableFrom(currentLayer.getClass())) {
                throw new Exception(currentLayer.getClass().getName() + " must implement Delegate<"
                        + service.getName() + ">");
            }
            for (Type genericInterface : currentLayer.getClass().getGenericInterfaces()) {
                if (genericInterface instanceof Delegate) {
                    Type[] genericTypes = ((ParameterizedType) genericInterface).getActualTypeArguments();
                    if (genericTypes.length != 1 || !service.isInstance(genericTypes[0])) {
                        throw new Exception(currentLayer.getClass().getName() + " must implement Delegate<"
                                + service.getName() + ">");
                    }
                    break;
                }
            }
            // Validated that this is Delegate<T> so should be safe now
            ((Delegate<T>) currentLayer).setDelegate(resultLayer);
        }
        resultLayer = currentLayer;
    }

    if (resultLayer == null) {
        throw new Exception("No service layers found for: " + service.getName());
    }
    return resultLayer;
}

From source file:cubicchunks.world.column.CubeMap.java

Iterable<Cube> cubes(int startY, int endY) {
    boolean reverse = false;
    if (startY > endY) {
        int i = startY;
        startY = endY;//from  w  w  w. j  a v a 2s.c  o m
        endY = i;
        reverse = true;
    }

    int bottom = binarySearch(startY);
    int top = binarySearch(endY + 1); // subList()'s second arg is exclusive so we need to add 1

    if (bottom < cubes.size() && top <= cubes.size()) {
        return reverse ? Lists.reverse(cubes.subList(bottom, top)) : cubes.subList(bottom, top);
    } else {
        return Collections.emptyList();
    }
}