List of usage examples for com.google.common.collect ImmutableList get
E get(int index);
From source file:com.github.rinde.opt.localsearch.Swaps.java
static <T> ImmutableList<T> replace(ImmutableList<T> list, IntList indices, ImmutableList<T> elements) { checkIndices(indices, elements);//from w w w .j a v a 2 s . c o m final List<T> newL = newArrayList(list); for (int i = 0; i < indices.size(); i++) { newL.set(indices.getInt(i), elements.get(i)); } return ImmutableList.copyOf(newL); }
From source file:de.ii.xtraplatform.feature.provider.pgis.MixAndMatch.java
public static <T> Source<T, NotUsed> create(Predicate<Pair<T, T>> matcher, Source<T, NotUsed>... sources) { ImmutableList<Source<T, ?>> sourcesList = ImmutableList.copyOf(sources); return Source.combine(sourcesList.get(0), sourcesList.get(1), sourcesList.size() > 2 ? sourcesList.subList(2, sourcesList.size()) : ImmutableList.of(), numberOfSources -> new MixAndMatchStage<>(numberOfSources, matcher)); }
From source file:de.ii.xtraplatform.feature.provider.pgis.MixAndMatch.java
public static <T> Source<T, NotUsed> create(Map<Integer, List<Integer>> sourceNesting, Map<Integer, Predicate<Pair<T, T>>> matchers, int mainSourceIndex, Source<T, NotUsed>... sources) { ImmutableList<Source<T, ?>> sourcesList = ImmutableList.copyOf(sources); return Source.combine(sourcesList.get(0), sourcesList.get(1), sourcesList.size() > 2 ? sourcesList.subList(2, sourcesList.size()) : ImmutableList.of(), numberOfSources -> new MixAndMatchStage<>(numberOfSources, sourceNesting, matchers, mainSourceIndex));//from ww w.j av a 2 s. com }
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 w w w. j a v a2 s.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(); } }
From source file:org.glowroot.local.store.Schemas.java
private static void createTable(@Untainted String tableName, ImmutableList<Column> columns, Connection connection) throws SQLException { StringBuilder sql = new StringBuilder(); sql.append("create table "); sql.append(tableName);//www . j av a 2 s . com sql.append(" ("); for (int i = 0; i < columns.size(); i++) { if (i > 0) { sql.append(", "); } String sqlTypeName = sqlTypeNames.get(columns.get(i).type()); checkNotNull(sqlTypeName, "Unexpected sql type: %s", columns.get(i).type()); sql.append(columns.get(i).name()); sql.append(" "); sql.append(sqlTypeName); if (columns.get(i).primaryKey()) { sql.append(" primary key"); } else if (columns.get(i).identity()) { sql.append(" identity"); } } sql.append(")"); execute(castUntainted(sql.toString()), connection); if (tableNeedsUpgrade(tableName, columns, connection)) { logger.warn("table {} thinks it still needs to be upgraded, even after it was just" + " upgraded", tableName); } }
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); }// w w w . ja v a 2s .c om 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:com.google.template.soy.shared.internal.MainEntryPointUtils.java
/** * Maps output paths to indices of inputs that should be emitted to them. * * @param locale The locale for the file path, or null if not applicable. * @param outputPathFormat The format string defining how to format output file paths. * @param inputPathsPrefix The input path prefix, or empty string if none. * @param fileNodes A list of the SoyFileNodes being written. * @return A map of output file paths to their respective input indicies. *//* w ww . j a v a2s.c om*/ public static Multimap<String, Integer> mapOutputsToSrcs(@Nullable String locale, String outputPathFormat, String inputPathsPrefix, ImmutableList<SoyFileNode> fileNodes) { Multimap<String, Integer> outputs = ArrayListMultimap.create(); // First, check that the parent directories for all output files exist, and group the output // files by the inputs that go there. // This means that the compiled source from multiple input files might be written to a single // output file, as is the case when there are multiple inputs, and the output format string // contains no wildcards. for (int i = 0; i < fileNodes.size(); ++i) { SoyFileNode inputFile = fileNodes.get(i); String inputFilePath = inputFile.getFilePath(); String outputFilePath = MainEntryPointUtils.buildFilePath(outputPathFormat, locale, inputFilePath, inputPathsPrefix); BaseUtils.ensureDirsExistInPath(outputFilePath); outputs.put(outputFilePath, i); } return outputs; }
From source file:com.facebook.presto.sql.planner.iterative.rule.ExtractSpatialJoins.java
private static QualifiedObjectName toQualifiedObjectName(String name, String catalog, String schema) { ImmutableList<String> ids = ImmutableList.copyOf(Splitter.on('.').split(name)); if (ids.size() == 3) { return new QualifiedObjectName(ids.get(0), ids.get(1), ids.get(2)); }/* ww w .j a v a 2 s .c om*/ if (ids.size() == 2) { return new QualifiedObjectName(catalog, ids.get(0), ids.get(1)); } if (ids.size() == 1) { return new QualifiedObjectName(catalog, schema, ids.get(0)); } throw new PrestoException(INVALID_SPATIAL_PARTITIONING, format("Invalid name: %s", name)); }
From source file:com.google.template.soy.jbcsrc.Expression.java
/** * Checks that the given expressions are compatible with the given types. */// w ww. jav a 2s.co m static void checkTypes(ImmutableList<Type> types, Iterable<? extends Expression> exprs) { int size = Iterables.size(exprs); checkArgument(size == types.size(), "Supplied the wrong number of parameters. Expected %s, got %s", types.size(), size); int i = 0; for (Expression expr : exprs) { expr.checkAssignableTo(types.get(i), "Parameter %s", i); i++; } }
From source file:com.analog.lyric.collect.Supers.java
/** * Returns a new array containing {@code elements}, which must be a subclass of {@code rootClass}, * with component type set to nearest common superclass ({@link #nearestCommonSuperClass(Object...)}) * of the objects it contains that is no deeper than {@code maxClassDepthBelowRoot} below {@code rootClass}. * //from ww w.ja v a 2 s. c om * @see #narrowArrayOf(Object...) * @see #copyOf(Class, Object...) */ public static <T> T[] narrowArrayOf(Class<? extends Object> rootClass, int maxRelativeClassDepth, T[] elements) { if (elements.length == 0) { if (rootClass.equals(elements.getClass().getComponentType())) { return elements; } else { @SuppressWarnings("unchecked") final T[] array = (T[]) Array.newInstance(rootClass, 0); return array; } } Class<?> c = nearestCommonSuperClass(elements); if (maxRelativeClassDepth < 500) { ImmutableList<Class<?>> supers = superClasses(c); final int maxClassDepth = numberOfSuperClasses(rootClass) + maxRelativeClassDepth; if (maxClassDepth < supers.size()) { c = supers.get(maxClassDepth); } } return copyOf(c, elements); }