List of usage examples for com.google.common.collect ImmutableList get
E get(int index);
From source file:org.guldenj.crypto.DeterministicHierarchy.java
/** * Returns a key for the given path, optionally creating it. * * @param path the path to the key//w ww.j a v a 2s.co m * @param relativePath whether the path is relative to the root path * @param create whether the key corresponding to path should be created (with any necessary ancestors) if it doesn't exist already * @return next newly created key using the child derivation function * @throws IllegalArgumentException if create is false and the path was not found. */ public DeterministicKey get(List<ChildNumber> path, boolean relativePath, boolean create) { ImmutableList<ChildNumber> absolutePath = relativePath ? ImmutableList.<ChildNumber>builder().addAll(rootPath).addAll(path).build() : ImmutableList.copyOf(path); if (!keys.containsKey(absolutePath)) { if (!create) throw new IllegalArgumentException(String.format(Locale.US, "No key found for %s path %s.", relativePath ? "relative" : "absolute", HDUtils.formatPath(path))); checkArgument(absolutePath.size() > 0, "Can't derive the master key: nothing to derive from."); DeterministicKey parent = get(absolutePath.subList(0, absolutePath.size() - 1), false, true); putKey(HDKeyDerivation.deriveChildKey(parent, absolutePath.get(absolutePath.size() - 1))); } return keys.get(absolutePath); }
From source file:com.google.devtools.build.lib.syntax.FunctionDefStatement.java
@Override void validate(final ValidationEnvironment env) throws EvalException { ValidationEnvironment localEnv = new ValidationEnvironment(env); FunctionSignature sig = signature.getSignature(); FunctionSignature.Shape shape = sig.getShape(); ImmutableList<String> names = sig.getNames(); List<Expression> defaultExpressions = signature.getDefaultValues(); int positionals = shape.getPositionals(); int mandatoryPositionals = shape.getMandatoryPositionals(); int namedOnly = shape.getNamedOnly(); int mandatoryNamedOnly = shape.getMandatoryNamedOnly(); boolean starArg = shape.hasStarArg(); boolean kwArg = shape.hasKwArg(); int named = positionals + namedOnly; int args = named + (starArg ? 1 : 0) + (kwArg ? 1 : 0); int startOptionals = mandatoryPositionals; int endOptionals = named - mandatoryNamedOnly; int j = 0; // index for the defaultExpressions for (int i = 0; i < args; i++) { String name = names.get(i); if (startOptionals <= i && i < endOptionals) { defaultExpressions.get(j++).validate(env); }//w w w. j ava 2 s.co m localEnv.declare(name, getLocation()); } for (Statement stmts : statements) { stmts.validate(localEnv); } }
From source file:org.kiji.schema.KijiURI.java
/** * Formats the full KijiURI up to the column. * * @param preserveOrdering Whether to preserve ordering. * @return Representation of this KijiURI up to the table. *//* www. jav a 2 s .c om*/ private String toStringCol(boolean preserveOrdering) { String columnField; ImmutableList<KijiColumnName> columns = preserveOrdering ? mColumnNames : mColumnNamesNormalized; if (columns.isEmpty()) { columnField = UNSET_URI_STRING; } else { ImmutableList.Builder<String> builder = ImmutableList.builder(); for (KijiColumnName column : columns) { builder.add(column.getName()); } ImmutableList<String> strColumns = builder.build(); if (strColumns.size() == 1) { columnField = strColumns.get(0); } else { columnField = Joiner.on(",").join(strColumns); } } try { // SCHEMA-6. URI Encode column names using RFC-2396. final URI columnsEncoded = new URI(KIJI_SCHEME, columnField, null); return String.format("%s%s/", toStringTable(preserveOrdering), columnsEncoded.getRawSchemeSpecificPart()); } catch (URISyntaxException e) { throw new KijiURIException(e.getMessage()); } }
From source file:org.elasticsearch.client.transport.TransportClientNodesService.java
public <T> T execute(NodeCallback<T> callback) throws ElasticsearchException { ImmutableList<DiscoveryNode> nodes = this.nodes; if (nodes.isEmpty()) { throw new NoNodeAvailableException(); }/*from w w w . j av a 2 s.c o m*/ int index = randomNodeGenerator.incrementAndGet(); if (index < 0) { index = 0; randomNodeGenerator.set(0); } for (int i = 0; i < nodes.size(); i++) { DiscoveryNode node = nodes.get((index + i) % nodes.size()); try { return callback.doWithNode(node); } catch (ElasticsearchException e) { if (!(e.unwrapCause() instanceof ConnectTransportException)) { throw e; } } } throw new NoNodeAvailableException(); }
From source file:com.google.errorprone.refaster.BlockTemplate.java
@Override public Fix replace(BlockTemplateMatch match) { checkNotNull(match);/* ww w . j av a 2 s. c o m*/ SuggestedFix.Builder fix = SuggestedFix.builder(); Inliner inliner = match.createInliner(); Context context = inliner.getContext(); if (annotations().containsKey(UseImportPolicy.class)) { ImportPolicy.bind(context, annotations().getInstance(UseImportPolicy.class).value()); } else { ImportPolicy.bind(context, ImportPolicy.IMPORT_TOP_LEVEL); } ImmutableList<JCStatement> targetStatements = match.getStatements(); try { ImmutableList.Builder<JCStatement> inlinedStatementsBuilder = ImmutableList.builder(); for (UStatement statement : templateStatements()) { inlinedStatementsBuilder.addAll(statement.inlineStatements(inliner)); } ImmutableList<JCStatement> inlinedStatements = inlinedStatementsBuilder.build(); int nInlined = inlinedStatements.size(); int nTargets = targetStatements.size(); if (nInlined <= nTargets) { for (int i = 0; i < nInlined; i++) { fix.replace(targetStatements.get(i), printStatement(context, inlinedStatements.get(i))); } for (int i = nInlined; i < nTargets; i++) { fix.delete(targetStatements.get(i)); } } else { for (int i = 0; i < nTargets - 1; i++) { fix.replace(targetStatements.get(i), printStatement(context, inlinedStatements.get(i))); } int last = nTargets - 1; ImmutableList<JCStatement> remainingInlined = inlinedStatements.subList(last, nInlined); fix.replace(targetStatements.get(last), CharMatcher.whitespace().trimTrailingFrom(printStatements(context, remainingInlined))); } } catch (CouldNotResolveImportException e) { logger.log(SEVERE, "Failure to resolve import in replacement", e); } return addImports(inliner, fix); }
From source file:org.kiji.schema.CassandraKijiURI.java
/** * Formats the full CassandraKijiURI up to the authority, preserving order. * * @param preserveOrdering Whether to preserve ordering. * @return Representation of this KijiURI up to the authority. *//*from w ww. j av a2 s . c o m*/ String toStringAuthority(boolean preserveOrdering) { String zkQuorum; ImmutableList<String> zookeeperQuorum = preserveOrdering ? getZookeeperQuorumOrdered() : getZookeeperQuorum(); if (null == zookeeperQuorum) { zkQuorum = UNSET_URI_STRING; } else { if (zookeeperQuorum.size() == 1) { zkQuorum = zookeeperQuorum.get(0); } else { zkQuorum = String.format("(%s)", Joiner.on(",").join(zookeeperQuorum)); } } String cNodes; ImmutableList<String> cassandraNodes = preserveOrdering ? getCassandraNodesOrdered() : getCassandraNodes(); if (null == cassandraNodes) { cNodes = UNSET_URI_STRING; } else { if (cassandraNodes.size() == 1) { cNodes = cassandraNodes.get(0); } else { cNodes = String.format("(%s)", Joiner.on(",").join(cassandraNodes)); } } return String.format("%s://%s:%s/%s/%s/", KIJI_SCHEME, zkQuorum, getZookeeperClientPort(), cNodes, getCassandraClientPort()); }
From source file:com.google.javascript.jscomp.TypeTransformation.java
private JSType evalRawTypeOf(Node ttlAst, NameResolver nameResolver) { ImmutableList<Node> params = getCallParams(ttlAst); JSType type = evalInternal(params.get(0), nameResolver); if (!type.isTemplatizedType()) { reportWarning(ttlAst, TEMPTYPE_INVALID, "rawTypeOf", type.toString()); return getUnknownType(); }//from w w w . j a va2s.com return ((TemplatizedType) type).getReferencedType(); }
From source file:com.moz.fiji.schema.FijiURI.java
/** * Formats the full FijiURI up to the column. * * @param preserveOrdering Whether to preserve ordering. * @return Representation of this FijiURI up to the table. *//* w ww. j a v a 2 s . co m*/ private String toStringCol(boolean preserveOrdering) { String columnField; ImmutableList<FijiColumnName> columns = preserveOrdering ? mColumnNames : mColumnNamesNormalized; if (columns.isEmpty()) { columnField = UNSET_URI_STRING; } else { ImmutableList.Builder<String> builder = ImmutableList.builder(); for (FijiColumnName column : columns) { builder.add(column.getName()); } ImmutableList<String> strColumns = builder.build(); if (strColumns.size() == 1) { columnField = strColumns.get(0); } else { columnField = Joiner.on(",").join(strColumns); } } try { // SCHEMA-6. URI Encode column names using RFC-2396. final URI columnsEncoded = new URI(FIJI_SCHEME, columnField, null); return String.format("%s%s/", toStringTable(preserveOrdering), columnsEncoded.getRawSchemeSpecificPart()); } catch (URISyntaxException e) { throw new FijiURIException(e.getMessage()); } }
From source file:com.google.errorprone.bugpatterns.WildcardImport.java
@Override public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState state) { ImmutableList<ImportTree> wildcardImports = getWildcardImports(tree.getImports()); if (wildcardImports.isEmpty()) { return NO_MATCH; }/* ww w . java2s .c om*/ // Find all of the types that need to be imported. Set<TypeToImport> typesToImport = ImportCollector.collect((JCCompilationUnit) tree); // Group the imported types by the on-demand import they replace. Multimap<ImportTree, TypeToImport> toFix = groupImports(wildcardImports, typesToImport); Fix fix = createFix(wildcardImports, toFix, state); if (fix.isEmpty()) { return NO_MATCH; } return describeMatch(wildcardImports.get(0), fix); }
From source file:com.google.javascript.jscomp.TypeTransformation.java
private JSType evalTemplateTypeOf(Node ttlAst, NameResolver nameResolver) { ImmutableList<Node> params = getCallParams(ttlAst); JSType type = evalInternal(params.get(0), nameResolver); if (!type.isTemplatizedType()) { reportWarning(ttlAst, TEMPTYPE_INVALID, "templateTypeOf", type.toString()); return getUnknownType(); }/*from www . j av a 2 s.c om*/ int index = (int) params.get(1).getDouble(); ImmutableList<JSType> templateTypes = ((TemplatizedType) type).getTemplateTypes(); if (index > templateTypes.size()) { reportWarning(ttlAst, INDEX_OUTOFBOUNDS, Integer.toString(index), Integer.toString(templateTypes.size())); return getUnknownType(); } return templateTypes.get(index); }