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:brooklyn.entity.rebind.Dumpers.java

public static void logUnserializableChains(Object root, final ObjectReplacer replacer)
        throws IllegalArgumentException, IllegalAccessException {
    final Map<List<Object>, Class<?>> unserializablePaths = Maps.newLinkedHashMap();

    Visitor visitor = new Visitor() {
        @Override/* ww  w  .  j  a  v a2  s .  c  o  m*/
        public boolean visit(Object o, Iterable<Object> refChain) {
            try {
                Serializers.reconstitute(o, replacer);
                return true;
            } catch (Throwable e) {
                Exceptions.propagateIfFatal(e);

                // not serializable in some way: report
                ImmutableList<Object> refChainList = ImmutableList.copyOf(refChain);
                // for debugging it can be useful to turn this on
                //                    LOG.warn("Unreconstitutable object detected ("+o+"): "+e);

                // First strip out any less specific paths
                for (Iterator<List<Object>> iter = unserializablePaths.keySet().iterator(); iter.hasNext();) {
                    List<Object> existing = iter.next();
                    if (refChainList.size() >= existing.size()
                            && refChainList.subList(0, existing.size()).equals(existing)) {
                        iter.remove();
                    }
                }

                // Then add this list
                unserializablePaths.put(ImmutableList.copyOf(refChainList), o.getClass());
                return false;
            }
        }
    };
    deepVisitInternal(root, SERIALIZED_FIELD_PREDICATE, Lists.newArrayList(), new LinkedList<Object>(),
            visitor);

    LOG.warn("Not serializable (" + root + "):");
    for (Map.Entry<List<Object>, Class<?>> entry : unserializablePaths.entrySet()) {
        StringBuilder msg = new StringBuilder("\t" + "type=" + entry.getValue() + "; chain=" + "\n");
        for (Object chainElement : entry.getKey()) {
            // try-catch motivated by NPE in org.jclouds.domain.LoginCredentials.toString
            String chainElementStr;
            try {
                chainElementStr = chainElement.toString();
            } catch (Exception e) {
                Exceptions.propagateIfFatal(e);
                LOG.error("Error calling toString on instance of " + chainElement.getClass(), e);
                chainElementStr = "<error " + e.getClass().getSimpleName() + " in toString>";
            }
            msg.append("\t\t" + "type=").append(chainElement.getClass()).append("; val=")
                    .append(chainElementStr).append("\n");
        }
        LOG.warn(msg.toString());
    }
}

From source file:org.glowroot.agent.embedded.init.ConfigRepositoryImpl.java

private static ImmutableList<Integer> fix(ImmutableList<Integer> thisList, List<Integer> defaultList) {
    if (thisList.size() >= defaultList.size()) {
        return thisList.subList(0, defaultList.size());
    }/*from  ww  w .  j  a  v a  2 s. c  o  m*/
    List<Integer> correctedList = Lists.newArrayList(thisList);
    for (int i = thisList.size(); i < defaultList.size(); i++) {
        correctedList.add(defaultList.get(i));
    }
    return ImmutableList.copyOf(correctedList);
}

From source file:com.google.errorprone.bugpatterns.TypeParameterNaming.java

private static String suggestedNameFollowedWithT(String identifier) {
    Preconditions.checkArgument(!identifier.isEmpty());

    // Some early checks:
    // TFoo => FooT
    if (identifier.length() > 2 && identifier.charAt(0) == 'T' && Ascii.isUpperCase(identifier.charAt(1))
            && Ascii.isLowerCase(identifier.charAt(2))) {
        // splitToLowercaseTerms thinks "TFooBar" is ["tfoo", "bar"], so we remove "t", have it parse
        // as ["foo", "bar"], then staple "t" back on the end.
        ImmutableList<String> tokens = NamingConventions.splitToLowercaseTerms(identifier.substring(1));
        return Streams.concat(tokens.stream(), Stream.of("T")).map(TypeParameterNaming::upperCamelToken)
                .collect(Collectors.joining());
    }/*w  w  w. j  a  v a  2s  .  c om*/

    ImmutableList<String> tokens = NamingConventions.splitToLowercaseTerms(identifier);

    // UPPERCASE => UppercaseT
    if (tokens.size() == 1) {
        String token = tokens.get(0);
        if (Ascii.toUpperCase(token).equals(identifier)) {
            return upperCamelToken(token) + "T";
        }
    }

    // FooType => FooT
    if (Iterables.getLast(tokens).equals("type")) {
        return Streams.concat(tokens.subList(0, tokens.size() - 1).stream(), Stream.of("T"))
                .map(TypeParameterNaming::upperCamelToken).collect(Collectors.joining());
    }

    return identifier + "T";
}

From source file:com.liveramp.megadesk.recipes.queue.PopOne.java

@Override
public Void run(Context context) throws Exception {
    ImmutableList<VALUE> list = context.read(this.list);
    if (!list.isEmpty()) {
        ImmutableList<VALUE> newList = list.subList(1, list.size());
        context.write(this.list, newList);
    }/*from ww w  .j  a va  2s  .  co m*/
    if (context.read(this.list).isEmpty()) {
        context.write(this.frozen, false);
    }
    return null;
}

From source file:com.google.template.soy.jbcsrc.restricted.BytecodeUtils.java

/**
 * Returns an expression that returns a new {@code ImmutableList} containing the given items.
 *
 * <p>NOTE: {@code ImmutableList} rejects null elements.
 *//*from w w  w.  j a va2 s .c om*/
public static Expression asImmutableList(Iterable<? extends Expression> items) {
    ImmutableList<Expression> copy = ImmutableList.copyOf(items);
    if (copy.size() < MethodRef.IMMUTABLE_LIST_OF.size()) {
        return MethodRef.IMMUTABLE_LIST_OF.get(copy.size()).invoke(copy);
    }
    ImmutableList<Expression> explicit = copy.subList(0, MethodRef.IMMUTABLE_LIST_OF.size());
    Expression remainder = asArray(OBJECT_ARRAY_TYPE,
            copy.subList(MethodRef.IMMUTABLE_LIST_OF.size(), copy.size()));
    return MethodRef.IMMUTABLE_LIST_OF_ARRAY.invoke(Iterables.concat(explicit, ImmutableList.of(remainder)));
}

From source file:ru.org.linux.topic.TopicTagService.java

/**
 *  ?  ??    ??.//  w ww . ja  v  a  2  s.c  o m
 *   ?  ?     
 *
 * @param msgId   ??
 * @return ?  ??
 */
public ImmutableList<String> getMessageTagsForTitle(int msgId) {
    ImmutableList<String> tags = topicTagDao.getTags(msgId);
    return tags.subList(0, Math.min(tags.size(), MAX_TAGS_IN_TITLE));
}

From source file:com.github.hilcode.versionator.impl.DefaultVersionChangeExtractor.java

Result<String, RequestedVersionChange> extractOldNew(final GroupArtifact groupArtifact, final String oldVersion,
        final String newVersion, final ImmutableList<String> arguments) {
    final Result<String, ImmutableList<Gav>> gavs = this.gavExtractor
            .extract(arguments.subList(0, arguments.size() - 3));
    if (gavs.isFailure()) {
        return Result.asFailure(gavs);
    } else {/*from  w w  w . j a v  a  2s.  c  o m*/
        final FromOldToNewVersion versionChange = new FromOldToNewVersion(groupArtifact, oldVersion,
                newVersion);
        final Either<FromOldToNewVersion, FromAnyToNewVersion> fromOldToNewVersion = Either.left(versionChange);
        return Result.success(new RequestedVersionChange(fromOldToNewVersion, gavs.success()));
    }
}

From source file:com.google.cloud.firestore.BasePath.java

/**
 * Returns the path of the parent element.
 *
 * @return The new Path or null if we are already at the root.
 *///w w  w  . ja va2 s  . c om
@Nullable
B getParent() {
    ImmutableList<String> parts = getSegments();
    if (parts.isEmpty()) {
        return null;
    }
    return createPathWithSegments(parts.subList(0, parts.size() - 1));
}

From source file:org.caleydo.core.view.internal.ColorPalettePicker.java

public ColorPalettePicker() {
    setLayout(GLLayouts.flowVertical(10));
    ImmutableSortedSet.Builder<IColorPalette> b = ImmutableSortedSet.orderedBy(new Comparator<IColorPalette>() {
        @Override/*  ww w .  ja  v  a 2  s .c  o  m*/
        public int compare(IColorPalette o1, IColorPalette o2) {
            int c;
            if ((c = o1.getType().compareTo(o2.getType())) != 0)
                return c;
            c = o1.getSizes().last() - o2.getSizes().last();
            if (c != 0)
                return -c;
            return String.CASE_INSENSITIVE_ORDER.compare(o1.getLabel(), o2.getLabel());
        }
    });
    b.add(ColorBrewer.values());
    b.add(AlexColorPalette.values());

    final ImmutableList<IColorPalette> l = b.build().asList();
    GLElementContainer c = new GLElementContainer(GLLayouts.flowHorizontal(2));
    for (IColorPalette p : l.subList(0, l.size() / 2))
        c.add(new ColorPalette(p));
    this.add(c);
    c = new GLElementContainer(GLLayouts.flowHorizontal(2));
    for (IColorPalette p : l.subList(l.size() / 2, l.size()))
        c.add(new ColorPalette(p));
    this.add(c);

}

From source file:com.google.devtools.build.docgen.SummaryRuleFamily.java

SummaryRuleFamily(ListMultimap<RuleType, RuleDocumentation> ruleTypeMap, String name) {
    this.name = name;
    this.binaryRules = ImmutableList.copyOf(ruleTypeMap.get(RuleType.BINARY));
    this.libraryRules = ImmutableList.copyOf(ruleTypeMap.get(RuleType.LIBRARY));
    this.testRules = ImmutableList.copyOf(ruleTypeMap.get(RuleType.TEST));

    final ImmutableList<RuleDocumentation> otherRules = ImmutableList.copyOf(ruleTypeMap.get(RuleType.OTHER));
    if (otherRules.size() >= 4) {
        this.otherRules1 = ImmutableList.copyOf(otherRules.subList(0, otherRules.size() / 2));
        this.otherRules2 = ImmutableList.copyOf(otherRules.subList(otherRules.size() / 2, otherRules.size()));
    } else {/*from   w w w  .  j  av  a  2  s. c  o  m*/
        this.otherRules1 = otherRules;
        this.otherRules2 = ImmutableList.of();
    }
}