List of usage examples for com.google.common.collect ArrayListMultimap trimToSize
public void trimToSize()
From source file:com.foundationdb.server.types.service.ResolvablesRegistry.java
private static <R extends TOverload, V extends TValidatedOverload> ListMultimap<String, ScalarsGroup<V>> createScalars( InstanceFinder finder, TCastResolver castResolver, Class<R> plainClass, Function<R, V> validator) { Multimap<String, V> overloadsByName = ArrayListMultimap.create(); int errors = 0; for (R scalar : finder.find(plainClass)) { try {//from w ww . j av a2 s. com V validated = validator.apply(scalar); String[] names = validated.registeredNames(); for (int i = 0; i < names.length; ++i) names[i] = names[i].toLowerCase(); for (String name : names) overloadsByName.put(name, validated); } catch (RuntimeException e) { rejectTOverload(scalar, e); ++errors; } catch (AssertionError e) { rejectTOverload(scalar, e); ++errors; } } if (errors > 0) { StringBuilder sb = new StringBuilder("Found ").append(errors).append(" error"); if (errors != 1) sb.append('s'); sb.append(" while collecting scalar functions. Check logs for details."); throw new AkibanInternalException(sb.toString()); } ArrayListMultimap<String, ScalarsGroup<V>> results = ArrayListMultimap.create(); for (Map.Entry<String, Collection<V>> entry : overloadsByName.asMap().entrySet()) { String overloadName = entry.getKey(); Collection<V> allOverloads = entry.getValue(); for (Collection<V> priorityGroup : scalarsByPriority(allOverloads)) { ScalarsGroup<V> scalarsGroup = new ScalarsGroupImpl<>(priorityGroup, castResolver); results.put(overloadName, scalarsGroup); } } results.trimToSize(); return Multimaps.unmodifiableListMultimap(results); }
From source file:com.trebogeer.jcql.JCQLMain.java
/** * main routine generating java code/*from www.j a va 2s . c om*/ * * @throws IOException thrown if unable to write generated code to files */ public void exec() throws IOException { String keyspace = cfg.keysapce; Cluster.Builder b = Cluster.builder().addContactPoint(cfg.dbHost).withPort(Integer.valueOf(cfg.dbPort)); if (cfg.userName != null && !"".equals(cfg.userName.trim()) && cfg.password != null && !"".equals(cfg.password.trim())) { b = b.withAuthProvider(new PlainTextAuthProvider(cfg.userName, cfg.password)); } else { logger.info("No auth will be used. Either credentials are not provided or are incorrect."); } try (Cluster c = b.build(); Session s = c.connect(keyspace)) { Multimap<String, Pair<String, DataType>> beans = HashMultimap.create(); Multimap<String, Pair<String, ColumnMetadata>> tables = HashMultimap.create(); ArrayListMultimap<String, String> partitionKeys = ArrayListMultimap.create(); Collection<UserType> types = s.getCluster().getMetadata().getKeyspace(keyspace).getUserTypes(); for (UserType t : types) { String name = t.getTypeName(); Set<Pair<String, DataType>> fields = new HashSet<Pair<String, DataType>>(); for (String field : t.getFieldNames()) { DataType dt = t.getFieldType(field); fields.add(Pair.with(field, dt)); } beans.putAll(name, fields); } Collection<TableMetadata> tbls = s.getCluster().getMetadata().getKeyspace(keyspace).getTables(); for (TableMetadata t : tbls) { String name = t.getName(); for (ColumnMetadata clmdt : t.getPartitionKey()) { partitionKeys.put(name, clmdt.getName()); } partitionKeys.trimToSize(); Set<Pair<String, ColumnMetadata>> fields = new HashSet<>(); for (ColumnMetadata field : t.getColumns()) { fields.add(Pair.with(field.getName(), field)); } tables.putAll(name, fields); } generateModelCode(beans, tables, partitionKeys); generateAccessCode(s); if ("y".equalsIgnoreCase(cfg.toString)) { toStringMethods(); } if ("y".equalsIgnoreCase(cfg.printInfo)) { info(); } if ("y".equalsIgnoreCase(cfg.debug)) { model.build(new SingleStreamCodeWriter(System.out)); } else { File source = new File(cfg.generatedSourceDir); if (source.exists() || source.mkdirs()) { model.build(new File(cfg.generatedSourceDir)); } } } }