List of usage examples for com.google.common.collect ImmutableList size
int size();
From source file:org.eclipse.buildship.ui.console.RemoveAllTerminatedGradleConsolesAction.java
@Override public void run() { ImmutableList<GradleConsole> terminatedConsoles = getTerminatedConsoles(); ConsolePlugin.getDefault().getConsoleManager() .removeConsoles(terminatedConsoles.toArray(new GradleConsole[terminatedConsoles.size()])); }
From source file:org.apache.aurora.common.args.parsers.RangeParser.java
@Override public Range<Integer> doParse(String raw) throws IllegalArgumentException { ImmutableList<String> numbers = ImmutableList.copyOf(Splitter.on('-').omitEmptyStrings().split(raw)); try {//from w w w .j a v a 2s . com int from = Integer.parseInt(numbers.get(0)); int to = Integer.parseInt(numbers.get(1)); if (numbers.size() != 2) { throw new IllegalArgumentException("Failed to parse the range:" + raw); } if (to < from) { return Range.closed(to, from); } else { return Range.closed(from, to); } } catch (NumberFormatException e) { throw new IllegalArgumentException("Failed to parse the range:" + raw, e); } }
From source file:com.opengamma.collect.io.PropertySet.java
/** * Gets a single value from this property set. * <p>// w w w .ja v a 2s . c om * This returns the value associated with the specified key. * If more than one value, or no value, is associated with the key an exception is thrown. * * @param key the key name * @return the value * @throws IllegalArgumentException if the key does not exist, or if more than one value is associated */ public String getValue(String key) { ArgChecker.notNull(key, "key"); ImmutableList<String> values = keyValueMap.get(key); if (values.size() == 0) { throw new IllegalArgumentException("Unknown key: " + key); } if (values.size() > 1) { throw new IllegalArgumentException("Multiple values for key: " + key); } return values.get(0); }
From source file:com.google.javascript.jscomp.ScopeSubject.java
public DeclarationSubject declares(String name) { AbstractVar<?, ?> var = getVar(name); if (var == null) { ImmutableList<AbstractVar<?, ?>> declared = ImmutableList.copyOf(actual().getAllAccessibleVariables()); ImmutableList<String> names = declared.stream().map(AbstractVar::getName).collect(toImmutableList()); if (names.size() > 10) { names = ImmutableList.<String>builder().addAll(names.subList(0, 9)) .add("and " + (names.size() - 9) + " others").build(); }//w w w . j a v a 2 s . co m failWithBadResults("declares", name, "declares", Joiner.on(", ").join(names)); } return new DeclarationSubject(var); }
From source file:com.google.cloud.firestore.FieldPath.java
/** Encodes a list of field name segments in the server-accepted format. */ private String canonicalString() { ImmutableList<String> segments = getSegments(); StringBuilder builder = new StringBuilder(); for (int i = 0; i < segments.size(); i++) { if (i > 0) { builder.append("."); }//from w ww .j av a2 s.co m // Escape backslashes and backticks. String escaped = segments.get(i); escaped = escaped.replace("\\", "\\\\").replace("`", "\\`"); if (!isValidIdentifier(escaped)) { escaped = '`' + escaped + '`'; } builder.append(escaped); } return builder.toString(); }
From source file:com.facebook.buck.config.resources.AbstractResourcesConfig.java
public ImmutableMap<String, ResourceAmounts> getResourceAmountsPerRuleType() { ImmutableMap.Builder<String, ResourceAmounts> result = ImmutableMap.builder(); ImmutableMap<String, String> entries = getDelegate() .getEntriesForSection(RESOURCES_PER_RULE_SECTION_HEADER); for (String ruleName : entries.keySet()) { ImmutableList<String> configAmounts = getDelegate() .getListWithoutComments(RESOURCES_PER_RULE_SECTION_HEADER, ruleName); Preconditions.checkArgument(configAmounts.size() == ResourceAmounts.RESOURCE_TYPE_COUNT, "Buck config entry [%s].%s contains %s values, but expected to contain %s values " + "in the following order: cpu, memory, disk_io, network_io", RESOURCES_PER_RULE_SECTION_HEADER, ruleName, configAmounts.size(), ResourceAmounts.RESOURCE_TYPE_COUNT); ResourceAmounts amounts = ResourceAmounts.of(Integer.parseInt(configAmounts.get(0)), Integer.parseInt(configAmounts.get(1)), Integer.parseInt(configAmounts.get(2)), Integer.parseInt(configAmounts.get(3))); result.put(ruleName, amounts);/*from w ww . ja v a2s . c o m*/ } return result.build(); }
From source file:org.locationtech.geogig.api.plumbing.diff.DiffPathFilter.java
/** * If this method is called then {@link #treeApplies(String)} returned {@code true} for the pair * of trees the buckets belong to, meaning that {@code treePath} either matches exactly one of * the filters, or is a filter children. If the former, all tree buckets apply. If the later, * only the ones whose simple name/*from w ww . j a va 2 s . c om*/ * <ul> * <li>a filter refers to exactly the same tree than {@code treePath}, in which case all buckets * apply * <li>a filter is a child of {@code treePath}, in which case the bucket applies * </ul> * * @param treePath the path of the tree the bucket belong to * @param bucketIndex * @param bucketDepth * @return */ public boolean bucketApplies(final String treePath, final int bucketIndex, final int bucketDepth) { String filter; for (int i = 0; i < pathFilters.size(); i++) { filter = pathFilters.get(i); if (filter.equals(treePath)) { // all buckets apply if (LOGGER.isTraceEnabled()) { LOGGER.trace("Filter: '{}', tree: '{}', depth: {}, bucket idx {}, applies: {}", filter, treePath, bucketDepth, bucketIndex, true); } return true; } boolean filterIsChildOfTree = NodeRef.isChild(treePath, filter); if (filterIsChildOfTree) { ImmutableList<String> filterSteps = NodeRef.split(filter); ImmutableList<String> treeSteps = NodeRef.split(treePath); String childName = filterSteps.get(treeSteps.size()); int childBucket = ORDER.bucket(childName, bucketDepth); boolean applies = childBucket == bucketIndex; if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Filter: '{}', tree: '{}', depth: {}, bucket idx {}, child bucket: {}, child name: '{}', applies: {}", filter, treePath, bucketDepth, bucketIndex, childBucket, childName, applies); } if (applies) { return true; } } } return false; }
From source file:org.locationtech.geogig.plumbing.diff.DiffPathFilter.java
/** * If this method is called then {@link #treeApplies(String)} returned {@code true} for the pair * of trees the buckets belong to, meaning that {@code treePath} either matches exactly one of * the filters, or is a filter children. If the former, all tree buckets apply. If the later, * only the ones whose simple name// ww w . j ava 2 s. co m * <ul> * <li>a filter refers to exactly the same tree than {@code treePath}, in which case all buckets * apply * <li>a filter is a child of {@code treePath}, in which case the bucket applies * </ul> * * @param treePath the path of the tree the bucket belong to * @param bucketIndex * @return */ public boolean bucketApplies(final String treePath, final BucketIndex bucketIndex) { String filter; for (int i = 0; i < pathFilters.size(); i++) { filter = pathFilters.get(i); if (filter.equals(treePath)) { // all buckets apply if (LOGGER.isTraceEnabled()) { LOGGER.trace("Filter: '{}', tree: '{}', bucket idx {}, applies: {}", filter, treePath, bucketIndex, true); } return true; } boolean filterIsChildOfTree = NodeRef.isChild(treePath, filter); if (filterIsChildOfTree) { ImmutableList<String> filterSteps = NodeRef.split(filter); ImmutableList<String> treeSteps = NodeRef.split(treePath); String childName = filterSteps.get(treeSteps.size()); int childBucket = ORDER.bucket(childName, bucketIndex.depthIndex()); boolean applies = childBucket == bucketIndex.lastIndex().intValue(); if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Filter: '{}', tree: '{}', bucket idx {}, child bucket: {}, child name: '{}', applies: {}", filter, treePath, bucketIndex, childBucket, childName, applies); } if (applies) { return true; } } } return false; }
From source file:org.waveprotocol.box.server.persistence.blocks.impl.SegmentOperationImpl.java
/** * Returns reverted {@link SegmentOperation}. * * @param context the reversed context.// w w w . j a v a2 s.co m */ @Override public SegmentOperationImpl revert(WaveletOperationContext context) { ImmutableList<? extends WaveletOperation> ops = getOperations(); ImmutableList.Builder<WaveletOperation> reverseOps = ImmutableList.builder(); for (int i = ops.size() - 1; i >= 0; i--) { WaveletOperation operation = ops.get(i); try { Preconditions.checkArgument(operation instanceof ReversibleOperation, "Bad operation type"); reverseOps.addAll(((ReversibleOperation) operation).reverse(context)); } catch (OperationException ex) { throw new RuntimeException(ex); } } return new SegmentOperationImpl(reverseOps.build()); }
From source file:com.linkedin.pinot.server.api.resources.TablesResource.java
@GET @Path("/tables/{tableName}/segments") @Produces(MediaType.APPLICATION_JSON)// w w w . ja v a 2 s. c o m @ApiOperation(value = "List table segments", notes = "List segments of table hosted on this server") @ApiResponses(value = { @ApiResponse(code = 200, message = "Success", response = TableSegments.class), @ApiResponse(code = 500, message = "Server initialization error", response = ErrorInfo.class) }) public TableSegments listTableSegments( @ApiParam(value = "Table name including type", required = true, example = "myTable_OFFLINE") @PathParam("tableName") String tableName) { TableDataManager tableDataManager = checkGetTableDataManager(tableName); ImmutableList<SegmentDataManager> segmentDataManagers = tableDataManager.acquireAllSegments(); List<String> segments = new ArrayList<>(segmentDataManagers.size()); for (SegmentDataManager segmentDataManager : segmentDataManagers) { segments.add(segmentDataManager.getSegmentName()); tableDataManager.releaseSegment(segmentDataManager); } return new TableSegments(segments); }