List of usage examples for com.google.common.collect ImmutableList size
int size();
From source file:org.lanternpowered.server.text.gson.JsonTextLiteralSerializer.java
static JsonElement serializeLiteralText(Text text, String content, JsonSerializationContext context, boolean removeComplexity) { final boolean noActionsAndStyle = areActionsAndStyleEmpty(text); final ImmutableList<Text> children = text.getChildren(); if (noActionsAndStyle) { if (children.isEmpty()) { return new JsonPrimitive(content); // Try to make the serialized text object less complex, // like text objects nested in a lot of other // text objects, this seems to happen a lot } else if (removeComplexity && content.isEmpty()) { if (children.size() == 1) { return context.serialize(children.get(0)); } else { return context.serialize(children); }/*from w ww. java2 s . co m*/ } } final JsonObject json = new JsonObject(); json.addProperty(TEXT, content); serialize(json, text, context); return json; }
From source file:com.facebook.stats.mx.StatsUtil.java
private static String serializeHistogram(QuantileDigest digest) { int buckets = 100; long min = digest.getMin(); long max = digest.getMax(); long bucketSize = (max - min + buckets) / buckets; ImmutableList.Builder<Long> boundaryBuilder = ImmutableList.builder(); for (int i = 1; i < buckets + 1; ++i) { boundaryBuilder.add(min + bucketSize * i); }// ww w . jav a2 s.com ImmutableList<Long> boundaries = boundaryBuilder.build(); List<QuantileDigest.Bucket> counts = digest.getHistogram(boundaries); StringBuilder builder = new StringBuilder(); // add bogus bucket (fb303 ui ignores the first one, for whatever reason) builder.append("-1:0:0,"); for (int i = 0; i < boundaries.size(); ++i) { long lowBoundary = min; if (i > 0) { lowBoundary = boundaries.get(i - 1); } builder.append(lowBoundary).append(':').append(Math.round(counts.get(i).getCount())).append(':') .append(Math.round(counts.get(i).getMean())).append(','); } // add a final bucket so that fb303 ui shows the max value builder.append(max); builder.append(":0:0"); return builder.toString(); }
From source file:org.geogig.osm.internal.OSMUnmapOp.java
private static int getPropertyIndex(RevFeatureType type, String name) { ImmutableList<PropertyDescriptor> descriptors = type.descriptors(); for (int i = 0; i < descriptors.size(); i++) { if (descriptors.get(i).getName().getLocalPart().equals(name)) { return i; }/*from w ww .j a v a 2 s. c o m*/ } // shouldn't reach this throw new RuntimeException("wrong field name"); }
From source file:com.google.template.soy.TemplateMetadataSerializer.java
private static ImmutableList<DataAllCallSituationP> protosFromCallSitatuations( ImmutableList<DataAllCallSituation> callSituationList, SoyFileNode fileNode) { ImmutableList.Builder<DataAllCallSituationP> builder = ImmutableList .builderWithExpectedSize(callSituationList.size()); for (DataAllCallSituation call : callSituationList) { builder.add(DataAllCallSituationP.newBuilder() .setTemplateName(call.isDelCall() ? call.getTemplateName() : maybeShortenTemplateName(fileNode.getNamespace(), call.getTemplateName())) .setDelCall(call.isDelCall()) .addAllExplicitlyPassedParameters(call.getExplicitlyPassedParameters()).build()); }//from ww w .j av a 2 s . c o m return builder.build(); }
From source file:net.femtoparsec.binding.property.BeanPropertyHelper.java
/** * <p>Complete a chained list of bean properties with a extra path.</p> * * @param parentPath the parent chained list of properties * @param path the path to append to the chain * @return the new chained list of bean properties *//*from w w w . j av a 2s .c om*/ public static ImmutableList<BeanProperty> completeBeanPropertyList(ImmutableList<BeanProperty> parentPath, String path) { final List<String> tokens = Arrays.asList(path.split("\\.")); //get the type of the last token in the parent path and use it to construct the rest of the path final TypeToken<?> last = parentPath.get(parentPath.size() - 1).getPropertyType(); return buildBeanPropertyList(last, tokens, parentPath); }
From source file:com.google.template.soy.jbcsrc.restricted.Expression.java
/** Checks that the given expressions are compatible with the given types. */ static void checkTypes(ImmutableList<Type> types, Iterable<? extends Expression> exprs) { if (Flags.DEBUG) { int size = Iterables.size(exprs); checkArgument(size == types.size(), "Supplied the wrong number of parameters. Expected %s, got %s", types.size(), size);/*from ww w. ja v a 2s. c o m*/ int i = 0; for (Expression expr : exprs) { expr.checkAssignableTo(types.get(i), "Parameter %s", i); i++; } } }
From source file:org.locationtech.geogig.repository.NodeRef.java
/** * Remove the parent path from the given child path. * //from w w w . ja va 2 s.com * @param parentPath the parent path to remove * @param childPath the child path to remove from * @return the stripped child path */ 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++) { strippedChildPath = appendChild(strippedChildPath, child.get(i)); } return strippedChildPath; }
From source file:org.locationtech.geogig.plumbing.merge.DiffMergeFeaturesOp.java
private static List<Object> getAncestorValues(FeatureDiff mergeIntoDiff, FeatureDiff toMergeDiff, ImmutableList<PropertyDescriptor> descriptors) { final List<Object> ancestorValues; {/* w w w . ja v a 2s .c o m*/ RevFeature ancestor = mergeIntoDiff.getOldFeature() == null ? toMergeDiff.getOldFeature() : mergeIntoDiff.getOldFeature(); if (ancestor == null) { Object[] array = new Optional[descriptors.size()]; ancestorValues = Arrays.asList(array); } else { ancestorValues = new ArrayList<>(ancestor.size()); ancestor.forEach((v) -> ancestorValues.add(v)); } } return ancestorValues; }
From source file:com.google.devtools.build.lib.syntax.FunctionSignature.java
/** * Signatures proper.//from w w w. j ava2 s .c o m * * <p>A signature is a Shape and an ImmutableList of argument variable names * NB: we assume these lists are short, so we may do linear scans. */ public static FunctionSignature create(Shape shape, ImmutableList<String> names) { Preconditions.checkArgument(names.size() == shape.getArguments()); return signatureInterner.intern(new AutoValue_FunctionSignature(shape, names(names))); }
From source file:com.facebook.buck.rust.RustCompileUtils.java
/** * Given a list of sources, return the one which is the root based on the defaults and user * parameters.//from ww w . j ava 2s . c o m * * @param resolver Source path resolver for rule * @param crate Name of crate * @param defaults Default names for this rule (library, binary, etc) * @param sources List of sources * @return The matching source */ public static Optional<SourcePath> getCrateRoot(SourcePathResolver resolver, String crate, Optional<SourcePath> crateRoot, ImmutableSet<String> defaults, Stream<SourcePath> sources) { String crateName = String.format("%s.rs", crate); ImmutableList<SourcePath> res = sources.filter(src -> { String name = resolver.getRelativePath(src).getFileName().toString(); return crateRoot.map(src::equals).orElse(false) || defaults.contains(name) || name.equals(crateName); }).collect(MoreCollectors.toImmutableList()); if (res.size() == 1) { return Optional.of(res.get(0)); } else { return Optional.empty(); } }