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.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();
    }
}

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

public static void createFolderPrompt(final Ds3Common ds3Common, final LoggingService loggingService,
        final ResourceBundle resourceBundle) {
    ImmutableList<TreeItem<Ds3TreeTableValue>> values = ds3Common.getDs3TreeTableView().getSelectionModel()
            .getSelectedItems().stream().collect(GuavaCollectors.immutableList());
    final TreeItem<Ds3TreeTableValue> root = ds3Common.getDs3TreeTableView().getRoot();
    final LazyAlert alert = new LazyAlert(resourceBundle);

    if (values.stream().map(TreeItem::getValue).anyMatch(Ds3TreeTableValue::isSearchOn)) {
        LOG.info("You can not create folder here. Please refresh your view");
        alert.info("cantCreateFolderHere");
        return;/* w w w  . jav  a 2s  .  c  o  m*/
    } else if (values.isEmpty() && root != null && root.getValue() != null) {
        final ImmutableList.Builder<TreeItem<Ds3TreeTableValue>> builder = ImmutableList.builder();
        values = builder.add(root).build();
    } else if (values.isEmpty()) {
        loggingService.logMessage(resourceBundle.getString("selectLocation"), LogType.ERROR);
        alert.info("locationNotSelected");
        return;
    } else if (values.size() > 1) {
        LOG.info("Only a single location can be selected to create empty folder");
        alert.info("selectSingleLocation");
        return;
    }

    final Optional<TreeItem<Ds3TreeTableValue>> first = values.stream().findFirst();
    if (first.isPresent()) {
        final TreeItem<Ds3TreeTableValue> ds3TreeTableValueTreeItem = first.get();

        final String destinationDirectory = ds3TreeTableValueTreeItem.getValue().getDirectoryName();

        final ImmutableList<String> buckets = values.stream().map(TreeItem::getValue)
                .map(Ds3TreeTableValue::getBucketName).distinct().collect(GuavaCollectors.immutableList());
        final Optional<String> bucketElement = buckets.stream().findFirst();
        bucketElement.ifPresent(bucket -> CreateFolderPopup.show(
                new CreateFolderModel(ds3Common.getCurrentSession().getClient(), destinationDirectory, bucket),
                resourceBundle));

        Ds3PanelService.refresh(ds3TreeTableValueTreeItem);
    }
}

From source file:org.eclipse.xtext.ui.generator.trace.ExtensibleTraceURIConverter.java

private ITraceURIConverterContribution getContribution(
        ImmutableList<? extends ITraceURIConverterContribution> allContributions) {
    switch (allContributions.size()) {
    case 0://from  ww  w .  j av  a2s . c  o m
        return new NullContribution();
    case 1:
        return allContributions.get(0);
    default:
        return new CompositeContribution(allContributions);
    }
}

From source file:com.spectralogic.ds3cli.views.cli.GetDataPoliciesView.java

protected String[][] formatTableContents() {

    final ImmutableList.Builder<String[]> builder = ImmutableList.builder();

    for (final DataPolicy dataPolicy : dataPolicies) {
        final String[] arrayEntry = new String[this.columnCount];
        arrayEntry[0] = nullGuardToString(dataPolicy.getName());
        arrayEntry[1] = nullGuardFromDate(dataPolicy.getCreationDate(), DATE_FORMAT);
        arrayEntry[2] = nullGuardToString(dataPolicy.getVersioning());
        arrayEntry[3] = nullGuardToString(dataPolicy.getChecksumType());
        arrayEntry[4] = nullGuardToString(dataPolicy.getEndToEndCrcRequired());
        arrayEntry[5] = nullGuardToString(dataPolicy.getBlobbingEnabled());
        arrayEntry[6] = nullGuardToString(dataPolicy.getDefaultBlobSize());
        arrayEntry[7] = nullGuardToString(dataPolicy.getDefaultGetJobPriority());
        arrayEntry[8] = nullGuardToString(dataPolicy.getDefaultPutJobPriority());
        arrayEntry[9] = nullGuardToString(dataPolicy.getDefaultVerifyJobPriority());
        arrayEntry[10] = nullGuardToString(dataPolicy.getId());
        arrayEntry[11] = nullGuardToString(dataPolicy.getLtfsObjectNamingAllowed());
        builder.add(arrayEntry);//from w  w w. j a  va 2s . co  m
    }

    final ImmutableList<String[]> dataPolicyStrings = builder.build();
    return dataPolicyStrings.toArray(new String[dataPolicyStrings.size()][]);
}

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

private Description checkArrayDimensions(Tree tree, Tree type, VisitorState state) {
    if (!(type instanceof ArrayTypeTree)) {
        return NO_MATCH;
    }//from ww  w  .  ja  va2s.  c o  m
    CharSequence source = state.getSourceCode();
    for (; type instanceof ArrayTypeTree; type = ((ArrayTypeTree) type).getType()) {
        Tree elemType = ((ArrayTypeTree) type).getType();
        int start = state.getEndPosition(elemType);
        int end = state.getEndPosition(type);
        if (start >= end) {
            continue;
        }
        String dim = source.subSequence(start, end).toString();
        if (dim.isEmpty()) {
            continue;
        }
        ImmutableList<ErrorProneToken> tokens = ErrorProneTokens.getTokens(dim.trim(), state.context);
        if (tokens.size() > 2 && tokens.get(0).kind() == TokenKind.IDENTIFIER) {
            int nonWhitespace = CharMatcher.isNot(' ').indexIn(dim);
            int idx = dim.indexOf("[]", nonWhitespace);
            if (idx > nonWhitespace) {
                String replacement = dim.substring(idx, dim.length()) + dim.substring(0, idx);
                return describeMatch(tree, SuggestedFix.replace(start, end, replacement));
            }
        }
    }
    return NO_MATCH;
}

From source file:com.torodb.kvdocument.values.TwelveBytesValue.java

public TwelveBytesValue(ImmutableList<Byte> bytes) {
    Preconditions.checkArgument(bytes.size() <= 12,
            "The list size must be equal or smaller than 12 but " + bytes.size() + " were recived");

    if (bytes.size() == 12) {
        this.bytes = bytes;
    } else {//  w w  w .  ja  v  a2s.  co m
        ImmutableList.Builder<Byte> builder = ImmutableList.builder();
        for (int i = 11; i >= bytes.size(); i--) {
            builder.add((byte) 0);
        }
        builder.addAll(bytes);
        this.bytes = bytes;
    }
    assert this.bytes.size() == 12;
    assert bytes.subList(12 - bytes.size(), 12).equals(bytes);
}

From source file:com.facebook.buck.rules.coercer.QueryTargetsAndOutputsMacroTypeCoercer.java

@Override
public QueryTargetsAndOutputsMacro coerce(CellPathResolver cellRoots, ProjectFilesystem filesystem,
        Path pathRelativeToProjectRoot, TargetConfiguration targetConfiguration, ImmutableList<String> args)
        throws CoerceFailedException {
    String separator = " ";
    String query;//w  w w.  j a v a 2s.  c om
    if (args.size() == 2) {
        separator = args.get(0);
        query = args.get(1);
    } else if (args.size() == 1) {
        query = args.get(0);
    } else {
        throw new CoerceFailedException("One quoted query expression is expected, or a separator and a query");
    }
    return QueryTargetsAndOutputsMacro.of(separator,
            queryCoercer.coerce(cellRoots, filesystem, pathRelativeToProjectRoot, targetConfiguration, query));
}

From source file:bots.mctsbot.ai.bots.bot.gametree.mcts.strategies.selection.UCTPlusPlusSelector.java

@Override
public INode select(InnerNode innerNode) {
    ImmutableList<INode> children = innerNode.getChildren();
    double[] probabilities = innerNode.getProbabilities();
    double[] cumulSums = new double[children.size()];
    double cumulSum = 0;
    for (int i = 0; i < children.size(); i++) {
        double weight = probabilities[i] * children.get(i).getEVStdDev();
        cumulSum += weight;/*from  w ww  .ja  v a 2  s .co  m*/
        cumulSums[i] = cumulSum;
    }
    double randVar = random.nextDouble() * cumulSum;
    for (int i = 0; i < cumulSums.length; i++) {
        if (randVar < cumulSums[i]) {
            return children.get(i);
        }
    }
    return children.get(cumulSums.length - 1);
}

From source file:com.palantir.typescript.search.SearchResultPage.java

@Override
public Match[] getDisplayedMatches(Object element) {
    if (element instanceof LineResult) {
        LineResult lineResult = (LineResult) element;
        ImmutableList<FindReferenceMatch> matches = lineResult.getMatches();

        return matches.toArray(new Match[matches.size()]);
    } else if (element instanceof IResource) {
        SearchResult input = (SearchResult) this.getInput();

        return input.getMatches(element);
    }/*from ww  w.  ja  v a2 s. co m*/

    return super.getDisplayedMatches(element);
}

From source file:com.github.rinde.opt.localsearch.Schedule.java

private Schedule(C s, ImmutableList<ImmutableList<T>> r, IntList si, DoubleList ovs, double ov,
        RouteEvaluator<C, T> eval) {
    checkArgument(r.size() == si.size());
    checkArgument(r.size() == ovs.size());
    context = s;/*ww  w .j a va 2s .  c  om*/
    routes = r;
    startIndices = si;
    objectiveValues = ovs;
    objectiveValue = ov;
    evaluator = eval;
}