List of usage examples for com.google.common.collect ImmutableList get
E get(int index);
From source file:net.techcable.pineapple.collect.ImmutableMaps.java
@SuppressWarnings("unchecked") public static <K, V> void forEach(ImmutableMap<K, V> map, BiConsumer<? super K, ? super V> action) { checkNotNull(map, "Null map"); if (ENTRIES_ARRAY_FIELD != null && ENTRIES_ARRAY_FIELD.getDeclaringClass().isInstance(map)) { for (Map.Entry<K, V> entry : ENTRIES_ARRAY_FIELD.get(map)) { K key = entry.getKey();//from w w w . jav a 2 s . co m V value = entry.getValue(); checkNotNull(action, "Null action").accept(key, value); } } else { ImmutableList<Map.Entry<K, V>> entryList = map.entrySet().asList(); // Since they don't support forEach this is the fastest way to iterate for (int i = 0; i < entryList.size(); i++) { Map.Entry<K, V> entry = entryList.get(i); action.accept(entry.getKey(), entry.getValue()); } } }
From source file:com.google.devtools.build.lib.remote.RemoteSpawnRunner.java
private static void passRemoteOutErr(RemoteActionCache cache, ActionResult result, FileOutErr outErr) throws CacheNotFoundException { 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)); }
From source file:com.google.caliper.util.Util.java
public static <T> ImmutableBiMap<T, String> assignNames(Set<T> items) { ImmutableList<T> itemList = ImmutableList.copyOf(items); ImmutableBiMap.Builder<T, String> itemNamesBuilder = ImmutableBiMap.builder(); for (int i = 0; i < itemList.size(); i++) { itemNamesBuilder.put(itemList.get(i), generateUniqueName(i)); }/*from ww w . ja v a 2 s . c om*/ return itemNamesBuilder.build(); }
From source file:com.google.devtools.build.lib.skyframe.AbstractLabelCycleReporter.java
/** * Prints the SkyKey-s in cycle into cycleMessage using the print function. *///from w w w. ja va2 s . co 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; }
From source file:com.spectralogic.ds3contractcomparator.print.htmlprinter.generators.row.ModifiedHtmlRowGenerator.java
/** * Retrieves the name of the unique property of the class within the lists {@code T}. * Either {@code oldObjectList} or {@code newObjectList} can be null or empty, but * there must exist at least one instance of {@code T} within at least one list. * @param oldObjectList List of objects from the old contract * @param newObjectList List of objects from the new contract *//* w w w.j a v a2 s .c o m*/ static <T> String getPropertyNameFromList(final ImmutableList<T> oldObjectList, final ImmutableList<T> newObjectList) { final T oldObject = hasContent(oldObjectList) ? oldObjectList.get(0) : null; final T newObject = hasContent(newObjectList) ? newObjectList.get(0) : null; return getPropertyName(oldObject, newObject); }
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 * <grouping>[/<name>]. * /*from w w w .java 2 s . co 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.spectralogic.ds3autogen.test.helpers.RemoveDollarSignConverterHelper.java
/** * Checks if a list of Ds3Response codes generated by the createPopulatedResponseCodes * function has successfully changed all type names by removing the '$' symbol *//*from w w w . ja v a 2 s. c o m*/ public static void checkAutoPopulatedResponseCodes(final ImmutableList<Ds3ResponseCode> responseCodes) { assertThat(responseCodes.size(), is(2)); final ImmutableList<Ds3ResponseType> firstResponseTypes = responseCodes.get(0).getDs3ResponseTypes(); assertThat(firstResponseTypes.size(), is(2)); assertThat(firstResponseTypes.get(0).getType(), is("com.test.package.Type1")); assertThat(firstResponseTypes.get(0).getComponentType(), is("com.test.package.Type2")); assertThat(firstResponseTypes.get(1).getType(), is("com.test.package.Type3")); assertThat(firstResponseTypes.get(1).getComponentType(), is("com.test.package.Type4")); final ImmutableList<Ds3ResponseType> secondResponseTypes = responseCodes.get(1).getDs3ResponseTypes(); assertThat(secondResponseTypes.size(), is(2)); assertThat(secondResponseTypes.get(0).getType(), is("com.test.package.Type1")); assertThat(secondResponseTypes.get(0).getComponentType(), is("com.test.package.Type2")); assertThat(secondResponseTypes.get(1).getType(), is("com.test.package.Type3")); assertThat(secondResponseTypes.get(1).getComponentType(), is("com.test.package.Type4")); }
From source file:com.spectralogic.ds3autogen.utils.ResponsePayloadUtil.java
/** * Retrieves the non-error non-null response payload associated with the request. * If one does not exist, then null is returned *//*from ww w . j a v a 2 s . c o m*/ public static String getResponsePayload(final ImmutableList<Ds3ResponseCode> responseCodes) { if (!hasResponsePayload(responseCodes)) { return null; } final ImmutableList.Builder<String> builder = ImmutableList.builder(); for (final String payload : getAllResponseTypes(responseCodes)) { if (!payload.equalsIgnoreCase("null")) { builder.add(payload); } } final ImmutableList<String> responsePayloads = builder.build(); switch (responsePayloads.size()) { case 0: return null; case 1: return responsePayloads.get(0); default: throw new IllegalArgumentException("Request has multiple non-error response payloads"); } }
From source file:org.eigenbase.rel.rules.AggregateStarTableRule.java
private static int find(ImmutableList<Lattice.Measure> measures, Pair<Aggregation, List<Integer>> seek) { for (int i = 0; i < measures.size(); i++) { Lattice.Measure measure = measures.get(i); if (measure.agg.equals(seek.left) && measure.argOrdinals().equals(seek.right)) { return i; }/* ww w . java2 s.c om*/ } return -1; }
From source file:org.apache.calcite.rel.rules.AggregateStarTableRule.java
private static int find(ImmutableList<Lattice.Measure> measures, Pair<SqlAggFunction, List<Integer>> seek) { for (int i = 0; i < measures.size(); i++) { Lattice.Measure measure = measures.get(i); if (measure.agg.equals(seek.left) && measure.argOrdinals().equals(seek.right)) { return i; }// w w w . j av a 2 s. c om } return -1; }