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

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

Introduction

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

Prototype

int size();

Source Link

Document

Returns the number of elements in this list.

Usage

From source file:com.facebook.presto.jdbc.client.FailureInfo.java

private static FailureException toException(FailureInfo failureInfo) {
    if (failureInfo == null) {
        return null;
    }//from   ww  w  .  ja v a  2s  .  c o  m
    FailureException failure = new FailureException(failureInfo.getType(), failureInfo.getMessage(),
            toException(failureInfo.getCause()));
    ImmutableList.Builder<StackTraceElement> stackTraceBuilder = ImmutableList.builder();
    for (String stack : failureInfo.getStack()) {
        stackTraceBuilder.add(toStackTraceElement(stack));
    }
    ImmutableList<StackTraceElement> stackTrace = stackTraceBuilder.build();
    failure.setStackTrace(stackTrace.toArray(new StackTraceElement[stackTrace.size()]));
    return failure;
}

From source file:aeon.compiler.FieldExtractorImpl.java

@NotNull
private static ImmutableList<Field> assertIntegrity(@NotNull final ImmutableList<Field> fields) {
    checkNotNull(fields);//from w ww .  j av a2s . c o m

    if (fields.size() == 0) {
        illegalArgument("No fields annotated with @aeon.Field");
    }

    final List<String> reservedNames = Arrays.asList(RESERVED_FIELD_NAMES);

    int idFieldCount = 0;
    for (final Field field : fields) {
        if (reservedNames.contains(Utils.normalizeFieldName(field.getName()))) {
            illegalArgument(String.format(
                    "Field name \"%s\" collides with default QueryBuilder methods. Consider renaming the field.",
                    field.getName()));
        }

        if (field.isNullable() && !field.getType().isReferenceType()) {
            illegalArgument("Only reference types can be declared @Nullable");
        }

        if (field.isId()) {
            if (!canBeIdField(field.getType())) {
                illegalArgument("Only integer types or String can be the ID");
            }

            if (field.isNullable()) {
                illegalArgument("ID field cannot be declared nullable");
            }

            if (field.getId().autoIncrement() && !canBeAutoIncrement(field.getType())) {
                illegalArgument("Only integer types can be AUTOINCREMENT");
            }

            idFieldCount++;
        }
    }

    if (idFieldCount == 0) {
        illegalArgument("Missing ID field");
    } else if (idFieldCount > 1) {
        illegalArgument("Multiple ID fields not supported");
    }

    return fields;
}

From source file:com.spectralogic.ds3autogen.utils.ResponsePayloadUtil.java

/**
 * Gets the non-error, non-null code associated with a list of Ds3ResponseCodes
 *//*from  w w  w .j a v a2s  . c o  m*/
public static Integer getPayloadResponseCode(final ImmutableList<Ds3ResponseCode> responseCodes) {

    final ImmutableList<Integer> codes = getAllNonErrorResponseCodes(responseCodes);
    switch (codes.size()) {
    case 0:
        //Log instead of throw error since GetObject and HeadBucket will have no values
        LOG.debug("There are no non-error non-null response codes for this request");
        return null;
    case 1:
        return codes.get(0);
    default:
        throw new IllegalArgumentException("There are multiple non-error response codes for this request");
    }
}

From source file:io.dfox.junit.http.api.Path.java

/**
 * Parse a String into a RunPath. The path is expected to be in the format 
 * &lt;grouping&gt;[/&lt;name&gt;].
 * /*from   w  ww.j  ava 2 s. c  o m*/
 * @param path The string path
 * @return The test path or an empty Optional if the path is not valid or could not be parsed
 */
public static Optional<Path> parse(final String path) {
    final ImmutableList<String> parts = Arrays.stream(path.split("/")).map(s -> s.trim())
            .filter(s -> !s.isEmpty()).collect(Collectors.toImmutableList());

    switch (parts.size()) {
    case 1:
        return Optional.of(new Path(parts.get(0), Optional.empty()));
    case 2:
        return Optional.of(new Path(parts.get(0), Optional.of(parts.get(1))));
    default:
        return Optional.empty();
    }
}

From source file:com.facebook.presto.client.FailureInfo.java

private static FailureException toException(FailureInfo failureInfo) {
    if (failureInfo == null) {
        return null;
    }//from  w w w  .  j av  a  2  s.  c o m
    FailureException failure = new FailureException(failureInfo.getType(), failureInfo.getMessage(),
            toException(failureInfo.getCause()));
    for (FailureInfo suppressed : failureInfo.getSuppressed()) {
        failure.addSuppressed(toException(suppressed));
    }
    ImmutableList.Builder<StackTraceElement> stackTraceBuilder = ImmutableList.builder();
    for (String stack : failureInfo.getStack()) {
        stackTraceBuilder.add(toStackTraceElement(stack));
    }
    ImmutableList<StackTraceElement> stackTrace = stackTraceBuilder.build();
    failure.setStackTrace(stackTrace.toArray(new StackTraceElement[stackTrace.size()]));
    return failure;
}

From source file:com.facebook.presto.execution.ExecutionFailureInfo.java

private static Failure toException(ExecutionFailureInfo executionFailureInfo) {
    if (executionFailureInfo == null) {
        return null;
    }//from  w ww  . j a v a 2s.  c o m
    Failure failure = new Failure(executionFailureInfo.getType(), executionFailureInfo.getMessage(),
            executionFailureInfo.getErrorCode(), toException(executionFailureInfo.getCause()));
    for (ExecutionFailureInfo suppressed : executionFailureInfo.getSuppressed()) {
        failure.addSuppressed(toException(suppressed));
    }
    ImmutableList.Builder<StackTraceElement> stackTraceBuilder = ImmutableList.builder();
    for (String stack : executionFailureInfo.getStack()) {
        stackTraceBuilder.add(toStackTraceElement(stack));
    }
    ImmutableList<StackTraceElement> stackTrace = stackTraceBuilder.build();
    failure.setStackTrace(stackTrace.toArray(new StackTraceElement[stackTrace.size()]));
    return failure;
}

From source file:com.google.api.codegen.configgen.CollectionPattern.java

private static boolean isValidCollectionPattern(FieldSegment fieldSegment) {
    ImmutableList<PathSegment> subPath = fieldSegment.getSubPath();
    if (subPath == null) {
        return false;
    }/*  w  ww. j  av  a  2  s  . com*/
    if (subPath.size() <= 1) {
        return false;
    }
    boolean containsLiteralWildcardPair = false;
    PathSegment lastSegment = null;
    for (PathSegment segment : subPath) {
        if (segment instanceof WildcardSegment && lastSegment != null
                && lastSegment instanceof LiteralSegment) {
            containsLiteralWildcardPair = true;
            break;
        }
        lastSegment = segment;
    }
    if (!containsLiteralWildcardPair) {
        return false;
    }

    return true;
}

From source file:com.facebook.buck.android.resources.ResourceTable.java

public static ResourceTable slice(ResourceTable table, Map<Integer, Integer> countsToExtract) {
    ResTablePackage newPackage = ResTablePackage.slice(table.resPackage, countsToExtract);

    StringPool strings = table.strings;/*from  w w w.ja v  a 2s.  c o m*/
    // Figure out what strings are used by the retained references.
    ImmutableSortedSet.Builder<Integer> stringRefs = ImmutableSortedSet
            .orderedBy(Comparator.comparing(strings::getString).thenComparingInt(i -> i));
    newPackage.visitStringReferences(stringRefs::add);
    ImmutableList<Integer> stringsToExtract = stringRefs.build().asList();
    ImmutableMap<Integer, Integer> stringMapping = Maps
            .uniqueIndex(IntStream.range(0, stringsToExtract.size())::iterator, stringsToExtract::get);

    // Extract a StringPool that contains just the strings used by the new package.
    // This drops styles.
    StringPool newStrings = StringPool.create(stringsToExtract.stream().map(strings::getString)::iterator);

    // Adjust the string references.
    newPackage.transformStringReferences(stringMapping::get);

    return new ResourceTable(newStrings, newPackage);
}

From source file:com.facebook.buck.artifact_cache.MultiArtifactCache.java

private static ListenableFuture<Void> storeToCaches(ImmutableList<ArtifactCache> caches, ArtifactInfo info,
        BorrowablePath output) {//from w ww .  j a  va 2  s .  co m
    // TODO(cjhopman): support BorrowablePath with multiple writable caches.
    if (caches.size() != 1) {
        output = BorrowablePath.notBorrowablePath(output.getPath());
    }
    List<ListenableFuture<Void>> storeFutures = Lists.newArrayListWithExpectedSize(caches.size());
    for (ArtifactCache artifactCache : caches) {
        storeFutures.add(artifactCache.store(info, output));
    }

    // Aggregate future to ensure all store operations have completed.
    return Futures.transform(Futures.allAsList(storeFutures), Functions.<Void>constant(null));
}

From source file:com.google.devtools.build.lib.skyframe.AbstractLabelCycleReporter.java

/**
 * Prints the SkyKey-s in cycle into cycleMessage using the print function.
 *//*from ww  w.j ava 2s. c  o m*/
static SkyKey printCycle(ImmutableList<SkyKey> cycle, StringBuilder cycleMessage,
        Function<SkyKey, String> printFunction) {
    Iterable<SkyKey> valuesToPrint = cycle.size() > 1 ? Iterables.concat(cycle, ImmutableList.of(cycle.get(0)))
            : cycle;
    SkyKey cycleValue = null;
    for (SkyKey value : valuesToPrint) {
        if (cycleValue == null) { // first item
            cycleValue = value;
            cycleMessage.append("\n.-> ");
        } else {
            if (value == cycleValue) { // last item of the cycle
                cycleMessage.append("\n`-- ");
            } else {
                cycleMessage.append("\n|   ");
            }
        }
        cycleMessage.append(printFunction.apply(value));
    }

    if (cycle.size() == 1) {
        cycleMessage.append(" [self-edge]");
        cycleMessage.append("\n`--");
    }

    return cycleValue;
}