List of usage examples for com.google.common.collect ImmutableList size
int size();
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 a v a 2 s . co 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.Ds3ElementUtil.java
/** * Gets the Xml tag name for an element from its list of Ds3Annotations, if one * exists. If multiple Xml tag names are found, an exception is thrown. *///w ww . j ava 2 s . c o m protected static String getXmlTagFromAllAnnotations(final ImmutableList<Ds3Annotation> annotations, final String elementName) { if (isEmpty(annotations)) { return ""; } final ImmutableList.Builder<String> builder = ImmutableList.builder(); for (final Ds3Annotation annotation : annotations) { final String curXmlName = getXmlTagFromAnnotation(annotation); if (hasContent(curXmlName)) { builder.add(curXmlName); } } final ImmutableList<String> xmlNames = builder.build(); switch (xmlNames.size()) { case 0: return ""; case 1: return xmlNames.get(0); default: throw new IllegalArgumentException( "There are multiple xml tag names described within the annotations for the element " + elementName + ": " + xmlNames.toString()); } }
From source file:com.google.template.soy.incrementaldomsrc.RemoveUnnecessaryEscapingDirectives.java
private static ImmutableList<SoyPrintDirective> filterEscapingDirectives( ImmutableList<SoyPrintDirective> escapingDirectives) { for (int i = 0; i < escapingDirectives.size(); i++) { SoyPrintDirective directive = escapingDirectives.get(i); if (canSkip(directive)) { ImmutableList.Builder<SoyPrintDirective> builder = ImmutableList.builder(); builder.addAll(escapingDirectives.subList(0, i)); for (; i < escapingDirectives.size(); i++) { directive = escapingDirectives.get(i); if (!canSkip(directive)) { builder.add(directive); }/*ww w . j a v a 2 s. c o m*/ } return builder.build(); } } return escapingDirectives; }
From source file:org.asoem.greyfish.utils.collect.BitSets.java
/** * Parses a string of '0' and '1' characters interpreted in big-endian format and transforms it into a BitSet. * <p>Whitespaces are ignored.</p> * * @param s the input string// w ww.j a v a 2 s.co m * @return A {@code BitSet} whose bits at indices are set to {@code true}, when the reversed input string has a '1' * character at the same index. */ public static BitSet parse(final String s) { checkNotNull(s); checkArgument(s.matches("^[01]*$"), "Invalid characters (other than '0' or '1') in string: %s", s); final ImmutableList<Character> characters = Lists.charactersOf(s); final BitSet bitSet = new BitSet(characters.size()); for (int i = 0, j = characters.size() - 1; i < characters.size() && j >= 0; i++, j--) { final Character character = characters.get(j); switch (character) { case '1': bitSet.set(i); break; case '0': break; default: if (!Character.isWhitespace(character)) { throw new IllegalArgumentException("Invalid character at position " + j); } } } return bitSet; }
From source file:uk.bl.wa.extract.LinkExtractor.java
public static String extractPublicSuffixFromHost(String host) { if (host == null) return null; // Parse out the public suffix: InternetDomainName domainName;// w ww. j a v a 2 s.c om try { domainName = InternetDomainName.from(host); } catch (Exception e) { return null; } InternetDomainName suffix = null; if (host.endsWith(".uk")) { ImmutableList<String> parts = domainName.parts(); if (parts.size() >= 2) { suffix = InternetDomainName.from(parts.get(parts.size() - 2) + "." + parts.get(parts.size() - 1)); } } else { suffix = domainName.publicSuffix(); } // Return a value: if (suffix == null) return null; return suffix.toString(); }
From source file:com.facebook.buck.core.graph.transformation.TransformationStageMap.java
static TransformationStageMap from(ImmutableList<GraphTransformationStage<?, ?>> stages) { ImmutableMap.Builder<Class<? extends ComputeKey<?>>, GraphTransformationStage<?, ?>> mapBuilder = ImmutableMap .builderWithExpectedSize(stages.size()); for (GraphTransformationStage<?, ?> stage : stages) { mapBuilder.put(stage.getKeyClass(), stage); }/* ww w. ja v a 2 s . c om*/ return new TransformationStageMap(mapBuilder.build()); }
From source file:com.spectralogic.ds3autogen.test.helpers.ResponseTypeConverterHelper.java
/** * Verifies that a list of ResponseTypes that were generated by this utility have been * properly updated.// w ww . j ava 2 s . co m * @param updatedResponseTypes The list of updated Response Types * @param originalResponseTypes The list of original Response Types that needed updating * @param variation The name variation used to auto populate unique Response Type names */ public static void verifyPopulatedResponseTypeList(final ImmutableList<Ds3ResponseType> updatedResponseTypes, final ImmutableList<Ds3ResponseType> originalResponseTypes, final String variation) { assertThat(updatedResponseTypes.size(), is(4)); assertThat(updatedResponseTypes.get(0), is(originalResponseTypes.get(0))); assertThat(updatedResponseTypes.get(2), is(originalResponseTypes.get(2))); assertThat(updatedResponseTypes.get(1).getType(), is("SimpleComponentType" + variation + "List")); assertThat(updatedResponseTypes.get(1).getComponentType(), is(nullValue())); assertThat(updatedResponseTypes.get(3).getType(), is("com.spectralogic.s3.common.dao.domain.ds3.BucketAcl" + variation + "List")); assertThat(updatedResponseTypes.get(3).getComponentType(), is(nullValue())); }
From source file:com.spectralogic.ds3cli.helpers.Util.java
public static int countLocalFiles() throws IOException { final ImmutableList<Path> files = FileUtils.listObjectsForDirectory(Paths.get(DOWNLOAD_BASE_NAME)); return files.size(); }
From source file:net.techcable.pineapple.collect.ImmutableLists.java
@Nonnull public static <T, U> ImmutableList<U> transform(ImmutableList<T> list, Function<T, U> transformer) { ImmutableList.Builder<U> resultBuilder = builder(checkNotNull(list, "Null list").size()); for (int i = 0; i < list.size(); i++) { T oldElement = list.get(i);/*from w ww . ja v a2 s . c o m*/ U newElement = checkNotNull(transformer, "Null transformer").apply(oldElement); if (newElement == null) throw new NullPointerException( "Transformer " + transformer.getClass().getTypeName() + " returned null."); resultBuilder.add(newElement); } return resultBuilder.build(); }
From source file:com.google.caliper.worker.instrument.WorkerInstrumentModule.java
private static Method findBenchmarkMethod(Class<?> benchmark, String methodName, ImmutableList<String> methodParameterClasses) { Class<?>[] params = new Class<?>[methodParameterClasses.size()]; for (int i = 0; i < methodParameterClasses.size(); i++) { try {// w w w . j av a2 s.c om String typeName = methodParameterClasses.get(i); Class<?> primitiveType = PRIMITIVE_TYPES.get(typeName); if (primitiveType != null) { params[i] = primitiveType; } else { params[i] = Util.loadClass(typeName); } } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } try { return benchmark.getDeclaredMethod(methodName, params); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } catch (SecurityException e) { // assertion error? throw new RuntimeException(e); } }