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:com.github.hilcode.versionator.impl.DefaultReleaseExtractor.java

@Override
public final Result<String, ImmutableList<GroupArtifact>> extract(final ImmutableList<String> arguments) {
    Preconditions.checkNotNull(arguments, "Missing 'arguments'.");
    if (arguments.isEmpty()) {
        return Result.success(ImmutableList.<GroupArtifact>of());
    }/* www  .  j  av  a 2 s  . c om*/
    final String firstArgument = arguments.get(0);
    if (firstArgument.equals("-x") || firstArgument.equals("--exclude")) {
        final ImmutableList<String> exclusions = arguments.subList(1, arguments.size());
        return extractExclusions(exclusions);
    } else {
        return Result.failure(String.format(
                "Expected '-x' or '--exclude' but found '%s' instead.\n\nPerhaps try --help?", firstArgument));
    }
}

From source file:com.google.errorprone.refaster.BlockTemplate.java

private Choice<List<BlockTemplateMatch>> matchesStartingAnywhere(JCBlock block, int offset,
        final ImmutableList<? extends StatementTree> statements, final Context context) {
    Choice<List<BlockTemplateMatch>> choice = Choice.none();
    for (int i = 0; i < statements.size(); i++) {
        choice = choice.or(matchesStartingAtBeginning(block, offset + i,
                statements.subList(i, statements.size()), context));
    }//from  w  w  w.  j  av a  2s  . c o m
    return choice.or(Choice.of(List.<BlockTemplateMatch>nil()));
}

From source file:org.glowroot.local.ui.GaugeJsonService.java

@GET("/backend/config/matching-mbean-objects")
String getMatchingMBeanObjects(String queryString) throws Exception {
    MBeanObjectNameRequest request = QueryStrings.decode(queryString, MBeanObjectNameRequest.class);
    Set<ObjectName> objectNames = lazyPlatformMBeanServer.queryNames(null,
            new ObjectNameQueryExp(request.partialMBeanObjectName()));
    List<String> names = Lists.newArrayList();
    for (ObjectName objectName : objectNames) {
        names.add(objectName.toString());
    }/*from w  w  w.  j a v a 2  s  .com*/
    ImmutableList<String> sortedNames = Ordering.from(String.CASE_INSENSITIVE_ORDER).immutableSortedCopy(names);
    if (sortedNames.size() > request.limit()) {
        sortedNames = sortedNames.subList(0, request.limit());
    }
    return mapper.writeValueAsString(sortedNames);
}

From source file:google.registry.dns.writer.clouddns.CloudDnsWriter.java

/**
 * Publish A/AAAA records to Cloud DNS./*from  w  w w .ja v  a2 s.c o m*/
 *
 * <p>Cloud DNS has no API for glue -- A/AAAA records are automatically matched to their
 * corresponding NS records to serve glue.
 */
@Override
public void publishHost(String hostName) {
    // Get the superordinate domain name of the host.
    InternetDomainName host = InternetDomainName.from(hostName);
    Optional<InternetDomainName> tld = Registries.findTldForName(host);

    // Host not managed by our registry, no need to update DNS.
    if (!tld.isPresent()) {
        logger.severefmt("publishHost called for invalid host %s", hostName);
        return;
    }

    // Extract the superordinate domain name. The TLD and host may have several dots so this
    // must calculate a sublist.
    ImmutableList<String> hostParts = host.parts();
    ImmutableList<String> tldParts = tld.get().parts();
    ImmutableList<String> domainParts = hostParts.subList(hostParts.size() - tldParts.size() - 1,
            hostParts.size());
    String domain = Joiner.on(".").join(domainParts);

    // Refresh the superordinate domain, since we shouldn't be publishing glue records if we are not
    // authoritative for the superordinate domain.
    publishDomain(domain);
}

From source file:org.glowroot.agent.live.LiveWeavingServiceImpl.java

@Override
public List<String> getMatchingMethodNames(String agentId, String className, String partialMethodName,
        int limit) {
    String partialMethodNameUpper = partialMethodName.toUpperCase(Locale.ENGLISH);
    Set<String> methodNames = Sets.newHashSet();
    for (UiAnalyzedMethod analyzedMethod : getClasspathCache().getAnalyzedMethods(className)) {
        String methodName = analyzedMethod.name();
        if (methodName.equals("<init>") || methodName.equals("<clinit>")) {
            // static initializers are not supported by weaver
            // (see AdviceMatcher.isMethodNameMatch())
            // and constructors do not support @OnBefore advice at this time
            continue;
        }//from www . jav a  2  s.  c  o  m
        if (methodName.toUpperCase(Locale.ENGLISH).contains(partialMethodNameUpper)) {
            methodNames.add(methodName);
        }
    }
    ImmutableList<String> sortedMethodNames = Ordering.natural().immutableSortedCopy(methodNames);
    if (methodNames.size() > limit) {
        return sortedMethodNames.subList(0, limit);
    } else {
        return sortedMethodNames;
    }
}

From source file:org.androidtransfuse.adapter.classes.ASTClassFactory.java

/**
 * Build an AST Constructor from the given constructor
 *
 * @param constructor/*from www .j ava2  s. co m*/
 * @return AST Constructor
 */
public ASTConstructor getConstructor(Constructor constructor, boolean isEnum, boolean isInnerClass) {
    ASTAccessModifier modifier = ASTAccessModifier.getModifier(constructor.getModifiers());

    Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();

    if (constructor.getDeclaringClass().getEnclosingClass() != null
            && !Modifier.isStatic(constructor.getDeclaringClass().getModifiers())) {
        // An inner class constructor contains a hidden non-annotated prameter
        Annotation[][] paddedParameterAnnotations = new Annotation[parameterAnnotations.length + 1][];

        paddedParameterAnnotations[0] = new Annotation[0];
        System.arraycopy(parameterAnnotations, 0, paddedParameterAnnotations, 1, parameterAnnotations.length);

        parameterAnnotations = paddedParameterAnnotations;
    }

    ImmutableList<ASTParameter> constructorParameters = getParameters(constructor.getParameterTypes(),
            constructor.getGenericParameterTypes(), parameterAnnotations);
    if (isEnum) {
        constructorParameters = constructorParameters.subList(2, constructorParameters.size());
    }
    if (isInnerClass) {
        constructorParameters = constructorParameters.subList(1, constructorParameters.size());
    }
    ImmutableSet<ASTType> throwsTypes = getTypes(constructor.getExceptionTypes());

    return new ASTClassConstructor(getAnnotations(constructor), constructor, constructorParameters, modifier,
            throwsTypes);
}

From source file:org.glowroot.local.ui.InstrumentationJsonService.java

private ImmutableList<String> getMatchingMethodNames(String className, String partialMethodName, int limit) {
    String partialMethodNameUpper = partialMethodName.toUpperCase(Locale.ENGLISH);
    Set<String> methodNames = Sets.newHashSet();
    for (UiAnalyzedMethod analyzedMethod : classpathCache.getAnalyzedMethods(className)) {
        String methodName = analyzedMethod.name();
        if (methodName.equals("<init>") || methodName.equals("<clinit>")) {
            // static initializers are not supported by weaver
            // (see AdviceMatcher.isMethodNameMatch())
            // and constructors do not support @OnBefore advice at this time
            continue;
        }//from   ww w .  j av  a2 s  .co  m
        if (methodName.toUpperCase(Locale.ENGLISH).contains(partialMethodNameUpper)) {
            methodNames.add(methodName);
        }
    }
    ImmutableList<String> sortedMethodNames = Ordering.from(String.CASE_INSENSITIVE_ORDER)
            .immutableSortedCopy(methodNames);
    if (methodNames.size() > limit) {
        return sortedMethodNames.subList(0, limit);
    } else {
        return sortedMethodNames;
    }
}

From source file:com.palantir.giraffe.file.UniformPath.java

private Path toRelativePath(FileSystem fs) {
    ImmutableList<String> segments = core.getPathSegments();
    if (segments.isEmpty()) {
        return fs.getPath("");
    } else {/*from   www  .  j  ava2  s .co  m*/
        String first = segments.get(0);
        String[] more = segments.subList(1, segments.size()).toArray(new String[0]);
        return fs.getPath(first, more);
    }
}

From source file:org.caleydo.view.bicluster.sorting.FuzzyClustering.java

public List<IntFloat> filter(float threshold, int maxElements, EThresholdMode mode) {
    if (threshold == 0 && maxElements == UNBOUND_NUMBER) {
        switch (mode) {
        case ABS:
            return memberships.asList();
        case NEGATIVE_ONLY:
            return negatives(0, UNBOUND_NUMBER);
        case POSITVE_ONLY:
            return positives(0, UNBOUND_NUMBER);
        }/*from   w  w  w . j  a  va 2  s  . c o m*/
    }
    ImmutableList<IntFloat> negatives = mode.includeNegatives() ? negatives(threshold, maxElements)
            : ImmutableList.<IntFloat>of();
    ImmutableList<IntFloat> positives = mode.includePositives() ? positives(threshold, maxElements)
            : ImmutableList.<IntFloat>of();
    if (maxElements == UNBOUND_NUMBER || (negatives.size() + positives.size()) <= maxElements) //just add negatives and positives
        return ConcatedList.concat(negatives, positives);

    if (negatives.isEmpty()) {
        return positives.subList(Math.max(0, positives.size() - maxElements), positives.size());
    }
    if (positives.isEmpty())
        return negatives.subList(0, Math.min(negatives.size(), maxElements));

    // take the abs top X elements
    Iterator<IntFloat> negIt = negatives.iterator();
    Iterator<IntFloat> posIt = Lists.reverse(positives).iterator();
    IntFloat negEnd = null;
    IntFloat negAct = negIt.next();
    IntFloat posStart = null;
    IntFloat posAct = posIt.next();

    for (int i = 0; i < maxElements; ++i) {
        if (negAct == null || (posAct != null && posAct.getMembership() > -negAct.getMembership())) {
            posStart = posAct;
            posAct = posIt.hasNext() ? posIt.next() : null;
        } else {
            negEnd = negAct;
            negAct = negIt.hasNext() ? negIt.next() : null;
        }
    }

    ImmutableSortedSet<IntFloat> headSet = negEnd == null ? ImmutableSortedSet.<IntFloat>of()
            : memberships.headSet(negEnd, true);
    ImmutableSortedSet<IntFloat> tailSet = posStart == null ? ImmutableSortedSet.<IntFloat>of()
            : memberships.tailSet(posStart, true);
    return ConcatedList.concat(headSet.asList(), tailSet.asList());
}

From source file:google.registry.dns.writer.dnsupdate.DnsUpdateWriter.java

@Override
public void publishHost(String hostName) {
    // Get the superordinate domain name of the host.
    InternetDomainName host = InternetDomainName.from(hostName);
    ImmutableList<String> hostParts = host.parts();
    Optional<InternetDomainName> tld = Registries.findTldForName(host);

    // host not managed by our registry, no need to update DNS.
    if (!tld.isPresent()) {
        return;// w  w  w.  j a  v  a 2  s .  c  o  m
    }

    ImmutableList<String> tldParts = tld.get().parts();
    ImmutableList<String> domainParts = hostParts.subList(hostParts.size() - tldParts.size() - 1,
            hostParts.size());
    String domain = Joiner.on(".").join(domainParts);

    // Refresh the superordinate domain, always delete the host first to ensure idempotency,
    // and only publish the host if it is a glue record.
    publishDomain(domain, hostName);
}