List of usage examples for com.google.common.collect Sets newHashSetWithExpectedSize
public static <E> HashSet<E> newHashSetWithExpectedSize(int expectedSize)
From source file:org.gradoop.flink.algorithms.fsm.transactional.tle.functions.SubgraphDecoder.java
/** * Turns the subgraph into a Gradoop graph transaction. * * @param subgraph subgraph//from www. j a v a 2 s. c om * @param canonicalLabel canonical label * @return graph transaction */ protected GraphTransaction createTransaction(Subgraph subgraph, String canonicalLabel) { // GRAPH HEAD Properties properties = new Properties(); properties.set(TFSMConstants.SUPPORT_KEY, subgraph.getCount()); properties.set(TFSMConstants.CANONICAL_LABEL_KEY, subgraph.getCanonicalLabel()); GraphHead epgmGraphHead = graphHeadFactory.createGraphHead(canonicalLabel, properties); GradoopIdSet graphIds = GradoopIdSet.fromExisting(epgmGraphHead.getId()); // VERTICES Map<Integer, String> vertices = subgraph.getEmbedding().getVertices(); Set<Vertex> epgmVertices = Sets.newHashSetWithExpectedSize(vertices.size()); Map<Integer, GradoopId> vertexIdMap = Maps.newHashMapWithExpectedSize(vertices.size()); for (Map.Entry<Integer, String> vertex : vertices.entrySet()) { Vertex epgmVertex = vertexFactory.createVertex(vertex.getValue(), graphIds); vertexIdMap.put(vertex.getKey(), epgmVertex.getId()); epgmVertices.add(epgmVertex); } // EDGES Collection<FSMEdge> edges = subgraph.getEmbedding().getEdges().values(); Set<Edge> epgmEdges = Sets.newHashSetWithExpectedSize(edges.size()); for (FSMEdge edge : edges) { epgmEdges.add(edgeFactory.createEdge(edge.getLabel(), vertexIdMap.get(edge.getSourceId()), vertexIdMap.get(edge.getTargetId()), graphIds)); } return new GraphTransaction(epgmGraphHead, epgmVertices, epgmEdges); }
From source file:org.jalphanode.jmx.MBeanAnnotationScanner.java
protected void buildAttributeMetadata(final Class<?> klass, final BeanInfo beanInfo, final MBeanMetadata.Builder builder) { final List<Field> fields = ReflectionUtils.getAnnotatedFields(klass, ManagedAttribute.class); final Map<String, Field> indexFields = Maps.newHashMapWithExpectedSize(fields.size()); for (Field field : fields) { indexFields.put(field.getName(), field); }//from w w w . j a v a2 s . c om PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); final Set<String> attributes = Sets.newHashSetWithExpectedSize(propertyDescriptors.length); for (PropertyDescriptor property : propertyDescriptors) { final Field annotatedField = indexFields.remove(property.getName()); final Method readMethod = property.getReadMethod(); final Method writeMethod = property.getWriteMethod(); ManagedAttribute annotation = getManagedAttribute(property.getName(), annotatedField, readMethod, writeMethod); if (annotation != null) { final String name = annotation.name().isEmpty() ? property.getName() : annotation.name(); if (!attributes.add(name)) { throw new MalformedMBeanException( MessageFormat.format("Attribute with name {0} already registered", name)); } ManagedAttributeMetadata.Builder attributeBuilder = new ManagedAttributeMetadata.Builder(name); if (!annotation.description().isEmpty()) { attributeBuilder.withDescription(annotation.description()); } if (readMethod != null) { attributeBuilder.withReadMethod(readMethod); } if (writeMethod != null) { attributeBuilder.withWriteMethod(writeMethod); } builder.putAttribute(attributeBuilder.build()); } } if (!indexFields.isEmpty()) { throw new MalformedMBeanException( MessageFormat.format("Found attribute(s) without getters/setters: {0}", indexFields.keySet())); } }
From source file:org.obm.sync.calendar.CalendarItemsParser.java
public EventChanges parseChanges(Document doc) { Element root = doc.getDocumentElement(); Date lastSync = DateHelper.asDate(root.getAttribute("lastSync")); Element removed = DOMUtils.getUniqueElement(root, "removed"); Element updated = DOMUtils.getUniqueElement(root, "updated"); NodeList rmed = removed.getElementsByTagName("event"); Set<DeletedEvent> removedIds = Sets.newHashSetWithExpectedSize(rmed.getLength() + 1); for (int i = 0; i < rmed.getLength(); i++) { Element e = (Element) rmed.item(i); removedIds.add(DeletedEvent.builder().eventObmId(Integer.valueOf(e.getAttribute("id"))) .eventExtId(e.getAttribute("extId")).build()); }//from ww w. j ava 2s . c o m NodeList upd = updated.getElementsByTagName("event"); List<Event> updatedEvents = new ArrayList<Event>(upd.getLength() + 1); for (int i = 0; i < upd.getLength(); i++) { Element e = (Element) upd.item(i); Event ev = parseEvent(e); updatedEvents.add(ev); } return EventChanges.builder().lastSync(lastSync).deletes(removedIds).updates(updatedEvents).build(); }
From source file:com.opengamma.integration.viewer.status.impl.SimpleViewStatusModel.java
@Override public Set<String> getSecurityTypes() { Set<String> result = Sets.newHashSetWithExpectedSize(_viewStatusResult.size()); for (ViewStatusKey key : _viewStatusResult.keySet()) { result.add(key.getSecurityType()); }/*from ww w . ja va 2 s .co m*/ return result; }
From source file:com.android.build.gradle.internal.dsl.NdkOptions.java
@NonNull public NdkOptions abiFilters(String... filters) { if (abiFilters == null) { abiFilters = Sets.newHashSetWithExpectedSize(2); }/*www. ja v a 2s.co m*/ Collections.addAll(abiFilters, filters); return this; }
From source file:com.opengamma.engine.function.exclusion.AbstractFunctionExclusionGroups.java
@Override public Collection<FunctionExclusionGroup> withExclusion(final Collection<FunctionExclusionGroup> existing, final FunctionExclusionGroup newGroup) { final Set<FunctionExclusionGroup> result = Sets.newHashSetWithExpectedSize(existing.size() + 1); result.addAll(existing);/* w ww. ja v a 2 s. c o m*/ result.add(newGroup); return result; }
From source file:com.android.build.gradle.internal.dsl.NdkConfigDsl.java
@NonNull public NdkConfigDsl abiFilters(String... filters) { if (abiFilters == null) { abiFilters = Sets.newHashSetWithExpectedSize(2); }/*from w w w .ja va 2s .c o m*/ Collections.addAll(abiFilters, filters); return this; }
From source file:org.sonatype.nexus.content.internal.VelocityContentRenderer.java
@Override public void renderCollection(final HttpServletRequest request, final HttpServletResponse response, final StorageCollectionItem coll, final Collection<StorageItem> children) throws IOException { final Set<String> uniqueNames = Sets.newHashSetWithExpectedSize(children.size()); final List<CollectionEntry> entries = Lists.newArrayListWithCapacity(children.size()); // use request URL (it does not contain any parameters) as the base URL of collection entries final String collUrl = BaseUrlHolder.get() + request.getServletPath() + request.getPathInfo(); for (StorageItem child : children) { if (child.isVirtual() || !child.getRepositoryItemUid().getBooleanAttributeValue(IsHiddenAttribute.class)) { if (!uniqueNames.contains(child.getName())) { final boolean isCollection = child instanceof StorageCollectionItem; final String name = isCollection ? child.getName() + "/" : child.getName(); final CollectionEntry entry = new CollectionEntry(name, isCollection, collUrl + name, new Date(child.getModified()), StorageFileItem.class.isAssignableFrom(child.getClass()) ? ((StorageFileItem) child).getLength() : -1,/*ww w . j av a2 s .com*/ ""); entries.add(entry); uniqueNames.add(child.getName()); } } } Collections.sort(entries, new CollectionEntryComparator()); final Map<String, Object> dataModel = createBaseModel(); dataModel.put("requestPath", coll.getPath()); dataModel.put("listItems", entries); templateRenderer .render(templateRenderer.template("/org/sonatype/nexus/content/internal/repositoryContentHtml.vm", getClass().getClassLoader()), dataModel, response); }
From source file:eu.interedition.text.rdbms.RelationalNameRepository.java
public synchronized Set<Name> get(Set<Name> names) { if (nameCache == null) { initCache();/*from w w w . j a va 2 s.c o m*/ } final Set<Name> requested = Sets.newHashSet(names); final Set<Name> found = Sets.newHashSetWithExpectedSize(requested.size()); for (Iterator<Name> it = requested.iterator(); it.hasNext();) { final Name name = it.next(); final Long id = nameCache.get(name); if (id != null) { found.add(new RelationalName(name, id)); it.remove(); } } if (requested.isEmpty()) { return found; } return tt.execute(new TransactionCallback<Set<Name>>() { @Override public Set<Name> doInTransaction(TransactionStatus status) { final List<Object> ps = Lists.newArrayList(); final StringBuilder sql = new StringBuilder("select ").append(selectNameFrom("n")) .append(" from text_qname n where "); for (Iterator<Name> it = requested.iterator(); it.hasNext();) { sql.append("("); final Name name = it.next(); sql.append("n.local_name = ? and "); ps.add(name.getLocalName()); final URI ns = name.getNamespace(); if (ns == null) { sql.append("n.namespace is null"); } else { sql.append("n.namespace = ?"); ps.add(ns.toString()); } sql.append(")").append(it.hasNext() ? " or " : ""); } for (RelationalName name : jt.query(sql.toString(), ROW_MAPPER, ps.toArray(new Object[ps.size()]))) { found.add(name); requested.remove(name); nameCache.put(name, name.getId()); } final List<RelationalName> created = Lists.newArrayListWithExpectedSize(requested.size()); final List<MapSqlParameterSource> nameBatch = Lists.newArrayListWithExpectedSize(requested.size()); for (Name name : requested) { final long id = nameIdIncrementer.nextLongValue(); final String localName = name.getLocalName(); final URI ns = name.getNamespace(); nameBatch.add(new MapSqlParameterSource().addValue("id", id).addValue("local_name", localName) .addValue("namespace", ns == null ? null : ns.toString())); created.add(new RelationalName(name, id)); } nameInsert.executeBatch(nameBatch.toArray(new MapSqlParameterSource[nameBatch.size()])); for (RelationalName n : created) { found.add(n); nameCache.put(n, n.getId()); } return found; } }); }
From source file:org.gradle.internal.locking.DependencyLockingArtifactVisitor.java
@Override public void startArtifacts(RootGraphNode root) { RootConfigurationMetadata metadata = root.getMetadata(); dependencyLockingState = metadata.getDependencyLockingState(); if (dependencyLockingState.mustValidateLockState()) { Set<ModuleComponentIdentifier> lockedModules = dependencyLockingState.getLockedDependencies(); modulesToBeLocked = Maps.newHashMapWithExpectedSize(lockedModules.size()); for (ModuleComponentIdentifier lockedModule : lockedModules) { modulesToBeLocked.put(lockedModule.getModuleIdentifier(), lockedModule); }// w w w .ja v a 2s . co m allResolvedModules = Sets.newHashSetWithExpectedSize(this.modulesToBeLocked.size()); extraModules = Sets.newHashSet(); } else { modulesToBeLocked = Collections.emptyMap(); allResolvedModules = Sets.newHashSet(); } }