List of usage examples for com.google.common.collect Sets newHashSetWithExpectedSize
public static <E> HashSet<E> newHashSetWithExpectedSize(int expectedSize)
From source file:org.onosproject.net.topology.AbstractPathService.java
private Set<DisjointPath> edgeToEdgePathsDisjoint(EdgeLink srcLink, EdgeLink dstLink) { Set<DisjointPath> endToEndPaths = Sets.newHashSetWithExpectedSize(1); endToEndPaths.add(edgeToEdgePathD(srcLink, dstLink, null)); return endToEndPaths; }
From source file:org.gradoop.util.AsciiGraphLoader.java
/** * Returns GraphHeads by their given variables. * * @param variables variables used in GDL script * @return graphHeads that are assigned to the given variables *//*w w w .jav a2s . c om*/ public Collection<G> getGraphHeadsByVariables(String... variables) { Collection<G> result = Sets.newHashSetWithExpectedSize(variables.length); for (String variable : variables) { G graphHead = getGraphHeadByVariable(variable); if (graphHead != null) { result.add(graphHead); } } return result; }
From source file:org.apache.cassandra.io.sstable.SSTable.java
/** * Reads the list of components from the TOC component. * @return set of components found in the TOC *///from w ww . j a va2s .c o m protected static Set<Component> readTOC(Descriptor descriptor) throws IOException { File tocFile = new File(descriptor.filenameFor(Component.TOC)); List<String> componentNames = Files.readLines(tocFile, Charset.defaultCharset()); Set<Component> components = Sets.newHashSetWithExpectedSize(componentNames.size()); for (String componentName : componentNames) { Component component = new Component(Component.Type.fromRepresentation(componentName), componentName); if (!new File(descriptor.filenameFor(component)).exists()) logger.error("Missing component: {}", descriptor.filenameFor(component)); else components.add(component); } return components; }
From source file:org.graylog.plugins.pipelineprocessor.rest.PipelineConnectionsResource.java
@ApiOperation("Get all pipeline connections") @GET//from w w w . j a v a2 s .co m @RequiresPermissions(PipelineRestPermissions.PIPELINE_CONNECTION_READ) public Set<PipelineConnections> getAll() throws NotFoundException { final Set<PipelineConnections> pipelineConnections = connectionsService.loadAll(); final Set<PipelineConnections> filteredConnections = Sets .newHashSetWithExpectedSize(pipelineConnections.size()); for (PipelineConnections pc : pipelineConnections) { // only include the streams the user can see if (isPermitted(RestPermissions.STREAMS_READ, pc.streamId())) { // filter out all pipelines the user does not have enough permissions to see filteredConnections.add(PipelineConnections.create(pc.id(), pc.streamId(), pc.pipelineIds().stream() .filter(id -> isPermitted(PipelineRestPermissions.PIPELINE_READ, id)) .collect(Collectors.toSet()))); } } return filteredConnections; }
From source file:org.onosproject.net.optical.intent.impl.compiler.OpticalOduIntentCompiler.java
/** * Find available TributarySlots across path. * * @param intent/*ww w . j a v a 2 s . c o m*/ * @param path path in OTU topology * @return Map of Linkey and Set of available TributarySlots on its ports */ private Map<LinkKey, Set<TributarySlot>> findAvailableTributarySlots(OpticalOduIntent intent, Path path) { Set<LinkKey> linkRequest = Sets.newHashSetWithExpectedSize(path.links().size()); for (int i = 0; i < path.links().size(); i++) { LinkKey link = linkKey(path.links().get(i)); linkRequest.add(link); } return findTributarySlots(intent, linkRequest); }
From source file:org.onosproject.net.topology.AbstractPathService.java
private Set<DisjointPath> edgeToEdgePathsDisjoint(EdgeLink srcLink, EdgeLink dstLink, Set<DisjointPath> paths) { Set<DisjointPath> endToEndPaths = Sets.newHashSetWithExpectedSize(paths.size()); for (DisjointPath path : paths) { endToEndPaths.add(edgeToEdgePathD(srcLink, dstLink, path)); }/*www.j a v a 2 s. c o m*/ return endToEndPaths; }
From source file:com.opengamma.financial.currency.CurrencyMatrixLookupFunction.java
@Override public Set<ValueSpecification> getResults(final FunctionCompilationContext context, final ComputationTarget target, final Map<ValueSpecification, ValueRequirement> inputs) { final Set<ValueSpecification> results = Sets.newHashSetWithExpectedSize(inputs.size()); for (Map.Entry<ValueSpecification, ValueRequirement> inputEntry : inputs.entrySet()) { ValueProperties.Builder properties = createValueProperties(); properties.with(CURRENCY_MATRIX_NAME_PROPERTY, inputEntry.getValue().getTargetReference() .getRequirement().getIdentifiers().getValue(CurrencyMatrixResolver.IDENTIFIER_SCHEME)); final ValueProperties inputProperties = inputEntry.getKey().getProperties(); for (String propertyName : inputProperties.getProperties()) { if (!AbstractCurrencyMatrixSourcingFunction.SOURCE_CURRENCY_PROPERTY.equals(propertyName) && !AbstractCurrencyMatrixSourcingFunction.TARGET_CURRENCY_PROPERTY.equals(propertyName) && !ValuePropertyNames.FUNCTION.equals(propertyName)) { final Set<String> values = inputProperties.getValues(propertyName); if (values.isEmpty()) { properties.withAny(propertyName); } else { properties.with(propertyName, values); }/* w w w .j a v a 2 s .co m*/ } } results.add(new ValueSpecification(inputEntry.getKey().getValueName(), target.toSpecification(), properties.get())); } return results; }
From source file:com.isotrol.impe3.idx.feedburner.FeedFlickrIndexer.java
/** * Initializing method, instances conversor function. *///from w w w . jav a2 s .co m public void init() { this.conversor = new Function<SyndEntryImpl, Document>() { public Document apply(SyndEntryImpl input) { final DocumentBuilder builder = new DocumentBuilder(); final nu.xom.Document xml = getXmlDocument(input); final Set<String> channels = categories(input); final String id = ISO9075.encode(input.getUri()); final UUID nodeType = getContentType(channels, defaultContent); if (nodeType == null) { return null; } final Date date = input.getPublishedDate(); final String title = input.getTitle(); final String description = input.getDescription().getValue(); @SuppressWarnings("unchecked") final List<SyndContentImpl> contents = input.getContents(); final Set<UUID> cmapped = mappingsService.getCategories(null, null, channels, xml); final Set<String> smapped = mappingsService.getSets(null, null, channels, xml); builder.setNodeKey(NodeKey.of(nodeType, id)); builder.setField(FeedBurnerSchema.ID, id, true, false); builder.setTitle(title); builder.setDate(date); builder.setExpirationDate(Schema.getMaxCalendar()); builder.setReleaseDate(date); if (description != null) { builder.setDescription(description); builder.setText(description); } builder.addLocale("es"); // TODO for (String set : smapped) { builder.addSet(set); } for (UUID categoryKey : cmapped) { builder.addCategory(categoryKey); } for (String catName : channels) { builder.setField(FeedBurnerSchema.CATEGORY, catName, true, false); } if (contents != null && !contents.isEmpty()) { final StringBuilder sb = new StringBuilder(); for (SyndContentImpl content : contents) { sb.append(content.getValue()); } builder.setBytes(sb.toString().getBytes(), true); } return builder.get(); } private nu.xom.Document getXmlDocument(SyndEntryImpl input) { final nu.xom.Element item = new nu.xom.Element("item"); final nu.xom.Element title = new nu.xom.Element("title"); title.appendChild(input.getTitle()); item.appendChild(title); final nu.xom.Element author = new nu.xom.Element("author"); author.appendChild(input.getAuthor()); item.appendChild(author); final nu.xom.Element link = new nu.xom.Element("link"); link.appendChild(input.getLink()); item.appendChild(link); final nu.xom.Element uri = new nu.xom.Element("uri"); uri.appendChild(input.getUri()); item.appendChild(uri); final nu.xom.Element publishedDate = new nu.xom.Element("publishedDate"); publishedDate.appendChild(String.valueOf(input.getPublishedDate().getTime())); item.appendChild(publishedDate); final SyndContent description = input.getDescription(); if (description != null) { final nu.xom.Element desc = new nu.xom.Element("description"); if (description.getType() != null) { desc.addAttribute(new Attribute("type", description.getType())); } desc.appendChild(description.getValue()); item.appendChild(desc); } @SuppressWarnings("unchecked") final List<SyndCategory> categories = input.getCategories(); if (categories != null) { final nu.xom.Element cats = new nu.xom.Element("categories"); for (SyndCategory category : categories) { final nu.xom.Element cat = new nu.xom.Element("category"); cat.appendChild(category.getName()); cats.appendChild(cat); } item.appendChild(cats); } return new nu.xom.Document(item); } private Set<String> categories(SyndEntryImpl input) { @SuppressWarnings("unchecked") final List<SyndCategoryImpl> categories = input.getCategories(); if (categories != null && !categories.isEmpty()) { final Set<String> channels = splitCategories ? splitChannels(categories) : Sets.newHashSet(Collections2.transform(categories, CAT)); return channels; } else { final Object others = input.getForeignMarkup(); if (others instanceof List) { @SuppressWarnings("unchecked") final List<Element> elements = (List<Element>) others; if (elements == null || elements.isEmpty()) { return Sets.newHashSetWithExpectedSize(0); } final Set<String> channels = Sets.newHashSet(); for (Element elem : elements) { if ("category".equals(elem.getName())) { final String c = elem.getTextTrim(); if (c != null && c.length() > 0) { if (splitCategories) { final StringTokenizer st = new StringTokenizer(c, " "); while (st.hasMoreElements()) { channels.add((String) st.nextElement()); } } else { channels.add(c.replaceAll(" ", "_")); } } } } return channels; } else { return Sets.newHashSetWithExpectedSize(0); } } } private Set<String> splitChannels(List<SyndCategoryImpl> categories) { final Set<String> channels = Sets.newHashSet(); for (SyndCategoryImpl category : categories) { final String c = category.getName(); final StringTokenizer st = new StringTokenizer(c, " "); while (st.hasMoreElements()) { channels.add((String) st.nextElement()); } } return channels; } private UUID getContentType(final Set<String> categories, final String defaultContent) { for (String category : categories) { final UUID uuid = mappingsService.getContentType(category); if (uuid != null) { return uuid; } } return mappingsService.getContentType(defaultContent); } }; }
From source file:com.android.tools.idea.npw.deprecated.NewFormFactorModulePath.java
public void updatePackageDerivedValues() { // TODO: Refactor handling of presets in TemplateParameterStep2 so that this isn't necessary myParameterStep.setPresetValue(PACKAGE_NAME_KEY.name, myState.get(PACKAGE_NAME_KEY)); Set<Key> keys = Sets.newHashSetWithExpectedSize(5); keys.add(PACKAGE_NAME_KEY);/*from w w w . ja va 2s . co m*/ keys.add(SRC_DIR_KEY); keys.add(TEST_DIR_KEY); keys.add(PROJECT_LOCATION_KEY); keys.add(NUM_ENABLED_FORM_FACTORS_KEY); deriveValues(keys); }
From source file:org.graylog2.rest.resources.search.SearchResource.java
protected Set<IndexRangeSummary> indexRangeListToValueList(Set<IndexRange> indexRanges) { final Set<IndexRangeSummary> result = Sets.newHashSetWithExpectedSize(indexRanges.size()); for (IndexRange indexRange : indexRanges) { result.add(IndexRangeSummary.create(indexRange.indexName(), indexRange.begin(), indexRange.end(), indexRange.calculatedAt(), indexRange.calculationDuration())); }/* w w w. j a v a2s . co m*/ return result; }