List of usage examples for com.google.common.collect ImmutableList get
E get(int index);
From source file:com.facebook.buck.rules.macros.OutputMacroExpander.java
@Override protected OutputMacro parse(BuildTarget target, CellPathResolver cellNames, ImmutableList<String> args) throws MacroException { if (args.size() != 1) { throw new MacroException(String.format("expected exactly one argument (found %d)", args.size())); }/*from w w w . j a v a2s . c om*/ return OutputMacro.of(args.get(0)); }
From source file:se.vlovgr.examresults.parse.ParsedResults.java
/** * Creates a new {@code ParsedResults} instance using the specified immutable * list of immutable course exam instances. The parsed results should have been * parsed from the response to a query. The specified integer value is the total * amount of parts available in the response to the query. If a negative value * is specified, the information will be marked as absent. Also, consider using * the {@link #ParsedResults(ImmutableList)} constructor in such case. * * @param courseExams the course exam instances which have been parsed * @param totalParts the total number of parts available; negative if omitted * @throws NullPointerException if the list or any element is {@code null} *//*from w w w.ja v a 2 s. c o m*/ public ParsedResults(final ImmutableList<CourseExam> courseExams, final int totalParts) { checkNotNull(courseExams, "courseExams null"); for (int i = 0, c = courseExams.size(); i < c; i++) checkNotNull(courseExams.get(i), "courseExams[%s] null", i); this.courseExams = courseExams; this.totalParts = totalParts < 0 ? Optional.<Integer>absent() : Optional.of(totalParts); }
From source file:com.spectralogic.ds3cli.views.cli.TableView.java
public void initTable(final ImmutableList<String> columnHeads) { this.columnCount = columnHeads.size(); // create the header this.header = new ASCIITableHeader[this.columnCount]; for (int i = 0; i < this.columnCount; i++) { header[i] = new ASCIITableHeader(columnHeads.get(i), ASCIITable.ALIGN_LEFT); }// w w w . j a v a2 s . c om }
From source file:org.geogit.repository.DepthSearch.java
/** * @param parent//from www. j a v a 2s . co m * @param directChildName * @return */ public Optional<Node> getDirectChild(RevTree parent, String directChildName, final int subtreesDepth) { if (parent.isEmpty()) { return Optional.absent(); } if (parent.trees().isPresent() || parent.features().isPresent()) { if (parent.trees().isPresent()) { ImmutableList<Node> refs = parent.trees().get(); for (int i = 0; i < refs.size(); i++) { if (directChildName.equals(refs.get(i).getName())) { return Optional.of(refs.get(i)); } } } if (parent.features().isPresent()) { ImmutableList<Node> refs = parent.features().get(); for (int i = 0; i < refs.size(); i++) { if (directChildName.equals(refs.get(i).getName())) { return Optional.of(refs.get(i)); } } } return Optional.absent(); } Integer bucket = refOrder.bucket(directChildName, subtreesDepth); ImmutableSortedMap<Integer, Bucket> buckets = parent.buckets().get(); Bucket subtreeBucket = buckets.get(bucket); if (subtreeBucket == null) { return Optional.absent(); } RevTree subtree = objectDb.get(subtreeBucket.id(), RevTree.class); return getDirectChild(subtree, directChildName, subtreesDepth + 1); }
From source file:org.locationtech.geogig.repository.impl.DepthSearch.java
/** * @param parent//w w w . ja v a 2 s. c o m * @param directChildName * @return */ public Optional<Node> getDirectChild(RevTree parent, String directChildName, final int subtreesDepth) { if (parent.isEmpty()) { return Optional.absent(); } if (!parent.trees().isEmpty() || !parent.features().isEmpty()) { if (!parent.trees().isEmpty()) { ImmutableList<Node> refs = parent.trees(); for (int i = 0; i < refs.size(); i++) { if (directChildName.equals(refs.get(i).getName())) { return Optional.of(refs.get(i)); } } } if (!parent.features().isEmpty()) { ImmutableList<Node> refs = parent.features(); for (int i = 0; i < refs.size(); i++) { if (directChildName.equals(refs.get(i).getName())) { return Optional.of(refs.get(i)); } } } return Optional.absent(); } Integer bucket = refOrder.bucket(directChildName, subtreesDepth); ImmutableSortedMap<Integer, Bucket> buckets = parent.buckets(); Bucket subtreeBucket = buckets.get(bucket); if (subtreeBucket == null) { return Optional.absent(); } RevTree subtree = objectDb.get(subtreeBucket.getObjectId(), RevTree.class); return getDirectChild(subtree, directChildName, subtreesDepth + 1); }
From source file:org.locationtech.geogig.api.plumbing.merge.MergeFeaturesOp.java
@SuppressWarnings("unchecked") private Feature merge(RevFeature featureA, RevFeature featureB, RevFeature ancestor, RevFeatureType featureType) {/*from ww w. ja v a2s . co m*/ SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) featureType.type()); ImmutableList<Optional<Object>> valuesA = featureA.getValues(); ImmutableList<Optional<Object>> valuesB = featureB.getValues(); ImmutableList<Optional<Object>> valuesAncestor = ancestor.getValues(); ImmutableList<PropertyDescriptor> descriptors = featureType.sortedDescriptors(); for (int i = 0; i < descriptors.size(); i++) { PropertyDescriptor descriptor = descriptors.get(i); boolean isGeom = Geometry.class.isAssignableFrom(descriptor.getType().getBinding()); Name name = descriptor.getName(); Optional<Object> valueAncestor = valuesAncestor.get(i); Optional<Object> valueA = valuesA.get(i); Optional<Object> valueB = valuesB.get(i); if (!valueA.equals(valueAncestor)) { Optional<Object> merged = valueA; if (isGeom && !valueB.equals(valueAncestor)) { // true merge is only done with // geometries GeometryAttributeDiff diffB = new GeometryAttributeDiff( Optional.fromNullable((Geometry) valueAncestor.orNull()), Optional.fromNullable((Geometry) valueB.orNull())); merged = (Optional<Object>) diffB.applyOn(valueA); } featureBuilder.set(name, merged.orNull()); } else { featureBuilder.set(name, valueB.orNull()); } } return featureBuilder.buildFeature(nodeRefA.name()); }
From source file:org.geogit.api.porcelain.BlameReport.java
/** * Sets all the missing attributes as having been modified for the last time by the passed * commit./* w w w . j ava 2s . c om*/ * * @param commit */ public void setFirstVersion(RevFeature feature, RevCommit commit) { ImmutableList<Optional<Object>> values = feature.getValues(); for (int i = 0; i < attributes.size(); i++) { String attr = attributes.get(i); if (!changes.containsKey(attr)) { Optional<Object> value = values.get(i); changes.put(attr, new ValueAndCommit(value, commit)); } } }
From source file:com.google.caliper.bridge.LogMessageParser.java
@Override public LogMessage parse(CharSequence text) { // TODO(gak): do this stuff in terms of CharSequence instead of String String string = text.toString(); if (string.startsWith(CONTROL_PREFIX)) { ImmutableList<String> parts = ImmutableList .copyOf(CONTROL_TYPE_SPLITTER.split(string.substring(CONTROL_PREFIX.length()))); Class<? extends CaliperControlLogMessage> messageType = typeMap.inverse().get(parts.get(0)); return gson.fromJson(parts.get(1), messageType); } else {/*from w w w . j a v a2s . c o m*/ Matcher gcMatcher = GC_PATTERN.matcher(string); if (gcMatcher.matches()) { return new GcLogMessage( "Full".equals(gcMatcher.group(1)) ? GcLogMessage.Type.FULL : GcLogMessage.Type.INCREMENTAL, ShortDuration.of(BigDecimal.valueOf(Double.parseDouble(gcMatcher.group(2))), SECONDS)); } Matcher jitMatcher = JIT_PATTERN.matcher(string); if (jitMatcher.matches()) { return new HotspotLogMessage(); } Matcher vmOptionMatcher = VM_OPTION_PATTERN.matcher(string); if (vmOptionMatcher.matches()) { return new VmOptionLogMessage(vmOptionMatcher.group(2), vmOptionMatcher.group(3)); } return new GenericLogMessage(); } }
From source file:com.facebook.buck.rules.macros.QueryOutputsMacroExpander.java
@Override public String expand(BuildTarget target, CellPathResolver cellNames, BuildRuleResolver resolver, ImmutableList<String> input) throws MacroException { if (input.isEmpty()) { throw new MacroException("One quoted query expression is expected"); }/*from w ww . j av a 2 s .c o m*/ String queryExpression = CharMatcher.anyOf("\"'").trimFrom(input.get(0)); return resolveQuery(target, cellNames, resolver, queryExpression).map(queryTarget -> { Preconditions.checkState(queryTarget instanceof QueryBuildTarget); return resolver.getRule(((QueryBuildTarget) queryTarget).getBuildTarget()); }).map(rule -> rule.getProjectFilesystem().resolve(rule.getPathToOutput())).filter(Objects::nonNull) .map(Path::toString).sorted().collect(Collectors.joining(" ")); }
From source file:org.locationtech.geogig.plumbing.index.BuildIndexOp.java
private int indexOf(String attName, RevFeatureType featureType) { ImmutableList<PropertyDescriptor> descriptors = featureType.descriptors(); for (int i = 0; i < descriptors.size(); i++) { String name = descriptors.get(i).getName().getLocalPart(); if (attName.equals(name)) { return i; }//from ww w .java2 s .com } throw new IllegalArgumentException(String.format("Feature type %s has no attribute '%s'", featureType.getName().getLocalPart(), attName)); }