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:org.glowroot.agent.model.ErrorMessage.java

private static StackTraceWithoutCommonFrames getStackTraceAndFramesInCommon(
        StackTraceElement[] stackTraceElements, @Nullable List<StackTraceElement> causedStackTrace,
        AtomicInteger transactionThrowableFrameCount) {
    if (transactionThrowableFrameCount.get() >= TRANSACTION_THROWABLE_FRAME_LIMIT) {
        return ImmutableStackTraceWithoutCommonFrames.builder().build();
    }/*from   ww w.  ja v  a 2 s. com*/
    if (causedStackTrace == null) {
        return ImmutableStackTraceWithoutCommonFrames.builder().addStackTrace(stackTraceElements).build();
    }
    ImmutableList<StackTraceElement> stackTrace = ImmutableList.copyOf(stackTraceElements);
    int framesInCommonWithEnclosing = 0;
    ListIterator<StackTraceElement> i = stackTrace.listIterator(stackTrace.size());
    ListIterator<StackTraceElement> j = causedStackTrace.listIterator(causedStackTrace.size());
    while (i.hasPrevious() && j.hasPrevious()) {
        StackTraceElement element = i.previous();
        StackTraceElement causedElement = j.previous();
        if (!element.equals(causedElement)) {
            break;
        }
        framesInCommonWithEnclosing++;
    }
    if (framesInCommonWithEnclosing > 0) {
        // strip off common frames
        stackTrace = stackTrace.subList(0, stackTrace.size() - framesInCommonWithEnclosing);
    }
    return ImmutableStackTraceWithoutCommonFrames.builder().stackTrace(stackTrace)
            .framesInCommonWithEnclosing(framesInCommonWithEnclosing).build();
}

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.facebook.buck.core.build.engine.manifest.Manifest.java

/** Hash the files pointed to by the source paths. */
@VisibleForTesting// w w  w  .ja  v a  2s  .co  m
static HashCode hashSourcePathGroup(FileHashCache fileHashCache, SourcePathResolver resolver,
        ImmutableList<SourcePath> paths) throws IOException {
    if (paths.size() == 1) {
        return hashSourcePath(paths.get(0), fileHashCache, resolver);
    }
    Hasher hasher = Hashing.md5().newHasher();
    for (SourcePath path : paths) {
        hasher.putBytes(hashSourcePath(path, fileHashCache, resolver).asBytes());
    }
    return hasher.hash();
}

From source file:com.google.testing.junit.runner.junit4.JUnit4Options.java

/**
 * Parses the given array of arguments and returns a JUnit4Options
 * object representing the parsed arguments.
 *///from  ww  w . j  a  v  a  2s.c  o  m
static JUnit4Options parse(Map<String, String> envVars, List<String> args) {
    ImmutableList.Builder<String> unparsedArgsBuilder = ImmutableList.builder();
    Map<String, String> optionsMap = Maps.newHashMap();

    optionsMap.put(TEST_INCLUDE_FILTER_OPTION, null);
    optionsMap.put(TEST_EXCLUDE_FILTER_OPTION, null);

    for (Iterator<String> it = args.iterator(); it.hasNext();) {
        String arg = it.next();
        int indexOfEquals = arg.indexOf("=");

        if (indexOfEquals > 0) {
            String optionName = arg.substring(0, indexOfEquals);
            if (optionsMap.containsKey(optionName)) {
                optionsMap.put(optionName, arg.substring(indexOfEquals + 1));
                continue;
            }
        } else if (optionsMap.containsKey(arg)) {
            // next argument is the regexp
            if (!it.hasNext()) {
                throw new RuntimeException("No filter expression specified after " + arg);
            }
            optionsMap.put(arg, it.next());
            continue;
        }
        unparsedArgsBuilder.add(arg);
    }
    // If TESTBRIDGE_TEST_ONLY is set in the environment, forward it to the
    // --test_filter flag.
    String testFilter = envVars.get(TESTBRIDGE_TEST_ONLY);
    if (testFilter != null && optionsMap.get(TEST_INCLUDE_FILTER_OPTION) == null) {
        optionsMap.put(TEST_INCLUDE_FILTER_OPTION, testFilter);
    }

    ImmutableList<String> unparsedArgs = unparsedArgsBuilder.build();
    return new JUnit4Options(optionsMap.get(TEST_INCLUDE_FILTER_OPTION),
            optionsMap.get(TEST_EXCLUDE_FILTER_OPTION), unparsedArgs.toArray(new String[unparsedArgs.size()]));
}

From source file:com.google.jimfs.FileTree.java

private static boolean isEmpty(ImmutableList<Name> names) {
    // the empty path (created by FileSystem.getPath("")), has no root and a single name, ""
    return names.isEmpty() || names.size() == 1 && names.get(0).toString().isEmpty();
}

From source file:com.google.javascript.rhino.QualifiedName.java

public static QualifiedName of(String string) {
    int lastIndex = 0;
    int index;// w  w w. ja  v a  2 s  .c  om
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    do {
        index = string.indexOf('.', lastIndex);
        builder.add(string.substring(lastIndex, index < 0 ? string.length() : index).intern());
        lastIndex = index + 1;
    } while (index >= 0);
    ImmutableList<String> terms = builder.build();
    return new StringListQname(terms, terms.size());
}

From source file:com.spectralogic.dsbrowser.gui.services.ds3Panel.Ds3PanelService.java

public static void showPhysicalPlacement(final Ds3Common ds3Common, final Workers workers,
        final ResourceBundle resourceBundle) {
    ImmutableList<TreeItem<Ds3TreeTableValue>> tempValues = ds3Common.getDs3TreeTableView().getSelectionModel()
            .getSelectedItems().stream().collect(GuavaCollectors.immutableList());
    final TreeItem<Ds3TreeTableValue> root = ds3Common.getDs3TreeTableView().getRoot();
    if (tempValues.isEmpty() && (root == null || root.getValue() != null)) {
        LOG.info(resourceBundle.getString("nothingSelected"));
        new LazyAlert(resourceBundle).info(resourceBundle.getString("nothingSelected"));
        return;//from  www  . j av  a  2 s .co m
    } else if (tempValues.isEmpty()) {
        final ImmutableList.Builder<TreeItem<Ds3TreeTableValue>> builder = ImmutableList.builder();
        tempValues = builder.add(root).build().asList();

    }
    final ImmutableList<TreeItem<Ds3TreeTableValue>> values = tempValues;
    if (values.size() > 1) {
        LOG.info(resourceBundle.getString("onlySingleObjectSelectForPhysicalPlacement"));
        new LazyAlert(resourceBundle)
                .info(resourceBundle.getString("onlySingleObjectSelectForPhysicalPlacement"));
        return;
    }

    final PhysicalPlacementTask getPhysicalPlacement = new PhysicalPlacementTask(ds3Common, values, workers);

    workers.execute(getPhysicalPlacement);
    getPhysicalPlacement.setOnSucceeded(SafeHandler.logHandle(event -> Platform.runLater(() -> {
        LOG.info("Launching PhysicalPlacement popup");
        PhysicalPlacementPopup.show((PhysicalPlacement) getPhysicalPlacement.getValue(), resourceBundle);
    })));
}

From source file:com.facebook.buck.apple.toolchain.impl.CodeSignIdentityStoreFactory.java

/**
 * Construct a store by asking the system keychain for all stored code sign identities.
 *
 * <p>The loading process is deferred till first access.
 *//*from w  w w.ja va  2s  . co m*/
public static CodeSignIdentityStore fromSystem(ProcessExecutor processExecutor, ImmutableList<String> command) {
    return CodeSignIdentityStore.of(MoreSuppliers.memoize(() -> {
        ProcessExecutorParams processExecutorParams = ProcessExecutorParams.builder().addAllCommand(command)
                .build();
        // Specify that stdout is expected, or else output may be wrapped in Ansi escape
        // chars.
        Set<Option> options = EnumSet.of(Option.EXPECTING_STD_OUT);
        Result result;
        try {
            result = processExecutor.launchAndExecute(processExecutorParams, options,
                    /* stdin */ Optional.empty(), /* timeOutMs */ Optional.empty(),
                    /* timeOutHandler */ Optional.empty());
        } catch (InterruptedException | IOException e) {
            LOG.warn("Could not execute security, continuing without codesign identity.");
            return ImmutableList.of();
        }

        if (result.getExitCode() != 0) {
            throw new RuntimeException(result.getMessageForUnexpectedResult(String.join(" ", command)));
        }

        Matcher matcher = CODE_SIGN_IDENTITY_PATTERN.matcher(result.getStdout().get());
        Builder<CodeSignIdentity> builder = ImmutableList.builder();
        while (matcher.find()) {
            Optional<HashCode> fingerprint = CodeSignIdentity.toFingerprint(matcher.group(1));
            if (!fingerprint.isPresent()) {
                // security should always output a valid fingerprint string.
                LOG.warn("Code sign identity fingerprint is invalid, ignored: " + matcher.group(1));
                break;
            }
            String subjectCommonName = matcher.group(2);
            CodeSignIdentity identity = CodeSignIdentity.builder().setFingerprint(fingerprint)
                    .setSubjectCommonName(subjectCommonName).build();
            builder.add(identity);
            LOG.debug("Found code signing identity: " + identity);
        }
        ImmutableList<CodeSignIdentity> allValidIdentities = builder.build();
        if (allValidIdentities.isEmpty()) {
            LOG.warn("No valid code signing identities found.  Device build/install won't work.");
        } else if (allValidIdentities.size() > 1) {
            LOG.info("Multiple valid identity found.  This could potentially cause the wrong one to"
                    + " be used unless explicitly specified via CODE_SIGN_IDENTITY.");
        }
        return allValidIdentities;
    }));
}

From source file:com.facebook.buck.apple.project_generator.ProjectGeneratorTestUtils.java

public static <T extends PBXBuildPhase> void assertHasSingletonPhaseWithEntries(PBXTarget target,
        final Class<T> cls, ImmutableList<String> entries) {
    PBXBuildPhase buildPhase = getSingletonPhaseByType(target, cls);
    assertThat("Phase should have right number of entries", buildPhase.getFiles(), hasSize(entries.size()));

    for (PBXBuildFile file : buildPhase.getFiles()) {
        PBXReference.SourceTree sourceTree = file.getFileRef().getSourceTree();
        switch (sourceTree) {
        case GROUP:
            fail("Should not emit entries with sourceTree <group>");
            break;
        case ABSOLUTE:
            fail("Should not emit entries with sourceTree <absolute>");
            break;
        // $CASES-OMITTED$
        default:/*from  w  ww.  ja v a 2  s. c  o m*/
            String serialized = "$" + sourceTree + "/" + file.getFileRef().getPath();
            assertThat("Source tree prefixed file references should exist in list of expected entries.",
                    entries, hasItem(serialized));
            break;
        }
    }
}

From source file:com.palantir.atlasdb.keyvalue.remoting.RemotingKeyValueService.java

private static <T> RangeIterator<T> transformIterator(String tableName, RangeRequest range, long timestamp,
        ClosableIterator<RowResult<T>> closableIterator,
        Function<Pair<Boolean, ImmutableList<RowResult<T>>>, RangeIterator<T>> resultSupplier) {
    try {// w  w w.ja  va 2s  .  co  m
        int pageSize = range.getBatchHint() != null ? range.getBatchHint() : 100;
        if (pageSize == 1) {
            pageSize = 2;
        }
        ImmutableList<RowResult<T>> page = ImmutableList.copyOf(Iterators.limit(closableIterator, pageSize));
        if (page.size() < pageSize) {
            return resultSupplier.apply(Pair.create(false, page));
        } else {
            return resultSupplier.apply(Pair.create(true, page.subList(0, pageSize - 1)));
        }
    } finally {
        closableIterator.close();
    }
}