List of usage examples for com.google.common.collect ImmutableList get
E get(int index);
From source file:com.google.jimfs.FileTree.java
private static boolean isEmpty(ImmutableList<Name> names) { // the empty path (created by FileSystem.getPath("")), has no root and a single name, "" return names.isEmpty() || names.size() == 1 && names.get(0).toString().isEmpty(); }
From source file:com.github.rinde.opt.localsearch.Schedule.java
static <C, T> Schedule<C, T> create(C context, ImmutableList<ImmutableList<T>> routes, IntList startIndices, RouteEvaluator<C, T> routeEvaluator) { final DoubleList costs = new DoubleArrayList(routes.size()); double sumCost = 0; for (int i = 0; i < routes.size(); i++) { final double cost = routeEvaluator.computeCost(context, i, routes.get(i)); costs.add(cost);//from w w w.ja va 2 s . c om sumCost += cost; } return new Schedule<C, T>(context, routes, IntLists.unmodifiable(new IntArrayList(startIndices)), DoubleLists.unmodifiable(costs), sumCost, routeEvaluator); }
From source file:org.asoem.greyfish.utils.collect.BitSets.java
/** * Parses a string of '0' and '1' characters interpreted in big-endian format and transforms it into a BitSet. * <p>Whitespaces are ignored.</p> * * @param s the input string//from w ww . j a v a 2s . c o m * @return A {@code BitSet} whose bits at indices are set to {@code true}, when the reversed input string has a '1' * character at the same index. */ public static BitSet parse(final String s) { checkNotNull(s); checkArgument(s.matches("^[01]*$"), "Invalid characters (other than '0' or '1') in string: %s", s); final ImmutableList<Character> characters = Lists.charactersOf(s); final BitSet bitSet = new BitSet(characters.size()); for (int i = 0, j = characters.size() - 1; i < characters.size() && j >= 0; i++, j--) { final Character character = characters.get(j); switch (character) { case '1': bitSet.set(i); break; case '0': break; default: if (!Character.isWhitespace(character)) { throw new IllegalArgumentException("Invalid character at position " + j); } } } return bitSet; }
From source file:eu.eubrazilcc.lvl.core.conf.ConfigurationFinder.java
private static String filesToString(final ImmutableList<File> files) { String str = ""; if (files != null && files.size() > 0) { int i = 0; for (; i < (files.size() - 1); i++) { try { str += files.get(i).getCanonicalPath() + ", "; } catch (Exception ignore) { }/* w w w .j a v a2 s . c o m*/ } try { str += files.get(i).getCanonicalPath(); } catch (Exception ignore) { } } return str; }
From source file:com.google.caliper.worker.instrument.WorkerInstrumentModule.java
private static Method findBenchmarkMethod(Class<?> benchmark, String methodName, ImmutableList<String> methodParameterClasses) { Class<?>[] params = new Class<?>[methodParameterClasses.size()]; for (int i = 0; i < methodParameterClasses.size(); i++) { try {/* w w w . ja v a 2 s. com*/ String typeName = methodParameterClasses.get(i); Class<?> primitiveType = PRIMITIVE_TYPES.get(typeName); if (primitiveType != null) { params[i] = primitiveType; } else { params[i] = Util.loadClass(typeName); } } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } try { return benchmark.getDeclaredMethod(methodName, params); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } catch (SecurityException e) { // assertion error? throw new RuntimeException(e); } }
From source file:com.facebook.buck.core.build.engine.manifest.Manifest.java
/** Hash the files pointed to by the source paths. */ @VisibleForTesting//from w w w . ja v a 2s . c om static HashCode hashSourcePathGroup(FileHashCache fileHashCache, SourcePathResolver resolver, ImmutableList<SourcePath> paths) throws IOException { if (paths.size() == 1) { return hashSourcePath(paths.get(0), fileHashCache, resolver); } Hasher hasher = Hashing.md5().newHasher(); for (SourcePath path : paths) { hasher.putBytes(hashSourcePath(path, fileHashCache, resolver).asBytes()); } return hasher.hash(); }
From source file:com.palantir.atlasdb.keyvalue.cassandra.CassandraVerifier.java
protected static void sanityCheckRingConsistency(Set<InetSocketAddress> currentAddrs, String keyspace, boolean isSsl, boolean safetyDisabled, int socketTimeoutMillis, int socketQueryTimeoutMillis) { Multimap<Set<TokenRange>, InetSocketAddress> tokenRangesToHost = HashMultimap.create(); for (InetSocketAddress addr : currentAddrs) { Cassandra.Client client = null;// w w w . j a va 2 s .c om try { client = CassandraClientFactory.getClientInternal(addr, isSsl, socketTimeoutMillis, socketQueryTimeoutMillis); try { client.describe_keyspace(keyspace); } catch (NotFoundException e) { log.info( "Tried to check ring consistency for node {} before keyspace was fully setup; aborting check for now.", addr, e); return; } tokenRangesToHost.put(ImmutableSet.copyOf(client.describe_ring(keyspace)), addr); } catch (Exception e) { log.warn("failed to get ring info from host: {}", addr, e); } finally { if (client != null) { client.getOutputProtocol().getTransport().close(); } } } if (tokenRangesToHost.isEmpty()) { log.error( "Failed to get ring info for entire Cassandra cluster ({}); ring could not be checked for consistency.", keyspace); return; } if (tokenRangesToHost.keySet().size() == 1) { return; } RuntimeException e = new IllegalStateException( "Hosts have differing ring descriptions. This can lead to inconsistent reads and lost data. "); log.error("QA-86204 " + e.getMessage() + tokenRangesToHost, e); if (tokenRangesToHost.size() > 2) { for (Entry<Set<TokenRange>, Collection<InetSocketAddress>> entry : tokenRangesToHost.asMap() .entrySet()) { if (entry.getValue().size() == 1) { log.error("Host: " + entry.getValue().iterator().next() + " disagrees with the other nodes about the ring state."); } } } if (tokenRangesToHost.keySet().size() == 2) { ImmutableList<Set<TokenRange>> sets = ImmutableList.copyOf(tokenRangesToHost.keySet()); Set<TokenRange> set1 = sets.get(0); Set<TokenRange> set2 = sets.get(1); log.error("Hosts are split. group1: " + tokenRangesToHost.get(set1) + " group2: " + tokenRangesToHost.get(set2)); } logErrorOrThrow(e.getMessage(), safetyDisabled); }
From source file:org.apache.kylin.query.util.ConvertToComputedColumn.java
private static String getTableAlias(SqlNode node) { if (node instanceof SqlCall) { SqlCall call = (SqlCall) node;// w w w. j av a2 s . co m return getTableAlias(call.getOperandList()); } if (node instanceof SqlIdentifier) { StringBuilder alias = new StringBuilder(""); ImmutableList<String> names = ((SqlIdentifier) node).names; if (names.size() >= 2) { for (int i = 0; i < names.size() - 1; i++) { alias.append(names.get(i)).append("."); } } return alias.toString(); } if (node instanceof SqlNodeList) { return ""; } if (node instanceof SqlLiteral) { return ""; } return ""; }
From source file:com.facebook.presto.metadata.FunctionListBuilder.java
private static List<Class<?>> getParameterTypes(Class<?>... types) { ImmutableList<Class<?>> parameterTypes = ImmutableList.copyOf(types); if (!parameterTypes.isEmpty() && parameterTypes.get(0) == ConnectorSession.class) { parameterTypes = parameterTypes.subList(1, parameterTypes.size()); }/*from w w w. j a v a2 s. co m*/ return parameterTypes; }
From source file:com.google.api.codegen.discovery.DefaultString.java
/** Returns a default string from `pattern`, or null if the pattern is not supported. */ @VisibleForTesting//from w w w . j a v a 2s . c om static String forPattern(String pattern, String placeholderFormat, boolean placeholderUpperCase) { // We only care about patterns that have alternating literal and wildcard like // ^foo/[^/]*/bar/[^/]*$ // Ignore if what we get looks nothing like this. if (pattern == null || !pattern.startsWith("^") || !pattern.endsWith("$")) { return null; } pattern = pattern.substring(1, pattern.length() - 1); ImmutableList<Elem> elems = parse(pattern); if (!validElems(elems)) { return null; } StringBuilder ret = new StringBuilder(); for (int i = 0; i < elems.size(); i += 2) { String literal = elems.get(i).getLiteral(); String placeholder = Inflector.singularize(literal); if (placeholderUpperCase) { placeholder = placeholder.toUpperCase(); } ret.append('/').append(literal).append("/").append(String.format(placeholderFormat, placeholder)); } return ret.substring(1); }