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.slc.sli.dal.convert.AssessmentConverter.java

/**
 * Construct the assessmentFamilyHierarchy string from the assessment family reference
 */// w w  w  . j  a  v  a  2s.c  o m
private void addFamilyHierarchy(Entity entity) {
    Object object = entity.getBody().remove(ASSESSMENT_FAMILY_REFERENCE);
    if (object == null || !(object instanceof String)) {
        // we don't validate assessmentFamilyHierarchy any more, so someone could have passed in
        // an object, array, number, etc.
        return;
    }
    String familyRef = (String) object;
    MongoTemplate mongo = ((MongoEntityRepository) repo).getTemplate();
    Entity family = mongo.findById(familyRef, Entity.class, ASSESSMENT_FAMILY);

    List<String> familyTitles = new LinkedList<String>();
    Set<String> seenFamilyRefs = new HashSet<String>();
    seenFamilyRefs.add(familyRef);
    while (family != null) {
        String familyTitle = (String) family.getBody().get(ASSESSMENT_FAMILY_TITLE);
        if (familyTitle == null) {
            LOG.error("Required assessmentFamilyTitle is null for assessmentFamily with _id : {}",
                    new Object[] { family.getEntityId() });
            break;
        }
        familyTitles.add(familyTitle);
        String parentRef = (String) family.getBody().get(ASSESSMENT_FAMILY_ASSESSMENT_FAMILY_REFERENCE);
        family = null;

        if (parentRef != null) {
            if (!seenFamilyRefs.contains(parentRef)) {
                family = mongo.findById(parentRef, Entity.class, ASSESSMENT_FAMILY);
                seenFamilyRefs.add(parentRef);
            } else {
                LOG.error(
                        "Circular reference detected in assessment family hierarchy. _id : {} occurs twice in hierarchy.",
                        new Object[] { parentRef });
            }
        }
    }

    String familyHierarchyString = Joiner.on(".").join(Lists.reverse(familyTitles));
    entity.getBody().put(ASSESSMENT_FAMILY_HIERARCHY, familyHierarchyString);
}

From source file:com.topsem.common.repository.plugin.serivce.BaseTreeableService.java

/**
 * /* ww  w  .j a  v  a 2s  .  co  m*/
 *
 * @param parentIds
 * @return
 */
public List<M> findAncestor(String parentIds) {
    if (StringUtils.isEmpty(parentIds)) {
        return Collections.EMPTY_LIST;
    }
    String[] ids = StringUtils.tokenizeToStringArray(parentIds, "/");
    return Lists.reverse(findAll(Query.where("id", Query.Filter.Operator.IN, ids)));
}

From source file:com.facebook.presto.metadata.DatabaseLocalStorageManager.java

/**
 * Generate a file system path for a shard id. This creates a four level deep, two digit directory
 * where the least significant digits are the first level, the next significant digits are the second
 * and so on. Numbers that have more than eight digits are lumped together in the last level.
 * <p/>/* ww w .  j  a  v a  2s .  c o m*/
 * <pre>
 *   1 --> 01/00/00/00
 *   1000 -> 00/10/00/00
 *   123456 -> 56/34/12/00
 *   4815162342 -> 42/23/16/4815
 * </pre>
 * <p/>
 * This ensures that files are spread out evenly through the tree while a path can still be easily navigated
 * by a human being.
 */
@VisibleForTesting
static File getShardPath(File baseDir, long shardId) {
    Preconditions.checkArgument(shardId >= 0, "shardId must be >= 0");

    String value = format("%08d", shardId);
    int split = value.length() - 6;
    List<String> pathElements = ImmutableList
            .copyOf(Splitter.fixedLength(2).limit(3).split(value.substring(split)));
    String path = Joiner.on('/').join(Lists.reverse(pathElements)) + "/" + value.substring(0, split);
    return new File(baseDir, path);
}

From source file:com.haulmont.cuba.core.sys.MetadataImpl.java

protected List<Method> getPostConstructMethodsNotCached(Class<?> clazz) {
    List<Method> postConstructMethods = Collections.emptyList();
    List<String> methodNames = Collections.emptyList();

    while (clazz != Object.class) {
        Method[] classMethods = clazz.getDeclaredMethods();
        for (Method method : classMethods) {
            if (method.isAnnotationPresent(PostConstruct.class) && !methodNames.contains(method.getName())) {
                if (postConstructMethods.isEmpty()) {
                    postConstructMethods = new ArrayList<>();
                }/* w  w  w  .  j av  a  2s .c  o  m*/
                postConstructMethods.add(method);

                if (methodNames.isEmpty()) {
                    methodNames = new ArrayList<>();
                }
                methodNames.add(method.getName());
            }
        }

        Class[] interfaces = clazz.getInterfaces();
        for (Class interfaceClazz : interfaces) {
            Method[] interfaceMethods = interfaceClazz.getDeclaredMethods();
            for (Method method : interfaceMethods) {
                if (method.isAnnotationPresent(PostConstruct.class) && method.isDefault()
                        && !methodNames.contains(method.getName())) {
                    if (postConstructMethods.isEmpty()) {
                        postConstructMethods = new ArrayList<>();
                    }
                    postConstructMethods.add(method);

                    if (methodNames.isEmpty()) {
                        methodNames = new ArrayList<>();
                    }
                    methodNames.add(method.getName());
                }
            }
        }

        clazz = clazz.getSuperclass();
    }

    for (Method method : postConstructMethods) {
        if (!method.isAccessible()) {
            method.setAccessible(true);
        }
    }

    return postConstructMethods.isEmpty() ? Collections.emptyList()
            : ImmutableList.copyOf(Lists.reverse(postConstructMethods));
}

From source file:com.daphne.es.common.plugin.serivce.BaseTreeableService.java

/**
 * //w  w  w  .j  a va  2 s.com
 *
 * @param parentIds
 * @return
 */
public List<M> findAncestor(String parentIds) {
    if (StringUtils.isEmpty(parentIds)) {
        return Collections.EMPTY_LIST;
    }
    String[] ids = StringUtils.tokenizeToStringArray(parentIds, "/");

    return Lists.reverse(
            findAllWithNoPageNoSort(Searchable.newSearchable().addSearchFilter("id", SearchOperator.in, ids)));
}

From source file:org.obeonetwork.m2doc.tplconf.TemplateConfigUtil.java

/**
 * Store the given template configuration into the given document.
 * /*from  ww  w  .jav  a 2s . c o  m*/
 * @param config
 *            The configuration to store
 * @param xwpfDocument
 *            The document the custom properties of which will be used to store the configuration
 */
public static void store(TemplateConfig config, XWPFDocument xwpfDocument) {
    // Metamodel URIs
    StringBuilder b = new StringBuilder(1000);
    for (EPackageMapping mm : config.getMappings()) {
        b.append(M2DocCustomProperties.SERVICETOKEN_SEPARATOR).append(mm.getUri());
    }
    b.deleteCharAt(0);
    CustomProperties customProperties = xwpfDocument.getProperties().getCustomProperties();
    if (customProperties.contains(M2DocCustomProperties.URI_PROPERTY_PREFIX)) {
        CTProperty uriProp = customProperties.getProperty(M2DocCustomProperties.URI_PROPERTY_PREFIX);
        uriProp.setLpwstr(b.toString());
    } else {
        customProperties.addProperty(M2DocCustomProperties.URI_PROPERTY_PREFIX, b.toString());
    }

    List<Integer> indicesToRemove = new ArrayList<Integer>();
    // Delete former variables
    List<CTProperty> propertyList = customProperties.getUnderlyingProperties().getPropertyList();
    for (int i = 0; i < propertyList.size(); i++) {
        CTProperty prop = propertyList.get(i);
        if (prop.getName() != null
                && prop.getName().startsWith(M2DocCustomProperties.VAR_PROPERTY_PREFIX + ":")) {
            indicesToRemove.add(i);
        }
    }
    for (Integer indexToRemove : Lists.reverse(indicesToRemove)) {
        customProperties.getUnderlyingProperties().removeProperty(indexToRemove.intValue());
    }

    // Variables
    for (TemplateVariable var : config.getVariables()) {
        String name = var.getName();
        String typeName = var.getTypeName();
        String key = M2DocCustomProperties.VAR_PROPERTY_PREFIX + ":" + name;
        if (customProperties.contains(key)) {
            customProperties.getProperty(key).setLpwstr(typeName);
        } else {
            customProperties.addProperty(key, typeName);
        }
    }
}

From source file:org.glowroot.weaving.WeavingMethodVisitor.java

@Override
public void visitMaxs(int maxStack, int maxLocals) {
    Label onCatchEndLabel = new Label();
    if (needsOnThrow) {
        visitLabel(onCatchEndLabel);//from  w  ww  . j  a v a  2s . c  o  m
    }
    // returnOpCode can be null if only ATHROW in method in which case method doesn't need
    // onReturn advice
    if (needsOnReturn && returnOpcode != null) {
        checkNotNull(onReturnLabel, "Call to onMethodEnter() is required");
        visitLabel(onReturnLabel);
        for (Advice advice : Lists.reverse(advisors)) {
            visitOnReturnAdvice(advice, returnOpcode);
            visitOnAfterAdvice(advice);
        }
        resetAdviceFlowIfNecessary();
        // need to call super.visitInsn() in order to avoid infinite loop
        // could call mv.visitInsn(), but that would bypass special constructor handling in
        // AdviceAdapter.visitInsn()
        super.visitInsn(returnOpcode);
    }
    if (needsOnThrow) {
        checkNotNull(onCatchStartLabel, "Call to onMethodEnter() is required");
        Label onCatchHandlerLabel = new Label();
        visitTryCatchBlock(onCatchStartLabel, onCatchEndLabel, onCatchHandlerLabel, "java/lang/Throwable");
        visitLabel(onCatchHandlerLabel);
        visitOnThrowAdvice();
        for (Advice advice : Lists.reverse(advisors)) {
            visitOnAfterAdvice(advice);
        }
        resetAdviceFlowIfNecessary();
        visitInsn(ATHROW);
    }
    super.visitMaxs(maxStack, maxLocals);
}

From source file:com.luna.common.plugin.serivce.BaseTreeableService.java

/**
 * //from www . jav  a2s .co  m
 *
 * @param parentIds
 * @return
 */
public List<M> findAncestor(String parentIds) {
    if (StringUtils.isEmpty(parentIds)) {
        return Collections.emptyList();
    }
    String[] ids = StringUtils.tokenizeToStringArray(parentIds, "/");

    return Lists.reverse(
            findAllWithNoPageNoSort(Searchable.newSearchable().addSearchFilter("id", SearchOperator.in, ids)));
}

From source file:de.uni_potsdam.hpi.asg.delaymatch.trace.ParallelTraceDetector.java

private List<Box> getTransitiveBox(SequenceBox start) {
    List<Box> retVal = new ArrayList<>();
    Box next = start;/*from   www  . j  ava 2s  . co  m*/
    while (next != null) {
        retVal.add(next);
        next = next.getSuperBox();
    }
    return Lists.reverse(retVal);
}