List of usage examples for com.google.common.collect ImmutableList get
E get(int index);
From source file:com.google.devtools.build.lib.remote.RemoteSpawnStrategy.java
private static void passRemoteOutErr(RemoteActionCache cache, ActionResult result, FileOutErr outErr) { try {//from www. j a v a 2 s . c om ImmutableList<byte[]> streams = cache .downloadBlobs(ImmutableList.of(result.getStdoutDigest(), result.getStderrDigest())); outErr.printOut(new String(streams.get(0), UTF_8)); outErr.printErr(new String(streams.get(1), UTF_8)); } catch (CacheNotFoundException e) { // Ignoring. } }
From source file:com.facebook.buck.io.file.PathListing.java
private static ImmutableSortedSet<Path> subSet(ImmutableSortedSet<Path> paths, FilterMode filterMode, int limitIndex) { // This doesn't copy the contents of the ImmutableSortedSet. We use it // as a simple way to get O(1) access to the set's contents, as otherwise // we would have to iterate to find the Nth element. ImmutableList<Path> pathsList = paths.asList(); boolean fullSet = limitIndex == paths.size(); switch (filterMode) { case INCLUDE: // Make sure we don't call pathsList.get(pathsList.size()). if (!fullSet) { paths = paths.headSet(pathsList.get(limitIndex)); }//from w w w . ja v a2 s .c om break; case EXCLUDE: if (fullSet) { // Make sure we don't call pathsList.get(pathsList.size()). paths = ImmutableSortedSet.of(); } else { paths = paths.tailSet(pathsList.get(limitIndex)); } break; } return paths; }
From source file:com.google.security.zynamics.binnavi.Gui.GraphWindows.types.TypeEditorSearchPanel.java
private static void selectMatches(final ImmutableList<Integer> matchedRows, final TypesTree tree) { if (matchedRows.isEmpty()) { tree.clearSelection();/*w w w . j ava2s. c o m*/ } else { final int[] selectRows = new int[matchedRows.size()]; for (int i = 0; i < matchedRows.size(); i++) { selectRows[i] = matchedRows.get(i); } tree.setSelectionRows(selectRows); } }
From source file:com.palantir.atlasdb.keyvalue.impl.KeyValueServices.java
public static void getFirstBatchForRangeUsingGetRange(KeyValueService kv, String tableName, RangeRequest request, long timestamp, @Output Map<RangeRequest, TokenBackedBasicResultsPage<RowResult<Value>, byte[]>> ret) { if (ret.containsKey(request)) { return;/* w w w .j ava2s .c o m*/ } RangeRequest requestWithHint = request; if (request.getBatchHint() == null) { requestWithHint = request.withBatchHint(100); } final ClosableIterator<RowResult<Value>> range = kv.getRange(tableName, requestWithHint, timestamp); try { int batchSize = requestWithHint.getBatchHint(); final Iterator<RowResult<Value>> withLimit = Iterators.limit(range, batchSize); ImmutableList<RowResult<Value>> results = ImmutableList.copyOf(withLimit); if (results.size() != batchSize) { ret.put(request, SimpleTokenBackedResultsPage.create(request.getEndExclusive(), results, false)); return; } RowResult<Value> last = results.get(results.size() - 1); byte[] lastRowName = last.getRowName(); if (RangeRequests.isTerminalRow(request.isReverse(), lastRowName)) { ret.put(request, SimpleTokenBackedResultsPage.create(lastRowName, results, false)); return; } byte[] nextStartRow = RangeRequests.getNextStartRow(request.isReverse(), lastRowName); if (Arrays.equals(request.getEndExclusive(), nextStartRow)) { ret.put(request, SimpleTokenBackedResultsPage.create(nextStartRow, results, false)); } else { ret.put(request, SimpleTokenBackedResultsPage.create(nextStartRow, results, true)); } } finally { range.close(); } }
From source file:com.spectralogic.ds3autogen.utils.ResponsePayloadUtil.java
/** * Gets the Response Type associated with a Ds3ResponseCode. This assumes that all component * response types have already been converted into encapsulating types, which is done within * the parser module.//from w w w.j a v a 2 s . c o m */ public static String getResponseType(final ImmutableList<Ds3ResponseType> responseTypes) { if (isEmpty(responseTypes)) { throw new IllegalArgumentException("Response code does not contain any associated types"); } switch (responseTypes.size()) { case 1: return responseTypes.get(0).getType(); default: throw new IllegalArgumentException("Response code has multiple associated types"); } }
From source file:com.google.api.codegen.discovery.DefaultString.java
/** * Returns whether the pattern represented by the list is in a form we expect. * * <p>A valid pattern must have the same number of literals and wildcards, alternating, and starts * with a literal. Literals must consists of only letters. *//*from w ww . ja v a 2 s.c o m*/ private static boolean validElems(ImmutableList<Elem> elems) { if (elems.size() % 2 != 0) { return false; } ImmutableList<ElemType> expect = ImmutableList.<ElemType>of(ElemType.LITERAL, ElemType.WILDCARD); for (int i = 0; i < elems.size(); i++) { if (elems.get(i).getType() != expect.get(i % expect.size())) { return false; } } for (int i = 0; i < elems.size(); i += 2) { for (char c : elems.get(i).getLiteral().toCharArray()) { if (!Character.isLetter(c)) { return false; } } } return true; }
From source file:org.apache.druid.segment.incremental.SpatialDimensionRowTransformer.java
/** * Decodes encodedCoordinate./*from w w w . j a va 2 s . c o m*/ * * @param encodedCoordinate encoded coordinate * * @return decoded coordinate, or null if it could not be decoded */ public static float[] decode(final String encodedCoordinate) { if (encodedCoordinate == null) { return null; } final ImmutableList<String> parts = ImmutableList.copyOf(SPLITTER.split(encodedCoordinate)); final float[] coordinate = new float[parts.size()]; for (int i = 0; i < coordinate.length; i++) { final Float floatPart = tryParseFloat(parts.get(i)); if (floatPart == null) { return null; } else { coordinate[i] = floatPart; } } return coordinate; }
From source file:org.geogit.api.NodeRef.java
public static String removeParent(final String parentPath, final String childPath) { checkArgument(isChild(parentPath, childPath)); ImmutableList<String> parent = split(parentPath); ImmutableList<String> child = split(childPath); child = child.subList(parent.size(), child.size()); String strippedChildPath = child.get(0); for (int i = 1; i < child.size(); i++) { appendChild(strippedChildPath, child.get(i)); }// www .j av a 2s.co m return strippedChildPath; }
From source file:com.google.devtools.build.lib.query2.engine.BinaryOperatorExpression.java
/** * Evaluates an expression of the form "e1 - e2 - ... - eK" by noting its equivalence to * "e1 - (e2 + ... + eK)" and evaluating the subexpressions on the right-hand-side in parallel. *//*from ww w . j ava2 s. co m*/ private static <T> void parEvalMinus(ImmutableList<QueryExpression> operands, QueryEnvironment<T> env, VariableContext<T> context, ThreadSafeCallback<T> callback, ForkJoinPool forkJoinPool) throws QueryException, InterruptedException { final Set<T> lhsValue = Sets.newConcurrentHashSet(QueryUtil.evalAll(env, context, operands.get(0))); ThreadSafeCallback<T> subtractionCallback = new ThreadSafeCallback<T>() { @Override public void process(Iterable<T> partialResult) throws QueryException, InterruptedException { for (T target : partialResult) { lhsValue.remove(target); } } }; parEvalPlus(operands.subList(1, operands.size()), env, context, subtractionCallback, forkJoinPool); callback.process(lhsValue); }
From source file:org.apache.hadoop.hive.ql.optimizer.calcite.rules.HivePreFilteringRule.java
private static List<RexNode> extractCommonOperands(RexBuilder rexBuilder, RexNode condition, int maxCNFNodeCount) { assert condition.getKind() == SqlKind.OR; Multimap<String, RexNode> reductionCondition = LinkedHashMultimap.create(); // Data structure to control whether a certain reference is present in every // operand/*from ww w. j a v a 2s .c o m*/ Set<String> refsInAllOperands = null; // 1. We extract the information necessary to create the predicate for the // new filter; currently we support comparison functions, in and between ImmutableList<RexNode> operands = RexUtil.flattenOr(((RexCall) condition).getOperands()); for (int i = 0; i < operands.size(); i++) { final RexNode operand = operands.get(i); final RexNode operandCNF = RexUtil.toCnf(rexBuilder, maxCNFNodeCount, operand); final List<RexNode> conjunctions = RelOptUtil.conjunctions(operandCNF); Set<String> refsInCurrentOperand = Sets.newHashSet(); for (RexNode conjunction : conjunctions) { // We do not know what it is, we bail out for safety if (!(conjunction instanceof RexCall) || !HiveCalciteUtil.isDeterministic(conjunction)) { return new ArrayList<>(); } RexCall conjCall = (RexCall) conjunction; RexNode ref = null; if (COMPARISON.contains(conjCall.getOperator().getKind())) { if (conjCall.operands.get(0) instanceof RexInputRef && conjCall.operands.get(1) instanceof RexLiteral) { ref = conjCall.operands.get(0); } else if (conjCall.operands.get(1) instanceof RexInputRef && conjCall.operands.get(0) instanceof RexLiteral) { ref = conjCall.operands.get(1); } else { // We do not know what it is, we bail out for safety return new ArrayList<>(); } } else if (conjCall.getOperator().getKind().equals(SqlKind.IN)) { ref = conjCall.operands.get(0); } else if (conjCall.getOperator().getKind().equals(SqlKind.BETWEEN)) { ref = conjCall.operands.get(1); } else { // We do not know what it is, we bail out for safety return new ArrayList<>(); } String stringRef = ref.toString(); reductionCondition.put(stringRef, conjCall); refsInCurrentOperand.add(stringRef); } // Updates the references that are present in every operand up till now if (i == 0) { refsInAllOperands = refsInCurrentOperand; } else { refsInAllOperands = Sets.intersection(refsInAllOperands, refsInCurrentOperand); } // If we did not add any factor or there are no common factors, we can // bail out if (refsInAllOperands.isEmpty()) { return new ArrayList<>(); } } // 2. We gather the common factors and return them List<RexNode> commonOperands = new ArrayList<>(); for (String ref : refsInAllOperands) { commonOperands.add(RexUtil.composeDisjunction(rexBuilder, reductionCondition.get(ref), false)); } return commonOperands; }