List of usage examples for com.google.common.collect ImmutableList get
E get(int index);
From source file:org.xlrnet.tibaija.commands.math.BinaryCommand.java
@NotNull @Override//from ww w .ja va 2 s .c o m protected Optional<Value> execute(@NotNull ImmutableList<Parameter> arguments) { final Value lhs = arguments.get(0).value(); final Value rhs = arguments.get(1).value(); final Value result = applyOperator(lhs, rhs); LOGGER.debug("({}) {} {} -> {}", operator, lhs.getValue(), rhs.getValue(), result.getValue()); return Optional.of(result); }
From source file:com.github.explainable.sql.ast.expression.SqlSubSelect.java
@Nullable @Override//from ww w . ja v a2 s. c o m public EqualityArg equalityArg() { if (select instanceof SqlPlainSelect) { ImmutableList<SqlSelectItem> items = ((SqlPlainSelect) select).selectItems().itemList(); if (items.size() == 1) { SqlSelectItem item = items.get(0); if (item instanceof SqlSelectColumn) { return ((SqlSelectColumn) item).value().equalityArg(); } } } return null; }
From source file:com.facebook.buck.query.RdepsFunction.java
/** * Evaluates to the reverse dependencies of the argument 'x' in the transitive closure of the * set 'u'. Breadth first search from the set 'x' until there are no more unvisited nodes in the * reverse transitive closure or the maximum depth (if supplied) is reached. *///www.ja va 2 s .c o m @Override public Set<QueryTarget> eval(QueryEnvironment env, ImmutableList<Argument> args, ListeningExecutorService executor) throws QueryException, InterruptedException { Set<QueryTarget> universeSet = args.get(0).getExpression().eval(env, executor); env.buildTransitiveClosure(universeSet, Integer.MAX_VALUE, executor); Predicate<QueryTarget> inUniversePredicate = env.getTransitiveClosure(universeSet)::contains; // LinkedHashSet preserves the order of insertion when iterating over the values. // The order by which we traverse the result is meaningful because the dependencies are // traversed level-by-level. Set<QueryTarget> visited = new LinkedHashSet<>(); Set<QueryTarget> argumentSet = args.get(1).getExpression().eval(env, executor); Collection<QueryTarget> current = argumentSet; int depthBound = args.size() > 2 ? args.get(2).getInteger() : Integer.MAX_VALUE; // Iterating depthBound+1 times because the first one processes the given argument set. for (int i = 0; i <= depthBound; i++) { // Restrict the search to nodes in the transitive closure of the universe set. Iterable<QueryTarget> currentInUniverse = Iterables.filter(current, inUniversePredicate); // Filter nodes visited before. Collection<QueryTarget> next = env .getReverseDeps(Iterables.filter(currentInUniverse, Predicates.not(visited::contains))); Iterables.addAll(visited, currentInUniverse); if (next.isEmpty()) { break; } current = next; } return visited; }
From source file:org.apache.james.mailetcontainer.impl.matchers.And.java
private Set<MailAddress> computeIntersection(ImmutableList<Set<MailAddress>> individualMatchedResults) { if (individualMatchedResults.size() == 0) { return ImmutableSet.of(); }/*w w w . j a va 2 s . c om*/ if (individualMatchedResults.size() == 1) { return individualMatchedResults.get(0); } return Sets.intersection(individualMatchedResults.get(0), computeIntersection(individualMatchedResults.subList(1, individualMatchedResults.size()))); }
From source file:org.xlrnet.tibaija.commands.math.BinaryCommand.java
/** * Check if both arguments are of a numerical type and not null. * * @param arguments/* ww w . ja v a2 s . c o m*/ * The arguments for the command. * @return True if both arguments are of a numerical type and not null. */ @Override protected boolean hasValidArgumentValues(@NotNull ImmutableList<Parameter> arguments) { final Value lhs = arguments.get(0).value(); final Value rhs = arguments.get(1).value(); checkNotNull(lhs); checkNotNull(rhs); if (operator == BinaryCommandOperator.PLUS && lhs.isString()) { // Type check for string concatenation if (!rhs.isString()) throw new IllegalTypeException( "Right hand side of concatenation expression is not a string: " + rhs.getValue(), Variables.VariableType.STRING, rhs.getType()); } else { if (!ValueUtils.isNumberOrList(lhs)) throw new IllegalTypeException( "Left hand side of expression is not a list or number: " + lhs.getValue(), Variables.VariableType.NUMBER, lhs.getType()); if (!ValueUtils.isNumberOrList(rhs)) throw new IllegalTypeException( "Right hand side of expression is not a list or number: " + rhs.getValue(), Variables.VariableType.NUMBER, rhs.getType()); } return true; }
From source file:org.ambraproject.service.migration.BootstrapMigratorServiceImpl.java
/** * Apply all migrations./*from www . ja va 2 s.c om*/ * * @throws Exception on an error */ public void migrate() throws Exception { ImmutableList<Migration> migrations = Migrations.getAllMigrations(); int binaryVersion = migrations.get(migrations.size() - 1).getVersion(); int dbVersion = fetchDatabaseVersion(); //Throws an exception if the database version is further into //the future then this version of the ambra war if (binaryVersion < dbVersion) { log.error("Binary version: " + binaryVersion + ", DB version: " + dbVersion); throw new Exception("The ambra war is out of date with the database, " + "update this war file to the latest version."); } waitForOtherMigrations(); for (Migration migration : migrations) { if (dbVersion < migration.getVersion()) { migration.migrate(hibernateTemplate); } } }
From source file:org.geogit.api.plumbing.merge.MergeFeaturesOp.java
private Feature merge(RevFeature featureA, RevFeature featureB, RevFeature ancestor, RevFeatureType featureType) {/*from w ww . j ava 2 s . c om*/ 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++) { Name name = descriptors.get(i).getName(); Optional<Object> valueAncestor = valuesAncestor.get(i); Optional<Object> valueA = valuesA.get(i); if (!valueA.equals(valueAncestor)) { featureBuilder.set(name, valueA.orNull()); } else { Optional<Object> valueB = valuesB.get(i); if (!valueB.equals(valueAncestor)) { featureBuilder.set(name, valueB.orNull()); } else { featureBuilder.set(name, valueAncestor.orNull()); } } } return featureBuilder.buildFeature(nodeRefA.name()); }
From source file:org.xlrnet.tibaija.matchers.EqualsTIListMatcher.java
public boolean matches(Object actualRaw) { ImmutableList<Complex> actualValues = ((Value) actualRaw).list(); if (actualValues.size() != wantedValues.length) return false; for (int i = 0; i < wantedValues.length; i++) { Complex actual = actualValues.get(i); Complex wanted = wantedValues[i]; if (!internalMatchesSingleComplex(actual, wanted)) return false; }// ww w . j a v a 2 s . c o m return true; }
From source file:com.facebook.buck.rules.query.ClasspathFunction.java
@Override public Set<QueryTarget> eval(QueryEnvironment env, ImmutableList<QueryEnvironment.Argument> args, ListeningExecutorService executor) throws QueryException, InterruptedException { Preconditions.checkArgument(env instanceof GraphEnhancementQueryEnvironment); Set<QueryTarget> targets = args.get(0).getExpression().eval(env, executor); return ((GraphEnhancementQueryEnvironment) env).getClasspath(targets); }
From source file:google.registry.backup.GcsDiffFileLister.java
List<GcsFileMetadata> listDiffFiles(DateTime fromTime) { logger.info("Requested restore from time: " + fromTime); // List all of the diff files on GCS and build a map from each file's upper checkpoint time // (extracted from the filename) to its asynchronously-loaded metadata, keeping only files with // an upper checkpoint time > fromTime. Map<DateTime, ListenableFuture<GcsFileMetadata>> upperBoundTimesToMetadata = new HashMap<>(); Iterator<ListItem> listItems; try {//from w ww. j a v a 2 s .co m // TODO(b/23554360): Use a smarter prefixing strategy to speed this up. listItems = gcsService.list(gcsBucket, new ListOptions.Builder().setPrefix(DIFF_FILE_PREFIX).build()); } catch (IOException e) { throw new RuntimeException(e); } DateTime lastUpperBoundTime = START_OF_TIME; while (listItems.hasNext()) { final String filename = listItems.next().getName(); DateTime upperBoundTime = DateTime.parse(filename.substring(DIFF_FILE_PREFIX.length())); if (isBeforeOrAt(fromTime, upperBoundTime)) { upperBoundTimesToMetadata.put(upperBoundTime, executor.submit(new Callable<GcsFileMetadata>() { @Override public GcsFileMetadata call() throws Exception { return getMetadata(filename); } })); } lastUpperBoundTime = latestOf(upperBoundTime, lastUpperBoundTime); } if (upperBoundTimesToMetadata.isEmpty()) { logger.info("No files found"); return ImmutableList.of(); } // GCS file listing is eventually consistent, so it's possible that we are missing a file. The // metadata of a file is sufficient to identify the preceding file, so if we start from the // last file and work backwards we can verify that we have no holes in our chain (although we // may be missing files at the end). ImmutableList.Builder<GcsFileMetadata> filesBuilder = new ImmutableList.Builder<>(); logger.info("Restoring until: " + lastUpperBoundTime); DateTime checkpointTime = lastUpperBoundTime; while (checkpointTime.isAfter(fromTime)) { GcsFileMetadata metadata; if (upperBoundTimesToMetadata.containsKey(checkpointTime)) { metadata = Futures.getUnchecked(upperBoundTimesToMetadata.get(checkpointTime)); } else { String filename = DIFF_FILE_PREFIX + checkpointTime; logger.info("Patching GCS list; discovered file " + filename); metadata = getMetadata(filename); checkState(metadata != null, "Could not read metadata for file %s", filename); } filesBuilder.add(metadata); checkpointTime = getLowerBoundTime(metadata); } ImmutableList<GcsFileMetadata> files = filesBuilder.build().reverse(); logger.info("Actual restore from time: " + getLowerBoundTime(files.get(0))); logger.infofmt("Found %d files to restore", files.size()); return files; }