List of usage examples for com.google.common.collect Sets newHashSetWithExpectedSize
public static <E> HashSet<E> newHashSetWithExpectedSize(int expectedSize)
From source file:org.n52.sos.ogc.sos.SosOffering.java
/** * Creates a set of {@literal SosOffering}s from a map containing * identifiers as keys and names as values. * // ww w . jav a2 s .c o m * @param map * the map (may be {@literal null}) * * @return the set (never {@literal null}) */ public static Set<SosOffering> fromMap(Map<String, String> map) { if (map == null) { return Collections.emptySet(); } final Set<SosOffering> set = Sets.newHashSetWithExpectedSize(map.size()); for (Entry<String, String> e : map.entrySet()) { set.add(new SosOffering(e.getKey(), e.getValue())); } return set; }
From source file:com.google.cloud.logging.spi.DefaultLoggingRpc.java
private static <V> Future<V> translate(ListenableFuture<V> from, final boolean idempotent, int... returnNullOn) { final Set<Integer> returnNullOnSet = Sets.newHashSetWithExpectedSize(returnNullOn.length); for (int value : returnNullOn) { returnNullOnSet.add(value);/*www. j a v a 2 s .c o m*/ } return Futures.catching(from, ApiException.class, new Function<ApiException, V>() { @Override public V apply(ApiException exception) { if (returnNullOnSet.contains(exception.getStatusCode().value())) { return null; } throw new LoggingException(exception, idempotent); } }); }
From source file:org.envirocar.server.mongo.dao.MongoUserDao.java
public Set<Key<MongoUser>> getBidirectionalFriendRefs(User user) { final Set<Key<MongoUser>> friendRefs = getFriendRefs(user); final Set<String> ids = Sets.newHashSetWithExpectedSize(friendRefs.size()); for (Key<MongoUser> key : friendRefs) { ids.add((String) key.getId()); }/*from w ww. j ava 2 s . co m*/ final Iterable<Key<MongoUser>> filtered = q().field(MongoUser.NAME).in(ids).field(MongoUser.FRIENDS) .hasThisElement(key(user)).fetchKeys(); return Sets.newHashSet(filtered); }
From source file:com.google.cloud.pubsub.deprecated.spi.DefaultPubSubRpc.java
private static <V> ApiFuture<V> translate(ApiFuture<V> from, final boolean idempotent, int... returnNullOn) { final Set<Integer> returnNullOnSet = Sets.newHashSetWithExpectedSize(returnNullOn.length); for (int value : returnNullOn) { returnNullOnSet.add(value);/*w ww. j av a 2 s .com*/ } return ApiFutures.<V, ApiException>catching(from, ApiException.class, new Function<ApiException, V>() { @Override public V apply(ApiException exception) { if (returnNullOnSet.contains(exception.getStatusCode().value())) { return null; } throw new PubSubException(exception, idempotent); } }); }
From source file:com.android.tools.idea.gradle.project.GradleModuleImporter.java
@NotNull private static Set<ModuleToImport> buildModulesSet(@NotNull Map<String, VirtualFile> modules, @NotNull Function<VirtualFile, Iterable<String>> parser) { Set<ModuleToImport> modulesSet = Sets.newHashSetWithExpectedSize(modules.size()); for (Map.Entry<String, VirtualFile> entry : modules.entrySet()) { VirtualFile location = entry.getValue(); Supplier<Iterable<String>> dependencyComputer; if (location != null) { dependencyComputer = Suppliers.compose(parser, Suppliers.ofInstance(location)); } else {/* ww w.ja va2s. c o m*/ dependencyComputer = Suppliers.<Iterable<String>>ofInstance(ImmutableSet.<String>of()); } modulesSet.add(new ModuleToImport(entry.getKey(), location, dependencyComputer)); } return modulesSet; }
From source file:org.sosy_lab.cpachecker.util.ci.translators.ApronRequirementsTranslator.java
private Set<String> getVarsInConstraint(final Tcons0 constraint, final List<String> varNames) { Set<String> vars = Sets.newHashSetWithExpectedSize(constraint.getSize()); Deque<Texpr0Node> stack = new ArrayDeque<>(); stack.push(constraint.getExpression().toTexpr0Node()); Texpr0Node current;//from ww w . j a v a2 s . c o m while (!stack.isEmpty()) { current = stack.pop(); if (current instanceof Texpr0BinNode) { stack.push(((Texpr0BinNode) current).getLeftArgument()); stack.push(((Texpr0BinNode) current).getRightArgument()); } else if (current instanceof Texpr0UnNode) { stack.push(((Texpr0UnNode) current).getArgument()); } else if (current instanceof Texpr0DimNode) { vars.add(varNames.get(((Texpr0DimNode) current).dim)); } } return vars; }
From source file:com.torodb.torod.db.backends.executor.jobs.InsertCallable.java
private InsertResponse transactionalInsert() throws ImplementationDbException, RetryTransactionException { DbConnection connection = getConnection(); List<WriteError> errors = Lists.newLinkedList(); try {/*from w w w.java 2s.c om*/ /* * First we need to store the root documents */ connection.insertRootDocuments(collection, docs); /* * Then we have to store the subdocuments. It is more efficient to do one insert for each table, so inserts * are done by subdocument type. * To do that, we could create a map like Map<SubDocType, List<SubDocument>> and then iterate over the keys, * but we need to duplicate memory and the documents to insert may be very big. So we decided to do it in a * functional way. First we get all types and then we use an iterator that, for each type 't' and document 'd' * does d.getSubDocuments().row(k).values().iterator and finally merges the iterators grouped by type. */ Set<SubDocType> types = Sets.newHashSetWithExpectedSize(10 * docs.size()); for (SplitDocument splitDocument : docs) { types.addAll(splitDocument.getSubDocuments().rowKeySet()); } /* * The following code that uses guava functions is the same as the following jdk8 code: * for (SubDocType type : types) { * java.util.function.Function<SplitDocument, Stream<SubDocument>> f = (sd) -> sd.getSubDocuments().row(type).values().stream(); * * Stream<SubDocument> flatMap = docs.stream().map(f).flatMap((stream) -> stream); * * connection.insertSubdocuments(collection, type, flatMap.iterator()); * * } */ for (SubDocType type : types) { Function<SplitDocument, Iterable<SubDocument>> extractor = new SubDocumentExtractorFunction(type); connection.insertSubdocuments(collection, type, Iterables.concat(Iterables.transform(docs, extractor))); } return createResponse(docs.size(), errors); } catch (UserDbException ex) { appendError(errors, ex, 0); connection.rollback(); } return createResponse(0, errors); }
From source file:org.graylog2.users.UserServiceImpl.java
@Override public Collection<User> loadAllForRole(Role role) { final String roleId = role.getId(); final DBObject query = BasicDBObjectBuilder.start(UserImpl.ROLES, new ObjectId(roleId)).get(); final List<DBObject> result = query(UserImpl.class, query); if (result == null || result.isEmpty()) { return Collections.emptySet(); }/*from ww w . ja v a2 s . c om*/ final Set<User> users = Sets.newHashSetWithExpectedSize(result.size()); for (DBObject dbObject : result) { //noinspection unchecked users.add(userFactory.create((ObjectId) dbObject.get("_id"), dbObject.toMap())); } return users; }
From source file:org.graylog.plugins.usagestatistics.collectors.NodeCollector.java
private Set<PluginInfo> buildPluginInfo(Set<PluginMetaData> plugins) { final Set<PluginInfo> pluginInfos = Sets.newHashSetWithExpectedSize(plugins.size()); for (PluginMetaData pluginMetaData : plugins) { pluginInfos.add(PluginInfo.create(pluginMetaData.getUniqueId(), pluginMetaData.getName(), pluginMetaData.getVersion().toString())); }//from w w w. ja v a 2s . c om return pluginInfos; }
From source file:voldemort.routing.ConsistentRoutingStrategy.java
@Override public Set<Node> getNodes() { Set<Node> s = Sets.newHashSetWithExpectedSize(partitionToNode.length); for (Node n : this.partitionToNode) s.add(n);/* www . jav a2 s . c o m*/ return s; }