List of usage examples for java.util Set addAll
boolean addAll(Collection<? extends E> c);
From source file:com.hpcloud.daas.ec2.AwsConsoleApp.java
public static void describeInstances() { try {//w w w . j a v a 2s . c o m DescribeAvailabilityZonesResult availabilityZonesResult = ec2.describeAvailabilityZones(); System.out.println("You have access to " + availabilityZonesResult.getAvailabilityZones().size() + " Availability Zones."); for (AvailabilityZone az : availabilityZonesResult.getAvailabilityZones()) { System.out.println(az); } DescribeInstancesResult describeInstancesRequest = ec2.describeInstances(); List<Reservation> reservations = describeInstancesRequest.getReservations(); Set<Instance> instances = new HashSet<Instance>(); for (Reservation reservation : reservations) { instances.addAll(reservation.getInstances()); } System.out.println("You have " + instances.size() + " Amazon EC2 instance(s) running."); for (Instance instance : instances) { System.out.println(instance); } } catch (AmazonServiceException ase) { System.out.println("Caught Exception: " + ase.getMessage()); System.out.println("Reponse Status Code: " + ase.getStatusCode()); System.out.println("Error Code: " + ase.getErrorCode()); System.out.println("Request ID: " + ase.getRequestId()); } }
From source file:expansionBlocks.ProcessCommunities.java
private static Set<Entity> removableAccordingToCategories(Map<Entity, Double> community) { community = MapUtils.sortByValue(community); Set<Entity> firstLevel = new HashSet<>(); double lastSize = 0.0; for (Map.Entry<Entity, Double> e : community.entrySet()) { if (firstLevel.isEmpty() || lastSize == e.getValue()) { firstLevel.add(e.getKey());//from w ww . ja v a2 s. c om lastSize = e.getValue(); } else break; } println("First level entities: " + firstLevel); Set<Category> firstLevelCategories = new HashSet<>(); for (Entity e : firstLevel) { firstLevelCategories.addAll(e.getCategories()); } println("First Level Categories = " + firstLevelCategories); Set<Category> secondLevelCategories = new HashSet<>(); for (Category c : firstLevelCategories) { secondLevelCategories.addAll(Category.getFathers(c)); } println("Second Level Categories = " + secondLevelCategories); Set<Category> thirdLevelCategories = new HashSet<>(); for (Category c : secondLevelCategories) { thirdLevelCategories.addAll(Category.getFathers(c)); } println("Third Level Categories = " + thirdLevelCategories); Set<Entity> susceptibleToBeRemoved = new HashSet<>(); for (Map.Entry<Entity, Double> e : community.entrySet()) { Entity entity = e.getKey(); Set<Category> entityCategory = entity.getCategories(); boolean maintainEntity = false; for (Category c : entityCategory) { maintainEntity |= (firstLevelCategories.contains(c) || secondLevelCategories.contains(c) || thirdLevelCategories.contains(c) || isSonOf(secondLevelCategories, c) || isGrandSon(thirdLevelCategories, c)); } if (!maintainEntity) susceptibleToBeRemoved.add(entity); } return susceptibleToBeRemoved; }
From source file:delfos.dataset.util.DatasetPrinter.java
public static String printCompactMatrix(Map<Object, Map<Object, String>> matrix) { StringBuilder str = new StringBuilder(); Set<Object> rowKeys = matrix.keySet(); Set<Object> colKeys = new TreeSet<>(); for (Object rowKey : rowKeys) { colKeys.addAll(matrix.get(rowKey).keySet()); }/*from w w w . j av a 2 s . co m*/ //Escribo la cabecera, para los nombres de las columnas { str.append("|\t|"); colKeys.stream().forEach((colKey) -> { str.append(colKey).append("\t|"); }); str.append("\n"); str.append("+-------+"); colKeys.stream().forEach((colKey) -> { str.append("-------+"); }); str.append("\n"); } //Escribo cada lnea for (Object rowKey : rowKeys) { str.append("|").append(rowKey).append("\t|"); for (Object colKey : colKeys) { if (matrix.get(rowKey).containsKey(colKey)) { String cellValue = matrix.get(rowKey).get(colKey); str.append(" ").append(cellValue).append(" \t|"); } else { str.append(" \t|"); } } str.append("\n"); } //Cierro la tabla str.append("+-------+"); colKeys.stream().forEach((colKey) -> { str.append("-------+"); }); str.append("\n"); return str.toString(); }
From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftFileWriterUtil.java
private static void writeProviders(Set<Source> sources, PrintWriter out) { final Set<AbstractContact> all = new HashSet<AbstractContact>(); for (final Source source : sources) { all.addAll(source.getProviders()); }//from www .j a va 2s .c o m for (final AbstractContact c : all) { out.print("!Sample_biomaterial_provider="); out.println(((Organization) c).getName()); } }
From source file:edu.cmu.tetrad.cli.search.FgsCli.java
private static Set<String> getExcludedVariables() { Set<String> variables = new HashSet<>(); try {//from w w w. jav a 2 s. c o m System.out.printf("%s: Start reading in excluded variable file.%n", DateTime.printNow()); LOGGER.info("Start reading in excluded variable file."); variables.addAll(FileIO.extractUniqueLine(excludedVariableFile)); System.out.printf("%s: End reading in excluded variable file.%n", DateTime.printNow()); LOGGER.info("End reading in excluded variable file."); } catch (IOException exception) { String errMsg = String.format("Failed when reading excluded variable file '%s'.", excludedVariableFile.getFileName()); System.err.println(errMsg); LOGGER.error(errMsg, exception); System.exit(-128); } return variables; }
From source file:org.craftercms.commons.ebus.config.EBusBeanAutoConfiguration.java
private static Set<Method> findHandlerMethods(final Class<?> handlerType, final ReflectionUtils.MethodFilter listenerMethodFilter) { final Set<Method> handlerMethods = new LinkedHashSet<Method>(); if (handlerType == null) { return handlerMethods; }//from w w w. ja v a 2 s . c om Set<Class<?>> handlerTypes = new LinkedHashSet<Class<?>>(); Class<?> specifiedHandlerType = null; if (!Proxy.isProxyClass(handlerType)) { handlerTypes.add(handlerType); specifiedHandlerType = handlerType; } handlerTypes.addAll(Arrays.asList(handlerType.getInterfaces())); for (Class<?> currentHandlerType : handlerTypes) { final Class<?> targetClass = (specifiedHandlerType != null ? specifiedHandlerType : currentHandlerType); ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() { @Override public void doWith(final Method method) throws IllegalArgumentException, IllegalAccessException { Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass); Method bridgeMethod = BridgeMethodResolver.findBridgedMethod(specificMethod); if (listenerMethodFilter.matches(specificMethod) && (bridgeMethod == specificMethod || !listenerMethodFilter.matches(bridgeMethod))) { handlerMethods.add(specificMethod); } } }, ReflectionUtils.USER_DECLARED_METHODS); } return handlerMethods; }
From source file:com.wrmsr.wava.basic.BasicLoopInfo.java
public static Map<Name, Name> getLoopParents(SetMultimap<Name, Name> loopContents) { Map<Name, Name> loopParents = new HashMap<>(); Map<Name, Set<Name>> map = loopContents.keySet().stream() .collect(toHashMap(identity(), loop -> new HashSet<>())); for (Name cur : loopContents.keySet()) { map.get(cur).add(ENTRY_NAME);/* w w w. j a va 2s . c o m*/ Set<Name> children = loopContents.get(cur); for (Name child : children) { if (!cur.equals(child) && loopContents.containsKey(child)) { map.get(child).add(cur); } } } Map<Name, Integer> loopDepths = map.entrySet().stream() .collect(toHashMap(entry -> entry.getKey(), entry -> entry.getValue().size())); loopDepths.put(ENTRY_NAME, 0); int maxDepth = loopDepths.values().stream().mapToInt(Integer::intValue).max().orElse(0); List<List<Name>> depthLoopsLists = IntStream.range(0, maxDepth + 1).boxed() .<List<Name>>map(i -> new ArrayList<>()).collect(toArrayList()); loopDepths.forEach((loop, depth) -> depthLoopsLists.get(depth).add(loop)); Set<Name> seen = new HashSet<>(); for (int depth = 1; depth < depthLoopsLists.size(); ++depth) { for (Name loop : depthLoopsLists.get(depth)) { Name parent = getOnlyElement(Sets.difference(map.get(loop), seen)); checkState(loopDepths.get(parent) == depth - 1); loopParents.put(loop, parent); } seen.addAll(depthLoopsLists.get(depth - 1)); } checkState(loopContents.keySet().equals(loopParents.keySet())); return loopParents; }
From source file:eu.itesla_project.modules.validation.OfflineValidationTool.java
private static void writeCsv(Map<String, Map<RuleId, ValidationStatus>> statusPerRulePerCase, Map<String, Map<RuleId, Map<HistoDbAttributeId, Object>>> valuesPerRulePerCase, Path outputDir) throws IOException { Set<RuleId> rulesIds = new TreeSet<>(); statusPerRulePerCase.values().stream().forEach(e -> rulesIds.addAll(e.keySet())); writeComparisonFiles(rulesIds, statusPerRulePerCase, outputDir); writeAttributesFiles(rulesIds, valuesPerRulePerCase, outputDir); List<String> categories = Arrays.asList(toCategory(OK_S, OK_R), toCategory(OK_S, NOK_R), toCategory(NOK_S, OK_R), toCategory(NOK_S, NOK_R), toCategory(OK_S, UNDEF_R), toCategory(NOK_S, UNDEF_R), toCategory(UNDEF_S, OK_R), toCategory(UNDEF_S, NOK_R), toCategory(UNDEF_S, UNDEF_R)); Map<RuleId, Map<String, AtomicInteger>> synthesisPerRule = new HashMap<>(); for (RuleId ruleId : rulesIds) { synthesisPerRule.put(ruleId,//from www .j av a 2s. c o m categories.stream().collect(Collectors.toMap(Function.identity(), e -> new AtomicInteger()))); } for (Map.Entry<String, Map<RuleId, ValidationStatus>> e : statusPerRulePerCase.entrySet()) { Map<RuleId, ValidationStatus> statusPerRule = e.getValue(); for (RuleId ruleId : rulesIds) { ValidationStatus status = statusPerRule.get(ruleId); String category = toCategory(status.isSimulationOkToStr(), status.isRuleOkToStr()); synthesisPerRule.get(ruleId).get(category).incrementAndGet(); } } writeSynthesisFile(synthesisPerRule, categories, outputDir.resolve("synthesis.csv")); }
From source file:ReflectUtil.java
/** * Returns an array of Type objects representing the actual type arguments * to targetType used by clazz.// www . j a va 2 s. co m * * @param clazz the implementing class (or subclass) * @param targetType the implemented generic class or interface * @return an array of Type objects or null */ public static Type[] getActualTypeArguments(Class<?> clazz, Class<?> targetType) { Set<Class<?>> classes = new HashSet<Class<?>>(); classes.add(clazz); if (targetType.isInterface()) classes.addAll(getImplementedInterfaces(clazz)); Class<?> superClass = clazz.getSuperclass(); while (superClass != null) { classes.add(superClass); superClass = superClass.getSuperclass(); } for (Class<?> search : classes) { for (Type type : (targetType.isInterface() ? search.getGenericInterfaces() : new Type[] { search.getGenericSuperclass() })) { if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if (targetType.equals(parameterizedType.getRawType())) return parameterizedType.getActualTypeArguments(); } } } return null; }
From source file:com.googlecode.fightinglayoutbugs.helpers.TestHelper.java
/** * Returns a {@link Set} containing the given <code>objects</code>. *//*w w w. j av a 2 s . c o m*/ public static <T> Set<T> asSet(T... objects) { final Set<T> result; result = new LinkedHashSet<T>(); result.addAll(new ArrayWrapper<T>(objects)); return result; }