List of usage examples for com.google.common.collect ImmutableList get
E get(int index);
From source file:com.facebook.buck.rules.coercer.QueryMacroTypeCoercer.java
@Override public M coerce(CellPathResolver cellRoots, ProjectFilesystem filesystem, Path pathRelativeToProjectRoot, TargetConfiguration targetConfiguration, ImmutableList<String> args) throws CoerceFailedException { if (args.size() != 1) { throw new CoerceFailedException(String.format("expected exactly one argument (found %d)", args.size())); }/*from w w w .j av a 2s . co m*/ return factory.apply(queryCoercer.coerce(cellRoots, filesystem, pathRelativeToProjectRoot, targetConfiguration, args.get(0))); }
From source file:com.google.cloud.firestore.BasePath.java
/** * Checks to see if this path is a prefix of (or equals) another path. * * @param path the path to check against * @return true if current path is a prefix of the other path. *///from w w w.j ava 2 s . co m boolean isPrefixOf(BasePath<B> path) { ImmutableList<String> prefixSegments = getSegments(); ImmutableList<String> childSegments = path.getSegments(); if (prefixSegments.size() > path.getSegments().size()) { return false; } for (int i = 0; i < prefixSegments.size(); i++) { if (!prefixSegments.get(i).equals(childSegments.get(i))) { return false; } } return true; }
From source file:de.metanome.backend.input.database.ResultSetWithoutRelationNameFixture.java
public ResultSet getTestData() throws SQLException { ResultSet resultSet = mock(ResultSet.class); ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class); // Expected values // Expected column count when(resultSetMetaData.getColumnCount()).thenReturn(numberOfColumns()); // Simulate SQLException when starting count at 0. when(resultSetMetaData.getTableName(0)).thenThrow(new SQLException()); // Simulate that JDBC driver is not properly reporting relation names (e.g., Redshift). when(resultSetMetaData.getTableName(1)).thenReturn(null); ImmutableList<String> expectedColumnNames = getExpectedColumnNames(); // Simulate SQLException when starting count at 0. when(resultSetMetaData.getColumnName(0)).thenThrow(new SQLException()); for (int i = 0; i < expectedColumnNames.size(); i++) { when(resultSetMetaData.getColumnLabel(i + 1)).thenReturn(expectedColumnNames.get(i)); }/*from w w w . j a va 2 s . c o m*/ // Expected values when calling getMetaData when(resultSet.getMetaData()).thenReturn(resultSetMetaData); // Expected values when calling next when(resultSet.next()).thenReturn(false); return resultSet; }
From source file:com.facebook.buck.rules.coercer.BuildTargetMacroTypeCoercer.java
@Override public M coerce(CellPathResolver cellRoots, ProjectFilesystem filesystem, Path pathRelativeToProjectRoot, TargetConfiguration targetConfiguration, ImmutableList<String> args) throws CoerceFailedException { if (args.size() != 1) { throw new CoerceFailedException(String.format("expected exactly one argument (found %d)", args.size())); }/*from ww w.j av a 2 s .c o m*/ BuildTarget target = buildTargetTypeCoercer.coerce(cellRoots, filesystem, pathRelativeToProjectRoot, targetConfiguration, args.get(0)); return factory.apply(target); }
From source file:org.jenkinsci.plugins.workflow.support.concurrent.ListFuture.java
private void init(final Executor listenerExecutor) { // First, schedule cleanup to execute when the Future is done. addListener(new Runnable() { @Override//from w w w . j a va 2 s. c o m public void run() { // By now the values array has either been set as the Future's value, // or (in case of failure) is no longer useful. ListFuture.this.values = null; // Let go of the memory held by other futures ListFuture.this.futures = null; } }, MoreExecutors.sameThreadExecutor()); // Now begin the "real" initialization. // Corner case: List is empty. if (futures.isEmpty()) { set(Lists.newArrayList(values)); return; } // Populate the results list with null initially. for (int i = 0; i < futures.size(); ++i) { values.add(null); } // Register a listener on each Future in the list to update // the state of this future. // Note that if all the futures on the list are done prior to completing // this loop, the last call to addListener() will callback to // setOneValue(), transitively call our cleanup listener, and set // this.futures to null. // We store a reference to futures to avoid the NPE. ImmutableList<? extends ListenableFuture<? extends V>> localFutures = futures; for (int i = 0; i < localFutures.size(); i++) { final ListenableFuture<? extends V> listenable = localFutures.get(i); final int index = i; listenable.addListener(new Runnable() { @Override public void run() { setOneValue(index, listenable); } }, listenerExecutor); } }
From source file:com.facebook.buck.js.JsBundleGenrule.java
@Override public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) { SourcePathResolver sourcePathResolver = context.getSourcePathResolver(); ImmutableList<Step> buildSteps = super.getBuildSteps(context, buildableContext); OptionalInt lastRmStep = IntStream.range(0, buildSteps.size()).map(x -> buildSteps.size() - 1 - x) .filter(i -> buildSteps.get(i) instanceof RmStep).findFirst(); Preconditions.checkState(lastRmStep.isPresent(), "Genrule is expected to have at least on RmDir step"); ImmutableList.Builder<Step> builder = ImmutableList.<Step>builder() // First, all Genrule steps including the last RmDir step are added .addAll(buildSteps.subList(0, lastRmStep.getAsInt() + 1)) // Our MkdirStep must run after all RmSteps created by Genrule to prevent immediate // deletion of the directory. It must, however, run before the genrule command itself // runs. .add(MkdirStep.of(BuildCellRelativePath.fromCellRelativePath(context.getBuildCellRootPath(), getProjectFilesystem(), sourcePathResolver.getRelativePath(getSourcePathToOutput())))); if (rewriteSourcemap) { // If the genrule rewrites the source map, we have to create the parent dir, and record // the build artifact SourcePath sourcePathToSourceMap = getSourcePathToSourceMap(); buildableContext.recordArtifact(sourcePathResolver.getRelativePath(sourcePathToSourceMap)); builder.add(MkdirStep.of(BuildCellRelativePath.fromCellRelativePath(context.getBuildCellRootPath(), getProjectFilesystem(),/*from w w w . j av a2s. c o m*/ sourcePathResolver.getRelativePath(sourcePathToSourceMap).getParent()))); } if (rewriteMisc) { // If the genrule rewrites the misc folder, we have to create the corresponding dir, and // record its contents SourcePath miscDirPath = getSourcePathToMisc(); buildableContext.recordArtifact(sourcePathResolver.getRelativePath(miscDirPath)); builder.add(MkdirStep.of(BuildCellRelativePath.fromCellRelativePath(context.getBuildCellRootPath(), getProjectFilesystem(), sourcePathResolver.getRelativePath(miscDirPath)))); } // Last, we add all remaining genrule commands after the last RmStep return builder.addAll(buildSteps.subList(lastRmStep.getAsInt() + 1, buildSteps.size())).build(); }
From source file:com.facebook.buck.parser.PerBuildStateFactoryWithConfigurableAttributes.java
private Platform getTargetPlatform(ConfigurationRuleResolver configurationRuleResolver, ConstraintResolver constraintResolver, Cell rootCell, ImmutableList<String> targetPlatforms) { if (targetPlatforms.isEmpty()) { return new ConstraintBasedPlatform("", ImmutableSet.of()); }//from w ww. j av a 2 s . c om String targetPlatformName = targetPlatforms.get(0); ConfigurationRule configurationRule = configurationRuleResolver .getRule(unconfiguredBuildTargetFactory.create(rootCell.getCellPathResolver(), targetPlatformName) .configure(EmptyTargetConfiguration.INSTANCE)); if (!(configurationRule instanceof PlatformRule)) { throw new HumanReadableException( "%s is used as a target platform, but not declared using `platform` rule", targetPlatformName); } PlatformRule platformRule = (PlatformRule) configurationRule; ImmutableSet<ConstraintValue> constraintValues = platformRule.getConstrainValues().stream() .map(constraintResolver::getConstraintValue).collect(ImmutableSet.toImmutableSet()); return new ConstraintBasedPlatform(targetPlatformName, constraintValues); }
From source file:com.google.devtools.build.benchmark.BuildGroupRunner.java
private double buildSingleTargetAndGetElapsedTime(ImmutableList<BuildTargetConfig> buildTargetConfigs, ImmutableList<BuildEnvConfig> buildEnvConfigs, Path buildBinary, int targetIndex, int envIndex) throws CommandException { BuildTargetConfig targetConfig = buildTargetConfigs.get(targetIndex); BuildEnvConfig envConfig = buildEnvConfigs.get(envIndex); // Clean if should if (envConfig.getCleanBeforeBuild()) { builder.clean();//from ww w. jav a2 s. c o m } // Modify generated code if should (only this target) if (envConfig.getIncremental()) { String targetName = targetConfig.getBuildTarget(); targetName = targetName.substring(targetName.lastIndexOf('/') + 1, targetName.length()); CodeGenerator codeGenerator = new JavaCodeGenerator(); codeGenerator.modifyExistingProject( workspace.resolve(GENERATED_CODE_DIR) + codeGenerator.getDirSuffix(), ImmutableSet.of(targetName)); codeGenerator = new CppCodeGenerator(); codeGenerator.modifyExistingProject( workspace.resolve(GENERATED_CODE_DIR) + codeGenerator.getDirSuffix(), ImmutableSet.of(targetName)); } // Remove the first target since it's slow if (targetIndex == 0 && envIndex == 0) { buildTargetAndGetElapsedTime(buildBinary, envConfig, targetConfig); builder.clean(); } return buildTargetAndGetElapsedTime(buildBinary, envConfig, targetConfig); }
From source file:grakn.core.graql.gremlin.GraqlTraversal.java
/** * @return a gremlin traversal that represents this inner query *//*from w w w.ja va2 s . c o m*/ private GraphTraversal<Vertex, Map<String, Element>> getConjunctionTraversal(TransactionOLTP tx, GraphTraversal<Vertex, Vertex> traversal, Set<Variable> vars, ImmutableList<Fragment> fragmentList) { GraphTraversal<Vertex, ? extends Element> newTraversal = traversal; // If the first fragment can operate on edges, then we have to navigate all edges as well if (fragmentList.get(0).canOperateOnEdges()) { newTraversal = traversal.union(__.identity(), __.outE(Schema.EdgeLabel.ATTRIBUTE.getLabel())); } return applyFragments(tx, vars, fragmentList, newTraversal); }
From source file:org.eigenbase.rex.RexUtil.java
/** * Converts a collection of expressions into an AND. * If there are zero expressions, returns TRUE. * If there is one expression, returns just that expression. * Removes expressions that always evaluate to TRUE. * Returns null only if {@code nullOnEmpty} and expression is TRUE. *///from w w w .j a va 2 s. com public static RexNode composeConjunction(RexBuilder rexBuilder, Iterable<? extends RexNode> nodes, boolean nullOnEmpty) { ImmutableList<RexNode> list = flattenAnd(nodes); switch (list.size()) { case 0: return nullOnEmpty ? null : rexBuilder.makeLiteral(true); case 1: return list.get(0); default: return rexBuilder.makeCall(SqlStdOperatorTable.AND, list); } }