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:org.eclipse.sirius.diagram.sequence.ui.tool.internal.layout.SequenceGraphicalHelper.java

/**
 * Finds and returns the InstanceRole semantic element which corresponds to
 * the first element graphically above the specified X coordinate in a
 * diagram.//from   w  w  w .j av  a  2s . co m
 * 
 * @param diagram
 *            the diagram.
 * @param x
 *            the X coordinate (in logical space)
 * @return the element which corresponds to the first InstanceRole above X.
 */
public static EObject getInstanceRoleBefore(SequenceDDiagram diagram, int x) {
    Iterable<Diagram> diagramViews = Iterables.filter(
            ISequenceElementAccessor.getViewsForSemanticElement(diagram, diagram.getTarget()), Diagram.class);
    if (!Iterables.isEmpty(diagramViews)) {
        Option<SequenceDiagram> seqDiag = ISequenceElementAccessor
                .getSequenceDiagram(diagramViews.iterator().next());
        if (seqDiag.some()) {
            for (InstanceRole ir : Lists.reverse(seqDiag.get().getSortedInstanceRole())) {
                int pos = ir.getProperLogicalBounds().x;
                if (pos <= x) {
                    return ir.getSemanticTargetElement().get();
                }
            }
        }
    }
    return null;
}

From source file:de.marx_labs.utilities.common.searchtree.MapSearchTree.java

@Override
public Set<T> findOld(Long term, int size) {
    Set<T> matches = new LinkedHashSet<T>();
    Long key = lowerKey(term);//from   www  .  j ava  2  s .  c  o m
    for (int i = 0; i < size; i++) {
        matches.add(get(key));
        key = lowerKey(key);

        if (key == null) {
            break;
        }
    }
    List<T> reverseList = Lists.reverse(Lists.newArrayList(matches));

    return Sets.newLinkedHashSet(reverseList);
}

From source file:org.fenixedu.spaces.domain.Space.java

/**
 * get all information beans//from w w  w .  j  av a 2s  . c om
 * 
 * @return information beans ordered by date (ascending)
 * @author cfscosta
 */
public List<InformationBean> timeline() {
    List<InformationBean> timeline = new ArrayList<>();
    Information current = getCurrent();
    while (current != null) {
        timeline.add(Information.builder(current).bean());
        current = current.getPrevious();
    }
    return Lists.reverse(timeline);
}

From source file:com.ning.billing.osgi.bundles.analytics.dao.factory.BusinessOverdueStatusFactory.java

private Collection<BusinessOverdueStatusModelDao> createBusinessOverdueStatusesForBundle(final UUID accountId,
        final SubscriptionBundle subscriptionBundle, final CallContext context)
        throws AnalyticsRefreshException {
    final Account account = getAccount(accountId, context);

    final Collection<BusinessOverdueStatusModelDao> businessOverdueStatuses = new LinkedList<BusinessOverdueStatusModelDao>();

    final List<BlockingState> blockingStatesOrdered = getBlockingHistory(subscriptionBundle.getId(), context);
    if (blockingStatesOrdered.size() == 0) {
        return businessOverdueStatuses;
    }/*from  ww  w  .  j  a v a2  s  . c o m*/

    final Long accountRecordId = getAccountRecordId(account.getId(), context);
    final Long tenantRecordId = getTenantRecordId(context);
    final ReportGroup reportGroup = getReportGroup(account.getId(), context);

    final List<BlockingState> blockingStates = Lists
            .reverse(ImmutableList.<BlockingState>copyOf(blockingStatesOrdered));
    DateTime previousStartDate = null;
    for (final BlockingState state : blockingStates) {
        final Long blockingStateRecordId = getBlockingStateRecordId(state.getId(), context);
        final AuditLog creationAuditLog = getBlockingStateCreationAuditLog(state.getId(), context);
        final BusinessOverdueStatusModelDao overdueStatus = new BusinessOverdueStatusModelDao(account,
                accountRecordId, subscriptionBundle, state, blockingStateRecordId, previousStartDate,
                creationAuditLog, tenantRecordId, reportGroup);
        businessOverdueStatuses.add(overdueStatus);
        previousStartDate = state.getTimestamp();
    }

    return businessOverdueStatuses;
}

From source file:org.gradle.api.internal.tasks.testing.logging.AbstractTestLogger.java

private String getEventPath(TestDescriptor descriptor) {
    List<String> names = Lists.newArrayList();
    TestDescriptor current = descriptor;
    while (current != null) {
        if (isAtomicTestWhoseParentIsNotTheTestClass(current)) {
            // This deals with the fact that in TestNG, there are no class-level events,
            // but we nevertheless want to see the class name. We use "." rather than
            // " > " as a separator to make it clear that the class is not a separate
            // level. This matters when configuring granularity.
            names.add(current.getClassName() + "." + current.getName());
        } else {/*ww  w  . j av a  2s.  co  m*/
            names.add(current.getName());
        }
        current = current.getParent();
    }

    int effectiveDisplayGranularity = displayGranularity == -1 ? names.size() - 1
            : Math.min(displayGranularity, names.size() - 1);
    List<String> displayedNames = Lists.reverse(names).subList(effectiveDisplayGranularity, names.size());
    return Joiner.on(" > ").join(displayedNames) + " ";
}

From source file:com.google.template.soy.passes.RewriteGenderMsgsPass.java

private void maybeRewriteNode(MsgNode msg, IdGenerator nodeIdGen) {
    List<ExprRootNode> genderExprs = msg.getAndRemoveGenderExprs();
    if (genderExprs == null) {
        return; // not a msg that this pass should rewrite
    }/* w w  w.  j  a  v  a  2  s . com*/

    // ------ Do the rewrite. ------

    // Note: We process the genders in reverse order so that the first listed gender will end up
    // being the outermost 'select' level.
    genderExprs = Lists.reverse(genderExprs);

    Checkpoint checkpoint = errorReporter.checkpoint();
    List<String> baseSelectVarNames = MsgSubstUnitBaseVarNameUtils.genNoncollidingBaseNamesForExprs(
            ExprRootNode.unwrap(genderExprs), FALLBACK_BASE_SELECT_VAR_NAME, errorReporter);
    if (errorReporter.errorsSince(checkpoint)) {
        return; // To prevent an IndexOutOfBoundsException below.
    }

    for (int i = 0; i < genderExprs.size(); i++) {
        ExprRootNode genderExpr = genderExprs.get(i);
        String baseSelectVarName = baseSelectVarNames.get(i);

        // Check whether the generated base name would be the same (both for the old naive algorithm
        // and the new algorithm). If so, then there's no need to specify the baseSelectVarName.
        if (MsgSubstUnitBaseVarNameUtils
                .genNaiveBaseNameForExpr(genderExpr.getRoot(), FALLBACK_BASE_SELECT_VAR_NAME)
                .equals(baseSelectVarName)
                && MsgSubstUnitBaseVarNameUtils
                        .genShortestBaseNameForExpr(genderExpr.getRoot(), FALLBACK_BASE_SELECT_VAR_NAME)
                        .equals(baseSelectVarName)) {
            baseSelectVarName = null;
        }

        splitMsgForGender(msg, genderExpr, baseSelectVarName, nodeIdGen);
    }

    // ------ Verify from the re-written msg that gender restrictions are followed. ------

    checkExceedsMaxGenders((MsgSelectNode) msg.getChild(0), 1);
}

From source file:org.apache.hadoop.hbase.regionserver.DefaultStoreFileManager.java

@Override
public final Iterator<StoreFile> getCandidateFilesForRowKeyBefore(final KeyValue targetKey) {
    return new ArrayList<StoreFile>(Lists.reverse(this.storefiles)).iterator();
}

From source file:com.codebullets.sagalib.processing.invocation.ModulesInvoker.java

/**
 * Execute error method on started modules.
 *//* ww w . j a  v  a2s .c  o m*/
public void error(final Object message, final Throwable error) {
    Lists.reverse(errorHandlers).forEach(f -> f.accept(message, error));
}

From source file:juicebox.tools.utils.juicer.arrowhead.BlockResults.java

/**
 * calculate D upstream, directionality index upstream
 *
 * @param observed//from  ww w  . j a va2  s .  c  o  m
 * @param n
 * @param gap
 * @return dUpstream
 */
private RealMatrix calculateDirectionalityIndexUpstream(RealMatrix observed, int n, int gap) {

    RealMatrix dUpstream = MatrixTools.cleanArray2DMatrix(n);

    for (int i = 0; i < n; i++) {
        // choose smaller window of two: from 0 to (i-gap) or from (i+gap) to n
        int window = Math.min(n - (i + gap), i - gap);
        window = Math.min(window, n);

        if (window >= gap) {
            double[] row = observed.getRow(i);

            // in MATLAB second index inclusive, but for java need +1
            double[] A = Doubles
                    .toArray(Lists.reverse(Doubles.asList(Arrays.copyOfRange(row, i - window, i - gap + 1))));
            double[] B = Arrays.copyOfRange(row, i + gap, i + window + 1);

            double[] preference = new double[A.length];
            for (int j = 0; j < A.length; j++) {
                preference[j] = (A[j] - B[j]) / (A[j] + B[j]);
            }

            int index = 0;
            for (int j = i + gap; j < i + window + 1; j++) {
                dUpstream.setEntry(i, j, preference[index]);
                index++;
            }
        }
    }
    return dUpstream;
}

From source file:com.github.fge.jsonpatch.diff.LCS.java

/**
 * Compute longest common subsequence out of two lists
 *
 * <p>When entering this function, both lists are trimmed from their
 * common leading and trailing nodes.</p>
 *
 * @param l1 the first list//  w ww .j a  va 2  s.c o  m
 * @param l2 the second list
 * @return the longest common subsequence
 */
private static List<JsonNode> doLCS(final List<JsonNode> l1, final List<JsonNode> l2) {
    final List<JsonNode> lcs = Lists.newArrayList();
    // construct LCS lengths matrix
    final int size1 = l1.size();
    final int size2 = l2.size();
    final int[][] lengths = new int[size1 + 1][size2 + 1];

    JsonNode node1;
    JsonNode node2;
    int len;

    for (int i = 0; i < size1; i++)
        for (int j = 0; j < size2; j++) {
            node1 = l1.get(i);
            node2 = l2.get(j);
            len = EQUIVALENCE.equivalent(node1, node2) ? lengths[i][j] + 1
                    : Math.max(lengths[i + 1][j], lengths[i][j + 1]);
            lengths[i + 1][j + 1] = len;
        }

    // return result out of the LCS lengths matrix
    int x = size1, y = size2;
    while (x > 0 && y > 0) {
        if (lengths[x][y] == lengths[x - 1][y])
            x--;
        else if (lengths[x][y] == lengths[x][y - 1])
            y--;
        else {
            lcs.add(l1.get(x - 1));
            x--;
            y--;
        }
    }
    return Lists.reverse(lcs);
}