Example usage for com.google.common.collect ImmutableList subList

List of usage examples for com.google.common.collect ImmutableList subList

Introduction

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

Prototype

@Override
    public ImmutableList<E> subList(int fromIndex, int toIndex) 

Source Link

Usage

From source file:org.glowroot.local.store.QueryResult.java

static <T extends /*@NonNull*/Object> QueryResult<T> from(ImmutableList<T> records, int limit) {
    if (limit == 0) {
        return new QueryResult<T>(records, false);
    } else if (records.size() > limit) {
        return new QueryResult<T>(records.subList(0, limit), true);
    } else {/*from   w  w  w  .j av  a2 s .  c  o m*/
        return new QueryResult<T>(records, false);
    }
}

From source file:com.github.rinde.logistics.pdptw.solver.CheapestInsertionHeuristic.java

static ImmutableList<Double> modifyCosts(ImmutableList<Double> costs, double newCost, int index) {
    return ImmutableList.<Double>builder().addAll(costs.subList(0, index)).add(newCost)
            .addAll(costs.subList(index + 1, costs.size())).build();
}

From source file:com.mycompany.mavenproject3.List.java

public static Cons makeCons(ImmutableList<Sexpression> list) {
    if (list.isEmpty()) {
        return new Nil();
    } else if (list.size() == 1) {
        return new Cons(list.get(0), new Nil());
    } else {/*from w  w w.  j  a v a2 s  .  c o  m*/
        Sexpression head = list.get(0);
        ImmutableList<Sexpression> tail = list.subList(1, list.size() - 1);
        return new Cons(head, makeCons(tail));
    }
}

From source file:com.mycompany.mavenproject3.Interpreter.java

public static Cons makeListHelp(ImmutableList<Sexpression> list) {
    //        ImmutableList<Sexpression> list = ImmutableList.copyOf(sexpressions);
    if (list.isEmpty()) {
        return new Nil();
    }/*from  w  w  w . j  av a2 s  .c  o m*/
    if (list.size() == 1) {
        return new Cons(list.get(0), new Nil());
    } else {
        return new Cons(list.get(0), makeListHelp(list.subList(1, list.size() - 1)));
    }
}

From source file:com.facebook.buck.model.BuildFileTree.java

/**
 * Finds the parent Node of the specified child Node.
 * @param child whose parent is sought in {@code basePathToNodeIndex}.
 * @param basePathToNodeIndex Map that must contain a Node with a basePath that is a prefix of
 *     {@code child}'s basePath.// www . j  a  v a 2  s.  c om
 * @return the Node in {@code basePathToNodeIndex} with the longest basePath that is a prefix of
 *     {@code child}'s basePath.
 */
private static Node findParent(Node child, Map<String, Node> basePathToNodeIndex) {
    ImmutableList<String> parts = ImmutableList.copyOf(child.basePath.split("/"));
    for (int numParts = parts.size() - 1; numParts > 0; numParts--) {
        List<String> partsCandidate = parts.subList(0, numParts);
        String candidateBasePath = PATH_JOINER.join(partsCandidate);
        Node candidate = basePathToNodeIndex.get(candidateBasePath);
        if (candidate != null) {
            return candidate;
        }
    }

    return basePathToNodeIndex.get("");
}

From source file:org.geogit.api.NodeRef.java

public static String removeParent(final String parentPath, final String childPath) {
    checkArgument(isChild(parentPath, childPath));
    ImmutableList<String> parent = split(parentPath);
    ImmutableList<String> child = split(childPath);
    child = child.subList(parent.size(), child.size());
    String strippedChildPath = child.get(0);
    for (int i = 1; i < child.size(); i++) {
        appendChild(strippedChildPath, child.get(i));
    }/* w w  w  .j a v  a  2  s .  co m*/
    return strippedChildPath;
}

From source file:com.google.template.soy.incrementaldomsrc.RemoveUnnecessaryEscapingDirectives.java

private static ImmutableList<SoyPrintDirective> filterEscapingDirectives(
        ImmutableList<SoyPrintDirective> escapingDirectives) {
    for (int i = 0; i < escapingDirectives.size(); i++) {
        SoyPrintDirective directive = escapingDirectives.get(i);
        if (canSkip(directive)) {
            ImmutableList.Builder<SoyPrintDirective> builder = ImmutableList.builder();
            builder.addAll(escapingDirectives.subList(0, i));
            for (; i < escapingDirectives.size(); i++) {
                directive = escapingDirectives.get(i);
                if (!canSkip(directive)) {
                    builder.add(directive);
                }//from  w  w  w. j  a  v a  2s. c o  m
            }
            return builder.build();
        }
    }
    return escapingDirectives;
}

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

private static List<Class<?>> getParameterTypes(Class<?>... types) {
    ImmutableList<Class<?>> parameterTypes = ImmutableList.copyOf(types);
    if (!parameterTypes.isEmpty() && parameterTypes.get(0) == ConnectorSession.class) {
        parameterTypes = parameterTypes.subList(1, parameterTypes.size());
    }/* ww  w. j  ava  2 s .c  om*/
    return parameterTypes;
}

From source file:org.locationtech.geogig.repository.NodeRef.java

/**
 * Remove the parent path from the given child path.
 * // ww w.  ja v  a2s  . c  o  m
 * @param parentPath the parent path to remove
 * @param childPath the child path to remove from
 * @return the stripped child path
 */
public static String removeParent(final String parentPath, final String childPath) {
    checkArgument(isChild(parentPath, childPath));
    ImmutableList<String> parent = split(parentPath);
    ImmutableList<String> child = split(childPath);
    child = child.subList(parent.size(), child.size());
    String strippedChildPath = child.get(0);
    for (int i = 1; i < child.size(); i++) {
        strippedChildPath = appendChild(strippedChildPath, child.get(i));
    }
    return strippedChildPath;
}

From source file:com.google.api.tools.framework.aspects.http.RestAnalyzer.java

static RestMethod createCustomMethod(Method method, HttpAttribute httpConfig, String customNamePrefix) {
    ImmutableList<PathSegment> path = httpConfig.getFlatPath();
    PathSegment lastSegment = path.get(path.size() - 1);

    // Determine base name.
    String customName = "";
    if (lastSegment instanceof LiteralSegment) {
        customName = ((LiteralSegment) lastSegment).getLiteral();
        path = path.subList(0, path.size() - 1);
    } else {//  w  w  w  .j a v a  2  s  .  co m
        if (method.getModel().getConfigVersion() > 1) {
            // From version 2 on, we generate a meaningful name here.
            customName = method.getSimpleName();
        } else if (customNamePrefix.isEmpty()) {
            // Older versions use the prefix or derive from the http method.
            customName = httpConfig.getMethodKind().toString().toLowerCase();
        }
    }

    // Prepend prefix.
    if (!customNamePrefix.isEmpty() && !customName.toLowerCase().startsWith(customNamePrefix.toLowerCase())) {
        customName = customNamePrefix + ensureUpperCase(customName);
    }

    // Ensure effective start is lower case.
    customName = ensureLowerCase(customName);

    return RestMethod.create(method, RestKind.CUSTOM, buildCollectionName(path), customName);
}