List of usage examples for com.google.common.collect Sets newHashSet
public static <E> HashSet<E> newHashSet()
From source file:com.noorq.casser.support.Transformers.java
public static <I, O> Set<O> transformSet(Set<I> inputSet, Function<I, O> func) { Set<O> set = Sets.newHashSet(); for (I in : inputSet) { set.add(func.apply(in));/* ww w . j a v a 2 s . c o m*/ } return set; }
From source file:presto.android.MultiMapUtil.java
public static <Key, HashSetElement, SubClassOfHashSetElement extends HashSetElement> void addKeyAndHashSet( Map<Key, Set<HashSetElement>> map, Key key, Set<SubClassOfHashSetElement> elements) { Set<HashSetElement> set = map.get(key); if (set == null) { set = Sets.newHashSet(); map.put(key, set);/* w w w .ja v a2 s . c o m*/ } set.addAll(elements); }
From source file:org.gradle.api.internal.tasks.properties.TaskPropertyUtils.java
public static <T extends TaskFilePropertySpec> SortedSet<T> collectFileProperties(String displayName, Iterable<? extends T> fileProperties) { Set<String> names = Sets.newHashSet(); ImmutableSortedSet.Builder<T> builder = ImmutableSortedSet.naturalOrder(); for (T propertySpec : fileProperties) { String propertyName = propertySpec.getPropertyName(); if (!names.add(propertyName)) { throw new IllegalArgumentException( String.format("Multiple %s file properties with name '%s'", displayName, propertyName)); }/*from w w w .j a v a 2s. c o m*/ builder.add(propertySpec); } return builder.build(); }
From source file:org.gradle.api.internal.tasks.TaskPropertyUtils.java
public static <T extends TaskFilePropertySpec> SortedSet<T> collectFileProperties(String displayName, Iterator<? extends T> fileProperties) { Set<String> names = Sets.newHashSet(); ImmutableSortedSet.Builder<T> builder = ImmutableSortedSet.naturalOrder(); while (fileProperties.hasNext()) { T propertySpec = fileProperties.next(); String propertyName = propertySpec.getPropertyName(); if (!names.add(propertyName)) { throw new IllegalArgumentException( String.format("Multiple %s file properties with name '%s'", displayName, propertyName)); }// w w w .j a va 2 s .c o m builder.add(propertySpec); } return builder.build(); }
From source file:com.opengamma.web.position.TradeJsonConverter.java
public static Set<ManageableTrade> fromJson(final String json) { Set<ManageableTrade> trades = Sets.newHashSet(); try {/*from w w w . j a v a 2 s. c o m*/ JSONObject jsonObject = new JSONObject(json); if (jsonObject.has("trades")) { JSONArray jsonArray = jsonObject.getJSONArray("trades"); for (int i = 0; i < jsonArray.length(); i++) { JSONObject tradeJson = jsonArray.getJSONObject(i); ManageableTrade trade = new ManageableTrade(); if (tradeJson.has("premium")) { trade.setPremium(tradeJson.getDouble("premium")); } if (tradeJson.has("counterParty")) { trade.setCounterpartyExternalId( ExternalId.of(Counterparty.DEFAULT_SCHEME, tradeJson.getString("counterParty"))); } if (tradeJson.has("premiumCurrency")) { trade.setPremiumCurrency(Currency.of(tradeJson.getString("premiumCurrency"))); } if (tradeJson.has("premiumDate")) { LocalDate premiumDate = LocalDate.parse(tradeJson.getString("premiumDate")); trade.setPremiumDate(premiumDate); if (tradeJson.has("premiumTime")) { LocalTime premiumTime = LocalTime.parse(tradeJson.getString("premiumTime")); ZoneOffset premiumOffset = getOffset(tradeJson, "premiumOffset"); ZonedDateTime zonedDateTime = premiumDate.atTime(premiumTime).atZone(premiumOffset); trade.setPremiumTime(zonedDateTime.toOffsetDateTime().toOffsetTime()); } } if (tradeJson.has("quantity")) { trade.setQuantity(new BigDecimal(tradeJson.getString("quantity"))); } if (tradeJson.has("tradeDate")) { LocalDate tradeDate = LocalDate.parse(tradeJson.getString("tradeDate")); trade.setTradeDate(tradeDate); if (tradeJson.has("tradeTime")) { LocalTime tradeTime = LocalTime.parse(tradeJson.getString("tradeTime")); ZoneOffset tradeOffset = getOffset(tradeJson, "tradeOffset"); ZonedDateTime zonedDateTime = tradeDate.atTime(tradeTime).atZone(tradeOffset); trade.setTradeTime(zonedDateTime.toOffsetDateTime().toOffsetTime()); } } addTradeAttributes(trade, tradeJson); trades.add(trade); } } else { throw new OpenGammaRuntimeException("missing trades field in trades json document"); } } catch (JSONException ex) { throw new OpenGammaRuntimeException("Error parsing Json document for Trades", ex); } return trades; }
From source file:org.impressivecode.depress.common.DataTableSpecUtils.java
public static Set<String> findMissingColumnSubset(final DataTableSpec dataTableSpec, final DataTableSpec subsetDataTableSpec) { Set<String> missing = Sets.newHashSet(); Iterator<DataColumnSpec> iterator = subsetDataTableSpec.iterator(); while (iterator.hasNext()) { DataColumnSpec spec = iterator.next(); boolean hasColumn = spec.equalStructure(dataTableSpec.getColumnSpec(spec.getName())); if (!hasColumn) { missing.add(spec.getName() + ":" + spec.getType()); }/*from ww w . ja v a 2 s . co m*/ } return missing; }
From source file:org.franca.core.dsl.validation.internal.util.GraphUtil.java
/** * Determines whether the given {@link IGraphDataSource} corresponds to a connected graph. * In case of directed graphs the method only checks for weak connectivity not for the strongly connected property. * //ww w . ja va 2 s . co m * @param graphDataSource the graph data source instance * @return true if the graph is connected, false otherwise */ public static <V> boolean isConnected(IGraphDataSource<V> graphDataSource) { if (graphDataSource.getAllNodes().size() > 0) { Set<V> visited = Sets.newHashSet(); List<V> queue = Lists.newArrayList(); queue.add(graphDataSource.getAllNodes().iterator().next()); while (!queue.isEmpty()) { V node = queue.remove(0); visited.add(node); for (V target : graphDataSource.getTargetNodes(node)) { if (!visited.contains(target)) { queue.add(target); } } } return (visited.size() == graphDataSource.getAllNodes().size()); } return true; }
From source file:org.glowroot.common2.repo.ConfigValidation.java
public static void validatePartOne(AgentConfig config) throws Exception { Set<String> gaugeMBeanObjectNames = Sets.newHashSet(); for (AgentConfig.GaugeConfig gaugeConfig : config.getGaugeConfigList()) { if (!gaugeMBeanObjectNames.add(gaugeConfig.getMbeanObjectName())) { throw new DuplicateMBeanObjectNameException(); }//from ww w . j a v a 2 s.c o m } Set<String> syntheticMonitorDisplays = Sets.newHashSet(); for (AgentConfig.SyntheticMonitorConfig syntheticMonitorConfig : config.getSyntheticMonitorConfigList()) { if (!syntheticMonitorDisplays.add(syntheticMonitorConfig.getDisplay())) { throw new DuplicateSyntheticMonitorDisplayException(); } } Set<String> alertVersions = Sets.newHashSet(); for (AgentConfig.AlertConfig alertConfig : config.getAlertConfigList()) { if (!alertVersions.add(Versions.getVersion(alertConfig))) { throw new IllegalStateException("Duplicate alerts"); } } Set<String> pluginIds = Sets.newHashSet(); for (AgentConfig.PluginConfig pluginConfig : config.getPluginConfigList()) { if (!pluginIds.add(pluginConfig.getId())) { throw new IllegalStateException("Duplicate plugin id: " + pluginConfig.getId()); } } Set<String> instrumentationVersions = Sets.newHashSet(); for (AgentConfig.InstrumentationConfig instrumentationConfig : config.getInstrumentationConfigList()) { if (!instrumentationVersions.add(Versions.getVersion(instrumentationConfig))) { throw new IllegalStateException("Duplicate instrumentation"); } } }
From source file:com.googlecode.t7mp.util.FileUtil.java
public static Set<File> getAllFiles(File rootDirectory, FileFilter fileFilter, boolean includeSubdirectories) { Set<File> fileSet = Sets.newHashSet(); return getAllFiles(rootDirectory, fileSet, fileFilter, includeSubdirectories); }
From source file:com.topekalabs.collection.utils.SetUtils.java
/** * This method returns the union of the two provided sets. * @param <T> The type of the objects contained in the input sets. * @param setA An input set./*from www. j a va 2 s .com*/ * @param setB An input set. * @return The union of setA and setB. */ public static <T> Set<T> unionSet(Set<T> setA, Set<T> setB) { Set<T> unionSet = Sets.newHashSet(); unionSet.addAll(setA); unionSet.addAll(setB); return unionSet; }