List of usage examples for com.google.common.collect Sets newHashSetWithExpectedSize
public static <E> HashSet<E> newHashSetWithExpectedSize(int expectedSize)
From source file:com.opengamma.integration.viewer.status.impl.SimpleViewStatusModel.java
@Override public Set<String> getValueRequirementNames() { Set<String> result = Sets.newHashSetWithExpectedSize(_viewStatusResult.size()); for (ViewStatusKey key : _viewStatusResult.keySet()) { result.add(key.getValueRequirementName()); }//from w w w.ja v a 2 s . c om return result; }
From source file:com.android.build.gradle.internal.dsl.SplitOptions.java
/** * Returns a list of all applicable filters for this dimension. * * <p>The list can return null, indicating that the no-filter option must also be used. * * @return the filters to use./*from w ww . java 2 s . c o m*/ */ @NonNull public Set<String> getApplicableFilters() { if (!enable) { return Collections.emptySet(); } Set<String> results = Sets.newHashSetWithExpectedSize(values.size()); for (String value : values) { if (allowedValues.contains(value)) { results.add(value); } } return results; }
From source file:org.attribyte.api.pubsub.impl.server.PingServlet.java
/** * Gets all public names (IP, hostname). * Always starts with "pong" and contains the instance name, if specified. * @return The list of names./* www . java 2 s. com*/ */ private Set<String> getPublicNames() { Set<String> names = Sets.newHashSetWithExpectedSize(8); names.add("pong"); if (instanceName != null && instanceName.length() > 0) { names.add(instanceName); } if (enumerateInterfaces) { try { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface iface = interfaces.nextElement(); if (!iface.isLoopback() && !iface.isPointToPoint() && !iface.isVirtual() && iface.isUp()) { for (final InterfaceAddress interfaceAddress : iface.getInterfaceAddresses()) { InetAddress addy = interfaceAddress.getAddress(); if (!addy.isLoopbackAddress() && !addy.isMulticastAddress() && !addy.isLinkLocalAddress() && !addy.isSiteLocalAddress() && !addy.isAnyLocalAddress()) { String hostAddress = addy.getHostAddress(); if (!hostAddress.contains("%")) { names.add(hostAddress); String hostname = addy.getHostName(); if (hostname != null) { names.add(hostname); } } } } } } } catch (SocketException se) { //Ignore } } return names; }
From source file:com.mgmtp.jfunk.data.source.BaseDataSource.java
protected Set<String> getFormDataKeys() { try {/*from w ww . j av a 2s. c o m*/ Map<String, String> view = Maps.filterKeys(configuration, Predicates.startsWith(JFunkConstants.FORM_DATA_PREFIX)); formDataKeys = Sets.newHashSetWithExpectedSize(view.size()); for (String key : view.keySet()) { String fixedPropsFilenameKey = key; int i = fixedPropsFilenameKey.lastIndexOf('.'); String dataKey = fixedPropsFilenameKey.substring(9, i); formDataKeys.add(dataKey); // Load fixed properties String fixedPropsFilename = configuration.get(fixedPropsFilenameKey); if (StringUtils.isNotEmpty(fixedPropsFilename)) { InputStream is = null; try { ExtendedProperties fixedProps = new ExtendedProperties(); is = configuration.openStream(fixedPropsFilename); fixedProps.load(is); for (Entry<String, String> entry : fixedProps.entrySet()) { setFixedValue(dataKey, entry.getKey(), entry.getValue()); } } finally { IOUtils.closeQuietly(is); } } } } catch (IOException ex) { throw new JFunkException("Error loading form data keys.", ex); } return formDataKeys; }
From source file:com.google.template.soy.shared.internal.BackendModuleUtils.java
/** * Given a backend-specific Soy directive type and the set of all Soy directive implementations, * finds the Soy directives that are implemented for the specific backend and returns them in the * form of a map from directive name to directive. * * @param backendSpecificSoyDirectiveType The backend-specific Soy directive type to filter for. * @param soyDirectivesSet The set of all Soy directives. * @return A map of the relevant backend-specific Soy directives (name to directive). */// w ww . ja v a 2s . c om public static <T extends SoyPrintDirective> Map<String, T> buildBackendSpecificSoyDirectivesMap( Class<T> backendSpecificSoyDirectiveType, Set<SoyPrintDirective> soyDirectivesSet) { ImmutableMap.Builder<String, T> mapBuilder = ImmutableMap.builder(); Set<String> seenDirectiveNames = Sets.newHashSetWithExpectedSize(soyDirectivesSet.size()); for (SoyPrintDirective directive : soyDirectivesSet) { if (backendSpecificSoyDirectiveType.isAssignableFrom(directive.getClass())) { String directiveName = directive.getName(); if (seenDirectiveNames.contains(directiveName)) { throw new IllegalStateException( "Found two implementations of " + backendSpecificSoyDirectiveType.getSimpleName() + " with the same directive name '" + directiveName + "'."); } seenDirectiveNames.add(directiveName); mapBuilder.put(directiveName, backendSpecificSoyDirectiveType.cast(directive)); } } return mapBuilder.build(); }
From source file:com.torodb.backend.converters.jooq.ToroIndexConverter.java
@Override public NamedToroIndex from(String databaseObject) { JsonReader reader = Json.createReader(new StringReader(databaseObject)); JsonObject object = reader.readObject(); IndexedAttributes.Builder builder = new IndexedAttributes.Builder(); JsonArray attsArray = object.getJsonArray(ATTS_KEY); Set<Integer> descendingAttPos; if (object.containsKey(DESCENDING)) { JsonArray descArray = object.getJsonArray(DESCENDING); descendingAttPos = Sets.newHashSetWithExpectedSize(descArray.size()); for (int i = 0; i < descArray.size(); i++) { descendingAttPos.add(descArray.getInt(i)); }/*ww w. j a v a 2 s. c o m*/ } else { descendingAttPos = Collections.emptySet(); } for (int i = 0; i < attsArray.size(); i++) { String att = attsArray.getString(i); AttributeReference attRef = parseAttRef(att); if (descendingAttPos.contains(i)) { builder.addAttribute(attRef, IndexType.desc); } else { builder.addAttribute(attRef, IndexType.asc); } } return new DefaultNamedToroIndex(object.getString(NAME_KEY), builder.build(), databaseName, collectionName, object.getBoolean(UNIQUE_KEY, false)); }
From source file:org.eclipse.che.workspace.infrastructure.docker.environment.compose.ComposeServicesStartStrategy.java
/** * Returns mapping of names of services to its weights in dependency graph. * * @throws ValidationException if weights of services can not be calculated *//*from w w w. j a v a 2 s .c o m*/ private Map<String, Integer> weightServices(Map<String, ComposeService> services) throws ValidationException { HashMap<String, Integer> weights = new HashMap<>(); // create services dependency graph Map<String, Set<String>> dependencies = new HashMap<>(services.size()); for (Map.Entry<String, ComposeService> containerEntry : services.entrySet()) { ComposeService service = containerEntry.getValue(); Set<String> serviceDependencies = Sets.newHashSetWithExpectedSize( service.getDependsOn().size() + service.getLinks().size() + service.getVolumesFrom().size()); for (String dependsOn : service.getDependsOn()) { checkDependency(dependsOn, containerEntry.getKey(), services, "A service can not depend on itself"); serviceDependencies.add(dependsOn); } // links also counts as dependencies for (String link : service.getLinks()) { String dependency = getContainerFromLink(link); checkDependency(dependency, containerEntry.getKey(), services, "A service can not link to itself"); serviceDependencies.add(dependency); } // volumesFrom also counts as dependencies for (String volumesFrom : service.getVolumesFrom()) { String dependency = getContainerFromVolumesFrom(volumesFrom); checkDependency(dependency, containerEntry.getKey(), services, "A service can not contain 'volumes_from' to itself"); serviceDependencies.add(dependency); } dependencies.put(containerEntry.getKey(), serviceDependencies); } // Find weight of each service in graph. // Weight of service is calculated as sum of all weights of services it depends on. // Nodes with no dependencies gets weight 0 while (!dependencies.isEmpty()) { int previousSize = dependencies.size(); for (Iterator<Map.Entry<String, Set<String>>> it = dependencies.entrySet().iterator(); it.hasNext();) { // process not yet processed services only Map.Entry<String, Set<String>> containerEntry = it.next(); String container = containerEntry.getKey(); Set<String> containerDependencies = containerEntry.getValue(); if (containerDependencies.isEmpty()) { // no links - smallest weight 0 weights.put(container, 0); it.remove(); } else { // service has dependencies - check if it has not weighted dependencies if (weights.keySet().containsAll(containerDependencies)) { // all connections are weighted - lets evaluate current service Optional<String> maxWeight = containerDependencies.stream() .max(Comparator.comparing(weights::get)); // optional can't be empty because size of the list is checked above // noinspection OptionalGetWithoutIsPresent weights.put(container, weights.get(maxWeight.get()) + 1); it.remove(); } } } if (dependencies.size() == previousSize) { throw new ValidationException( "Launch order of services '" + Joiner.on(", ").join(dependencies.keySet()) + "' can't be evaluated. Circular dependency."); } } return weights; }
From source file:com.palantir.atlasdb.keyvalue.api.RowResult.java
public Set<Cell> getCellSet() { Set<Cell> cells = Sets.newHashSetWithExpectedSize(columns.size()); for (byte[] column : columns.keySet()) { cells.add(Cell.create(row, column)); }//from w ww . j av a 2 s . c o m return cells; }
From source file:org.apache.phoenix.compile.AggregationManager.java
/** * Compiles projection by:/*from w ww . j a v a 2 s .com*/ * 1) Adding RowCount aggregate function if not present when limiting rows. We need this * to track how many rows have been scanned. * 2) Reordering aggregation functions (by putting fixed length aggregates first) to * optimize the positional access of the aggregated value. */ public void compile(StatementContext context, GroupByCompiler.GroupBy groupBy) throws SQLException { final Set<SingleAggregateFunction> aggFuncSet = Sets .newHashSetWithExpectedSize(context.getExpressionManager().getExpressionCount()); Iterator<Expression> expressions = context.getExpressionManager().getExpressions(); while (expressions.hasNext()) { Expression expression = expressions.next(); expression.accept(new SingleAggregateFunctionVisitor() { @Override public Iterator<Expression> visitEnter(SingleAggregateFunction function) { aggFuncSet.add(function); return Iterators.emptyIterator(); } }); } if (aggFuncSet.isEmpty() && groupBy.isEmpty()) { return; } List<SingleAggregateFunction> aggFuncs = new ArrayList<SingleAggregateFunction>(aggFuncSet); Collections.sort(aggFuncs, SingleAggregateFunction.SCHEMA_COMPARATOR); int minNullableIndex = getMinNullableIndex(aggFuncs, groupBy.isEmpty()); context.getScan().setAttribute(BaseScannerRegionObserver.AGGREGATORS, ServerAggregators.serialize(aggFuncs, minNullableIndex)); ClientAggregators clientAggregators = new ClientAggregators(aggFuncs, minNullableIndex); context.getAggregationManager().setAggregators(clientAggregators); }
From source file:com.b2international.snowowl.snomed.importer.rf2.refset.RefSetMemberLookup.java
public <M> Collection<M> getMembers(Collection<String> memberIds) { final Collection<M> members = Sets.newHashSetWithExpectedSize(memberIds.size()); final Set<String> missingMemberIds = Sets.newHashSet(); for (String memberId : memberIds) { final M component = getNewMember(memberId); if (component != null) { members.add(component);/*w w w .j ava2 s . co m*/ } else { missingMemberIds.add(memberId); } } if (missingMemberIds.isEmpty()) { return members; } LongIterator storageKeys = getComponentStorageKeys(missingMemberIds).iterator(); while (storageKeys.hasNext()) { final long storageKey = storageKeys.next(); members.add((M) editingContext.lookup(storageKey)); } return members; }