List of usage examples for java.util Map values
Collection<V> values();
From source file:AIR.Common.collections.IGrouping.java
public static <K, V> List<IGrouping<K, V>> createGroups(Collection<V> list, Transformer transformer) { Map<K, IGrouping<K, V>> map = new HashMap<K, IGrouping<K, V>>(); for (V element : list) { @SuppressWarnings("unchecked") K groupValue = (K) transformer.transform(element); IGrouping<K, V> group = null; if (map.containsKey(groupValue)) { group = map.get(groupValue); } else {/* www. j a va 2 s . co m*/ group = new IGrouping<K, V>(groupValue); map.put(groupValue, group); } group.add(element); } return new ArrayList<IGrouping<K, V>>(map.values()); }
From source file:org.dspace.servicemanager.DSpaceServiceManager.java
/** * Adds configuration settings into services if possible. * Skips any that are invalid./* www .ja va 2s . c o m*/ * * @param serviceName the name of the service * @param service the service object * @param serviceNameConfigs all known service configuration settings (from the DS config service impl) */ public static void configureService(String serviceName, Object service, Map<String, Map<String, ServiceConfig>> serviceNameConfigs) { // stuff the config settings into the bean if there are any if (serviceNameConfigs.containsKey(serviceName)) { BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(service); Map<String, ServiceConfig> configs = serviceNameConfigs.get(serviceName); for (ServiceConfig config : configs.values()) { try { beanWrapper.setPropertyValue(config.getParamName(), config.getValue()); log.info("Set param (" + config.getParamName() + ") on service bean (" + serviceName + ") to: " + config.getValue()); } catch (RuntimeException e) { log.error("Unable to set param (" + config.getParamName() + ") on service bean (" + serviceName + "): " + e.getMessage(), e); } } } }
From source file:eu.itesla_project.modules.simulation.ImpactAnalysisTool.java
private static void writeCsv(Map<String, Map<SecurityIndexId, SecurityIndex>> securityIndexesPerCase, Path outputCsvFile) throws IOException { Objects.requireNonNull(outputCsvFile); Set<SecurityIndexId> securityIndexIds = new LinkedHashSet<>(); for (Map<SecurityIndexId, SecurityIndex> securityIndexesPerId : securityIndexesPerCase.values()) { if (securityIndexesPerId != null) { securityIndexIds.addAll(securityIndexesPerId.keySet()); }/*w w w .j a v a2 s. c o m*/ } try (BufferedWriter writer = Files.newBufferedWriter(outputCsvFile, StandardCharsets.UTF_8)) { writer.write("Base case"); for (SecurityIndexId securityIndexId : securityIndexIds) { writer.write(CSV_SEPARATOR); writer.write(securityIndexId.toString()); } writer.newLine(); for (Map.Entry<String, Map<SecurityIndexId, SecurityIndex>> entry : securityIndexesPerCase.entrySet()) { String baseCaseName = entry.getKey(); writer.write(baseCaseName); Map<SecurityIndexId, SecurityIndex> securityIndexes = entry.getValue(); for (SecurityIndexId securityIndexId : securityIndexIds) { Boolean b = null; if (securityIndexes != null) { SecurityIndex securityIndex = securityIndexes.get(securityIndexId); if (securityIndex != null) { b = securityIndex.isOk(); } } writer.write(CSV_SEPARATOR); writer.write(okToStr(b)); } writer.newLine(); } } }
From source file:name.abhijitsarkar.algorithms.core.Sorter.java
public static Integer[] countingSort(final int[] arr) { final Map<Integer, Pair> countMap = new HashMap<>(); for (final int i : arr) { Pair p = new Pair(i, 1); if (countMap.containsKey(i)) { p.value += countMap.get(i).value; }// w w w . ja v a2s .c om countMap.put(i, p); } BinarySearchTree<Pair> bst = new BinarySearchTree<>(countMap.values()); final List<Pair> sortedPairs = BinaryTreeWalker.recursiveInorder(bst.root()); return CollectionUtils.collect(sortedPairs, TransformerUtils.<Pair, Integer>invokerTransformer("getKey")) .toArray(new Integer[] {}); }
From source file:com.microsoft.tfs.core.clients.favorites.IdentityFavoritesStore.java
/** * Remove entries by given id list.//from ww w . ja v a 2 s . com * <p> * No-op on empty input */ private static void remove(final TeamFoundationIdentity identity, final String effectiveNamespace, final GUID[] items) { if (items == null || items.length == 0) { return; } boolean allEmpty = true; for (final GUID item : items) { if (!GUID.EMPTY.equals(item)) { allEmpty = false; break; } } if (allEmpty) { return; } final Map<GUID, FavoriteItem> dict = new HashMap<GUID, FavoriteItem>(); for (final FavoriteItem item : getFavorites(identity)) { dict.put(item.getID(), item); } final Set<GUID> itemsToDelete = new HashSet<GUID>(Arrays.asList(items)); for (final FavoriteItem favItem : dict.values()) { fixTree(favItem, dict, itemsToDelete); } for (final GUID id : itemsToDelete) { removeViewProperty(identity, IdentityPropertyScope.LOCAL, effectiveNamespace, id.getGUIDString()); } }
From source file:org.zenoss.zep.impl.PluginServiceImpl.java
/** * Detects any cycles in the specified plug-ins and their dependencies. * * @param plugins/*w ww . j av a 2 s. c o m*/ * The plug-ins to analyze. * @param existingDeps * Any existing dependency ids which don't trigger a * {@link MissingDependencyException}. * @throws MissingDependencyException * If a dependency is not found. * @throws DependencyCycleException * If a cycle in the dependencies is detected. */ static void detectCycles(Map<String, ? extends EventPlugin> plugins, Set<String> existingDeps) throws MissingDependencyException, DependencyCycleException { Set<String> analyzed = new HashSet<String>(); for (EventPlugin plugin : plugins.values()) { detectPluginCycles(plugins, existingDeps, plugin, analyzed, new HashSet<String>()); } }
From source file:com.wrmsr.wava.util.collect.MoreMultimaps.java
public static <K, V> Multimap<K, V> unmodifiableMultimapView(Map<K, Collection<V>> collectionMap) { // checkArgument(collectionMap.values().stream().allMatch(coll -> !coll.isEmpty())); return new Multimap<K, V>() { private OptionalInt size = OptionalInt.empty(); private int cachedSize() { if (!size.isPresent()) { size = OptionalInt.of(collectionMap.values().stream().mapToInt(coll -> { checkState(!coll.isEmpty()); return coll.size(); }).sum());/*from w ww.j a v a 2 s . c o m*/ } return size.getAsInt(); } @Override public int size() { return cachedSize(); } @Override public boolean isEmpty() { return !collectionMap.isEmpty(); } @Override public boolean containsKey(@Nullable Object key) { return collectionMap.containsKey(key); } @Override public boolean containsValue(@Nullable Object value) { return collectionMap.values().stream().anyMatch(coll -> coll.contains(value)); } @Override public boolean containsEntry(@Nullable Object key, @Nullable Object value) { return collectionMap.getOrDefault(key, ImmutableList.of()).contains(value); } @Override public boolean put(@Nullable K key, @Nullable V value) { throw new UnsupportedOperationException(); } @Override public boolean remove(@Nullable Object key, @Nullable Object value) { throw new UnsupportedOperationException(); } @Override public boolean putAll(@Nullable K key, Iterable<? extends V> values) { throw new UnsupportedOperationException(); } @Override public boolean putAll(Multimap<? extends K, ? extends V> multimap) { throw new UnsupportedOperationException(); } @Override public Collection<V> replaceValues(@Nullable K key, Iterable<? extends V> values) { throw new UnsupportedOperationException(); } @Override public Collection<V> removeAll(@Nullable Object key) { throw new UnsupportedOperationException(); } @Override public void clear() { throw new UnsupportedOperationException(); } @Override public Collection<V> get(@Nullable K key) { return collectionMap.getOrDefault(key, ImmutableList.of()); } @Override public Set<K> keySet() { return collectionMap.keySet(); } @Override public Multiset<K> keys() { // FIXME throw new UnsupportedOperationException(); } @Override public Collection<V> values() { return new AbstractCollection<V>() { @Override public Iterator<V> iterator() { return Iterators.concat(collectionMap.values().stream().map(Iterable::iterator).iterator()); } @Override public int size() { return cachedSize(); } }; } @Override public Collection<Map.Entry<K, V>> entries() { return new AbstractCollection<Map.Entry<K, V>>() { @Override public Iterator<Map.Entry<K, V>> iterator() { return Iterators.concat(collectionMap.entrySet().stream() .map(entry -> entry.getValue().stream() .map(value -> ImmutablePair.of(entry.getKey(), value)).iterator()) .iterator()); } @Override public int size() { return cachedSize(); } }; } @Override public Map<K, Collection<V>> asMap() { return collectionMap; } }; }
From source file:Main.java
public static String request(String url, Map<String, String> cookies, Map<String, String> parameters) throws Exception { HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36"); if (cookies != null && !cookies.isEmpty()) { StringBuilder cookieHeader = new StringBuilder(); for (String cookie : cookies.values()) { if (cookieHeader.length() > 0) { cookieHeader.append(";"); }// w w w . ja v a 2 s . co m cookieHeader.append(cookie); } connection.setRequestProperty("Cookie", cookieHeader.toString()); } connection.setDoInput(true); if (parameters != null && !parameters.isEmpty()) { connection.setDoOutput(true); OutputStreamWriter osw = new OutputStreamWriter(connection.getOutputStream()); osw.write(parametersToWWWFormURLEncoded(parameters)); osw.flush(); osw.close(); } if (cookies != null) { for (Map.Entry<String, List<String>> headerEntry : connection.getHeaderFields().entrySet()) { if (headerEntry != null && headerEntry.getKey() != null && headerEntry.getKey().equalsIgnoreCase("Set-Cookie")) { for (String header : headerEntry.getValue()) { for (HttpCookie httpCookie : HttpCookie.parse(header)) { cookies.put(httpCookie.getName(), httpCookie.toString()); } } } } } Reader r = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringWriter w = new StringWriter(); char[] buffer = new char[1024]; int n = 0; while ((n = r.read(buffer)) != -1) { w.write(buffer, 0, n); } r.close(); return w.toString(); }
From source file:expansionBlocks.ProcessCommunities.java
public static Pair<Map<Entity, Double>, Map<Entity, Double>> execute(Configuration configuration, Query query) throws Exception { Map<Set<Long>, Map<Entity, Double>> mapPathCommunities = query.getCommunities(); HashSet<Map<Entity, Double>> initialCommunities = new HashSet<>(mapPathCommunities.values()); Set<Map<Entity, Double>> scaledCommunities = new HashSet<>(); AbstractCommunityScalator as = configuration.getAbstractCommunityScalator(); for (Map<Entity, Double> community : initialCommunities) { Map<Entity, Double> scaledCommunity = as.scaledEmphasisArticlesInCommunity(configuration, query, community);/* w ww. j a v a2 s . co m*/ scaledCommunities.add(scaledCommunity); } Set<Map<Entity, Double>> communitiesFusioned = getCommunitiesFromCommunitiesBasedOnSimilarity( scaledCommunities, configuration.getFusionThreshold()); if (configuration.DEBUG_INFO) { println("Fusion communities based on similarity communities: "); for (Map<Entity, Double> community : communitiesFusioned) { println(community); } } println(initialCommunities.size() + " communities have been fusioned into " + communitiesFusioned.size()); println("[[WARNING]] - Select best community algorithm seems to differ from select best path. You may want to double ckeck it."); Set<Map<Entity, Double>> selectBestCommunities = selectBestCommunities(configuration, communitiesFusioned, query.getTokenNames()); if (configuration.DEBUG_INFO) { println("Selected best communities: "); for (Map<Entity, Double> community : selectBestCommunities) { println(StringUtilsQueryExpansion.MapDoubleValueToString(community)); } } Map<Entity, Double> result = agregateCommunities(selectBestCommunities); if (configuration.DEBUG_INFO) { println("Agragated community(size: " + result.size() + "): "); println(StringUtilsQueryExpansion.MapDoubleValueToString(result)); } Set<Entity> entitiesToRemove = new HashSet<>(); /*for (Map.Entry<Entity, Double> e : result.entrySet()) { Set<Category> categories = e.getKey().getCategories(); println("Categories of \"" + e.getKey() + "\": " + categories); if (categories.isEmpty()) entitiesToRemove.add(e.getKey()); }*/ entitiesToRemove.addAll(removableAccordingToCategories(result)); Map<Entity, Double> filteredCommunity = new HashMap<>(result); for (Entity e : entitiesToRemove) { filteredCommunity.remove(e); } println("Based on category analisy I would suggest to remove: " + entitiesToRemove); println("New Community in case of category based filtering" + StringUtilsQueryExpansion.MapDoubleValueToString(filteredCommunity)); query.setCommunityAfterRemoval(filteredCommunity); query.setCommunity(result); return new Pair<>(result, filteredCommunity); }
From source file:org.bigtester.ate.GlobalUtils.java
/** * Find db initializer./*w w w. j a v a 2s. co m*/ * * @param appCtx * the app ctx * @return the test database initializer */ public static TestDatabaseInitializer findDBInitializer(ApplicationContext appCtx) throws NoSuchBeanDefinitionException { Map<String, TestDatabaseInitializer> dbInit = appCtx.getBeansOfType(TestDatabaseInitializer.class); if (dbInit.isEmpty()) { throw new NoSuchBeanDefinitionException(TestDatabaseInitializer.class); } else { TestDatabaseInitializer retVal = dbInit.values().iterator().next(); if (null == retVal) { throw new NoSuchBeanDefinitionException(TestDatabaseInitializer.class); } else { return retVal; } } }