List of usage examples for com.google.common.collect ImmutableList size
int size();
From source file:com.github.explainable.sql.table.TempTable.java
/** * Initialization of the table columns occurs the first time this method is called. The return * value is memoized, and the same result is returned on all subsequent calls. * * @return The columns in the table/* www. j av a2 s . c o m*/ */ @Override public ImmutableList<TempColumn> columns() { if (columns == null) { ImmutableList<String> columnNames = body.columnNames(); ImmutableList.Builder<TempColumn> columnsBuilder = ImmutableList.builder(); for (int i = 0; i < columnNames.size(); i++) { columnsBuilder.add(new TempColumn(columnNames.get(i), i, this)); } columns = columnsBuilder.build(); } return columns; }
From source file:org.locationtech.geogig.plumbing.merge.MergeFeaturesOp.java
private Feature merge(RevFeature featureA, RevFeature featureB, RevFeature ancestor, RevFeatureType featureType) {//from w ww . j a v a 2 s . c o m SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) featureType.type()); ImmutableList<PropertyDescriptor> descriptors = featureType.descriptors(); for (int i = 0; i < descriptors.size(); i++) { final PropertyDescriptor descriptor = descriptors.get(i); final boolean isGeom = descriptor instanceof GeometryDescriptor; Name name = descriptor.getName(); Object valueAncestor = ancestor.get(i).orNull(); Object valueA = featureA.get(i).orNull(); Object valueB = featureB.get(i).orNull(); final boolean valueAEqualsAncestor = valueEquals(isGeom, valueA, valueAncestor); if (valueAEqualsAncestor) { featureBuilder.set(name, valueB); } else { Object merged = valueA; featureBuilder.set(name, merged); } } return featureBuilder.buildFeature(nodeRefA.name()); }
From source file:com.forerunnergames.tools.common.Strings.java
/** * Converts a collection of list elements to a string list, separated by separator, in case letterCase. * * @param <T>//from ww w . ja v a 2 s . c om * The type of the list elements. * @param listElements * The collection of list elements to convert, must not be null, must not contain any null elements. * @param separator * The separator that should be added between list elements, must not be null. * @param letterCase * The desired letter case of the list elements, must not be null, choose LetterCase.NONE to leave the list * elements as-is. * @param hasAnd * Whether or not to insert the word 'and ' between the last two elements in the list, one space after the * last separator. * * @return A string list of listElements, separated by separator, in case letterCase, with an optional 'and ' * occurring between the last two elements of the list. */ public static <T> String toStringList(final Collection<T> listElements, final String separator, final LetterCase letterCase, final boolean hasAnd) { Arguments.checkIsNotNull(listElements, "listElements"); Arguments.checkHasNoNullElements(listElements, "listElements"); Arguments.checkIsNotNull(separator, "separator"); Arguments.checkIsNotNull(letterCase, "letterCase"); final ImmutableList.Builder<T> printableListElementsBuilder = ImmutableList.builder(); for (final T element : listElements) { if (isPrintable(element.toString())) printableListElementsBuilder.add(element); } final ImmutableList<T> printableListElements = printableListElementsBuilder.build(); // Handle the first three special cases if (printableListElements.isEmpty()) { return ""; } else if (printableListElements.size() == 1) { return toCase(Iterables.getOnlyElement(printableListElements).toString(), letterCase); } else if (printableListElements.size() == 2) { final Iterator<T> iterator = printableListElements.iterator(); // Here, if the separator is a comma, for example, it's either: // "item1 and item2" or "item1,item2" (if no "and" is desired) // because "item1, and item2" doesn't make sense grammatically, which is // what would happen if we didn't treat this as a special case return toCase(iterator.next().toString() + (hasAnd ? " and " : separator) + iterator.next().toString(), letterCase); } final StringBuilder s = new StringBuilder(); for (final T element : printableListElements) { final String elementString = toCase(element.toString(), letterCase); s.append(elementString).append(separator); } try { // Delete the extra comma at the end of the last element in the list. s.delete(s.length() - separator.length(), s.length()); if (hasAnd && s.lastIndexOf(separator) >= 0) { // Insert the word 'and' between the last two elements in the list, // after the last comma. s.insert(s.lastIndexOf(separator) + 1, "and "); } } catch (final StringIndexOutOfBoundsException ignored) { } return s.toString(); }
From source file:com.facebook.buck.apple.RegisterDebugSymbolsStep.java
@Override public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException { ImmutableList<String> lldbCommandPrefix = lldb.getCommandPrefix(resolver); ProcessExecutorParams params = ProcessExecutorParams.builder() .addCommand(lldbCommandPrefix.toArray(new String[lldbCommandPrefix.size()])).build(); return StepExecutionResult .of(context.getProcessExecutor() .launchAndExecute(params, ImmutableSet.of(), Optional.of(String.format("target create %s\ntarget symbols add %s", resolver.getAbsolutePath(binary), dsymPath)), Optional.empty(), Optional.empty())); }
From source file:org.openqa.selenium.BuckBuild.java
public Path go() throws IOException { Path projectRoot = InProject.locate("Rakefile").toPath().getParent(); if (!isInDevMode()) { // we should only need to do this when we're in dev mode // when running in a test suite, our dependencies should already // be listed. log.info("Not in dev mode. Ignoring attempt to build: " + target); return findOutput(projectRoot); }//from w ww . j a va2 s. co m if (target == null || "".equals(target)) { throw new IllegalStateException("No targets specified"); } System.out.println("\nBuilding " + target + " ..."); ImmutableList.Builder<String> builder = ImmutableList.builder(); findBuck(projectRoot, builder); builder.add("build"); builder.add(target); ImmutableList<String> command = builder.build(); CommandLine commandLine = new CommandLine(command.toArray(new String[command.size()])); commandLine.copyOutputTo(System.err); commandLine.execute(); if (!commandLine.isSuccessful()) { throw new WebDriverException("Build failed! " + target); } return findOutput(projectRoot); }
From source file:com.facebook.buck.rules.coercer.VersionMatchedCollection.java
/** * @return the only item that matches the given version map, or throw. *///from w ww. j a v a 2 s . c om public T getOnlyMatchingValue(ImmutableMap<BuildTarget, Version> selected) { ImmutableList<T> matching = getMatchingValues(selected); Preconditions.checkState(!matching.isEmpty(), "no matches for %s found", selected); Preconditions.checkState(matching.size() < 2, "multiple matches for %s found: %s", selected, matching); return matching.get(0); }
From source file:org.openqa.selenium.build.BuckBuild.java
private Path findOutput(Path projectRoot) throws IOException { ImmutableList.Builder<String> builder = ImmutableList.builder(); findBuck(projectRoot, builder);// w w w.ja va 2 s. com builder.add("targets", "--show-full-output", "--config", "color.ui=never", target); ImmutableList<String> command = builder.build(); CommandLine commandLine = new CommandLine(command.toArray(new String[command.size()])); commandLine.setWorkingDirectory(projectRoot.toAbsolutePath().toString()); commandLine.copyOutputTo(System.err); commandLine.execute(); if (!commandLine.isSuccessful()) { throw new WebDriverException("Unable to find output! " + target); } String stdOut = commandLine.getStdOut(); String[] allLines = stdOut.split(LINE_SEPARATOR.value()); String lastLine = null; for (String line : allLines) { if (line.startsWith(target)) { lastLine = line; break; } } Preconditions.checkNotNull(lastLine, "Value read: %s", stdOut); List<String> outputs = Splitter.on(' ').limit(2).splitToList(lastLine); if (outputs.size() != 2) { throw new WebDriverException(String.format("Unable to find output! %s, %s", target, lastLine)); } Path output = projectRoot.resolve(outputs.get(1)); if (!Files.exists(output)) { throw new WebDriverException( String.format("Found output, but it does not exist: %s, %s", target, output)); } return output; }
From source file:com.google.cloud.firestore.BasePath.java
/** * Returns the path of the parent element. * * @return The new Path or null if we are already at the root. *//*from www. j a v a 2 s . c om*/ @Nullable B getParent() { ImmutableList<String> parts = getSegments(); if (parts.isEmpty()) { return null; } return createPathWithSegments(parts.subList(0, parts.size() - 1)); }
From source file:com.google.devtools.build.skyframe.CycleDeduper.java
/** * Marks a non-empty list representing a cycle of unique values as being seen and returns true * iff the cycle hasn't been seen before, accounting for logical equivalence of cycles. * * For example, the cycle 'a' -> 'b' -> 'c' -> 'a' is represented by the list ['a', 'b', 'c'] * and is logically equivalent to the cycle represented by the list ['b', 'c', 'a']. *//*from w w w. ja v a 2 s .co m*/ public boolean seen(ImmutableList<T> cycle) { ImmutableSet<T> cycleMembers = ImmutableSet.copyOf(cycle); Preconditions.checkState(!cycle.isEmpty()); Preconditions.checkState(cycle.size() == cycleMembers.size(), "cycle doesn't have unique members: " + cycle); if (knownCyclesByMembers.containsEntry(cycleMembers, cycle)) { return false; } // Of the C cycles, suppose there are D cycles that have the same members (but are in an // incompatible order). This code path takes O(D * L) time. The common case is that D is // very small. boolean found = false; for (ImmutableList<T> candidateCycle : knownCyclesByMembers.get(cycleMembers)) { int startPos = candidateCycle.indexOf(cycle.get(0)); // The use of a multimap keyed by cycle members guarantees that the first element of 'cycle' // is present in 'candidateCycle'. Preconditions.checkState(startPos >= 0); if (equalsWithSingleLoopFrom(cycle, candidateCycle, startPos)) { found = true; break; } } // We add the cycle even if it's a duplicate so that future exact copies of this can be // processed in O(L) time. We are already using O(CL) memory, and this optimization doesn't // change that. knownCyclesByMembers.put(cycleMembers, cycle); return !found; }
From source file:com.facebook.buck.query.AbstractBinaryOperatorExpression.java
@Override public String toString() { ImmutableList<QueryExpression> operands = getOperands(); StringBuilder result = new StringBuilder(); for (int i = 1; i < operands.size(); i++) { result.append("("); }/* w w w .j a v a 2 s . c o m*/ result.append(operands.get(0)); for (int i = 1; i < operands.size(); i++) { result.append(" ").append(getOperator()).append(" ").append(operands.get(i)).append(")"); } return result.toString(); }