List of usage examples for java.util SortedSet addAll
boolean addAll(Collection<? extends E> c);
From source file:com.aurel.track.admin.customize.category.filter.execute.loadItems.LoadItemLinksUtil.java
/** * Get the linked workItemIDs/*from ww w . j ava 2 s .c o m*/ * @param linkedWorkItemIDsMap * @return */ private static SortedSet<Integer> getFlatItems(Map<Integer, SortedSet<Integer>> linkedWorkItemIDsMap) { //get the flat linked items SortedSet<Integer> linkedWorkItemIDsSet = new TreeSet<Integer>(); if (linkedWorkItemIDsMap != null) { Iterator<SortedSet<Integer>> iterator = linkedWorkItemIDsMap.values().iterator(); while (iterator.hasNext()) { linkedWorkItemIDsSet.addAll(iterator.next()); } } return linkedWorkItemIDsSet; }
From source file:spade.storage.CompressedTextFile.java
private static SortedSet<Integer> uncompressReference(Integer id, String ancestorOrSuccessorList, boolean ancestorOrSuccessor) throws UnsupportedEncodingException { //System.out.println("step m"); SortedSet<Integer> list = new TreeSet<Integer>(); StringTokenizer st = new StringTokenizer(ancestorOrSuccessorList); //System.out.println("ancestorOrSuccessorList :" + ancestorOrSuccessorList + " /id :" + id); //st.nextToken(); String token = st.nextToken(); //System.out.println("step n"); Integer referenceID = id + Integer.parseInt(token); //System.out.println("referenceID1: " + referenceID); LinkedList<String> previousLayers = new LinkedList<String>(); previousLayers.addFirst(id + " " + ancestorOrSuccessorList); String toUncompress;//from w w w . ja v a 2s .c o m //System.out.println("step o"); boolean hasReference = true; //System.out.println(toUncompress); //System.out.println(ancestorOrSuccessorList); while (hasReference) { //System.out.println("step p"); String currentLine = get(scaffoldWriter, referenceID); if (currentLine.length() > 0) { if (ancestorOrSuccessor) { // we want to uncompress ancestors toUncompress = currentLine.substring(currentLine.indexOf(' ') + 1, currentLine.indexOf("/") - 1); } else { // we want to uncompress successors toUncompress = currentLine.substring(currentLine.indexOf("/") + 2); toUncompress = toUncompress.substring(toUncompress.indexOf(' ') + 1); } //System.out.println("step q"); //System.out.println("toUncompress:" + toUncompress); // System.out.println(toUncompress); toUncompress = referenceID + " " + toUncompress; previousLayers.addFirst(toUncompress); //System.out.println("step r"); if (toUncompress.contains(" _ ")) { // this is the last layer hasReference = false; } else { // we need to go one layer further to uncompress the successors String aux = toUncompress.substring(toUncompress.indexOf(" ") + 1); //System.out.println("toUncompress:" + toUncompress); referenceID = referenceID + Integer.parseInt(aux.substring(0, aux.indexOf(" "))); // System.out.println("referenceID : " + referenceID); //System.out.println("step s"); } } else { System.out.println("Data missing."); hasReference = false; } //System.out.println("step t"); } // System.out.println("previousLayers: " + previousLayers.toString()); String bitListLayer; String remainingNodesLayer; Integer layerID; for (String layer : previousLayers) { //find the successors of the first layer and then those of the second layer and so on... layerID = Integer.parseInt(layer.substring(0, layer.indexOf(" "))); //System.out.println("step u"); if (layer.contains("_ ")) { //this is the case for the first layer only remainingNodesLayer = layer.substring(layer.indexOf("_ ") + 2); //System.out.println("step v"); } else { // uncompress the bitlist remainingNodesLayer = layer.substring(layer.indexOf(" ") + 1); //System.out.println("remaining Nodes Layer 1: " + remainingNodesLayer); //// System.out.println("step 1 :" + remainingNodesLayer + "/"); remainingNodesLayer = remainingNodesLayer.substring(remainingNodesLayer.indexOf(" ") + 1); //remainingNodesLayer = remainingNodesLayer.substring(remainingNodesLayer.indexOf(" ") + 1); //// System.out.println("step 2 :" + remainingNodesLayer + "/"); //System.out.println("step w"); //System.out.println("remaining Nodes Layer " + remainingNodesLayer); if (remainingNodesLayer.contains(" ")) { bitListLayer = remainingNodesLayer.substring(0, remainingNodesLayer.indexOf(" ")); remainingNodesLayer = remainingNodesLayer.substring(remainingNodesLayer.indexOf(" ") + 1); } else { bitListLayer = remainingNodesLayer.substring(0); remainingNodesLayer = ""; } //System.out.println("bitListLayer :" + bitListLayer + "/"); int count = 0; SortedSet<Integer> list2 = new TreeSet<Integer>(); list2.addAll(list); // System.out.println("step x"); //System.out.println(bitListLayer); for (Integer successor : list2) { //System.out.println(successor + " " + count); if (bitListLayer.charAt(count) == '0') { list.remove(successor); //System.out.println("step y"); } count++; } } // uncompress remaining nodes list.addAll(uncompressRemainingNodes(layerID, remainingNodesLayer)); //System.out.println("step z"); } //System.out.println("uncompressReference : " + list.toString() + "id : " + id); return list; }
From source file:com.cloudera.whirr.cm.CmServerClusterInstance.java
@SuppressWarnings("unchecked") public static SortedSet<String> getMounts(ClusterSpec specification, Set<Instance> instances) throws IOException { Configuration configuration = getConfiguration(specification); SortedSet<String> mounts = new TreeSet<String>(); Set<String> deviceMappings = CmServerClusterInstance.getDeviceMappings(specification, instances).keySet(); if (!configuration.getList(CONFIG_WHIRR_DATA_DIRS_ROOT).isEmpty()) { mounts.addAll(configuration.getList(CONFIG_WHIRR_DATA_DIRS_ROOT)); } else if (!deviceMappings.isEmpty()) { mounts.addAll(deviceMappings);//from ww w. ja va 2s . c om } else { mounts.add(configuration.getString(CONFIG_WHIRR_INTERNAL_DATA_DIRS_DEFAULT)); } return mounts; }
From source file:controllers.nwbib.Application.java
private static List<String> cleanSortUnique(List<JsonNode> topics) { List<String> filtered = topics.stream().map(topic -> topic.textValue().replaceAll("\\([\\d,]+\\)$", "")) .filter(topic -> !topic.trim().startsWith(":")).map(v -> v.trim()).collect(Collectors.toList()); SortedSet<String> sortedUnique = new TreeSet<>( (s1, s2) -> Collator.getInstance(Locale.GERMAN).compare(s1, s2)); sortedUnique.addAll(filtered); return new ArrayList<>(sortedUnique); }
From source file:spade.storage.CompressedTextFile.java
public static boolean encodeAncestorsSuccessors( HashMap.Entry<Integer, Pair<SortedSet<Integer>, SortedSet<Integer>>> nodeToCompress) { //find reference node Integer id = nodeToCompress.getKey(); //System.out.println(id); SortedSet<Integer> ancestors = nodeToCompress.getValue().first(); SortedSet<Integer> successors = nodeToCompress.getValue().second(); //NodeLayerAncestorSuccessor currentNode = new NodeLayerAncestorSuccessor(id, ancestors, successors); Pair<Integer, Integer> maxNodesInCommonAncestor = new Pair<Integer, Integer>(0, 0); Pair<Integer, Integer> maxNodesInCommonSuccessor = new Pair<Integer, Integer>(0, 0); //first integer is the max of nodes in common, the second one is the number of 0 in the corresponding bit list //NodeLayerAncestorSuccessor referenceAncestor = currentNode; String bitlistAncestor = ""; int layerAncestor = 1; Integer referenceAncestor = -1; SortedSet<Integer> referenceAncestorList = new TreeSet<Integer>(); //NodeLayerAncestorSuccessor referenceSuccessor = currentNode; String bitlistSuccessor = ""; int layerSuccessor = 1; Integer referenceSuccessor = -1; SortedSet<Integer> referenceSuccessorList = new TreeSet<Integer>(); //Iterator<NodeLayerAncestorSuccessor> iteratorPossibleReference = lastNodesSeen.iterator(); //while (iteratorPossibleReference.hasNext()){ //System.out.println("step 1"); for (Integer possibleReferenceID = 1; possibleReferenceID < id; possibleReferenceID++) { //for each node in the W last nodes seen, compute the proximity, i.e. the number of successors of the current node that also are successors of the possibleReference node. Pair<Pair<Integer, SortedSet<Integer>>, Pair<Integer, SortedSet<Integer>>> asl = uncompressAncestorsSuccessorsWithLayer( possibleReferenceID, true, true); if (asl.first().first() < L) { //System.out.println("step 1.1"); Pair<Pair<Integer, Integer>, String> nodesInCommonAncestor = commonNodes(asl.first().second(), ancestors);//from www . j a v a 2s. co m int numberOfOneAncestor = nodesInCommonAncestor.first().first(); int numberOfZeroAncestor = nodesInCommonAncestor.first().second(); int maxNumberOfOneAncestor = maxNodesInCommonAncestor.first(); int maxNumberOfZeroAncestor = maxNodesInCommonAncestor.second(); //System.out.println("step 2"); if (numberOfOneAncestor > maxNumberOfOneAncestor || (numberOfOneAncestor == maxNumberOfOneAncestor && numberOfZeroAncestor < maxNumberOfZeroAncestor)) { maxNodesInCommonAncestor = nodesInCommonAncestor.first(); bitlistAncestor = nodesInCommonAncestor.second(); referenceAncestor = possibleReferenceID; layerAncestor = asl.first().first() + 1; referenceAncestorList = asl.first().second(); //System.out.println("step 3"); } } //System.out.println("step 4"); if (asl.second().first() < L) { //System.out.println("step 4.1"); Pair<Pair<Integer, Integer>, String> nodesInCommonSuccessor = commonNodes(asl.second().second(), successors); int numberOfOneSuccessor = nodesInCommonSuccessor.first().first(); int numberOfZeroSuccessor = nodesInCommonSuccessor.first().second(); int maxNumberOfOneSuccessor = maxNodesInCommonSuccessor.first(); int maxNumberOfZeroSuccessor = maxNodesInCommonSuccessor.second(); if (numberOfOneSuccessor > maxNumberOfOneSuccessor || (numberOfOneSuccessor == maxNumberOfOneSuccessor && numberOfZeroSuccessor < maxNumberOfZeroSuccessor)) { maxNodesInCommonSuccessor = nodesInCommonSuccessor.first(); bitlistSuccessor = nodesInCommonSuccessor.second(); referenceSuccessor = possibleReferenceID; layerSuccessor = asl.second().first() + 1; referenceSuccessorList = asl.second().second(); } } //System.out.println("step 5"); } //System.out.println("step 6"); //encode ancestor list SortedSet<Integer> remainingNodesAncestor = new TreeSet<Integer>(); remainingNodesAncestor.addAll(ancestors); //encode reference //String encoding = id.toString() + " "; String encoding = layerAncestor + " "; if (maxNodesInCommonAncestor.first() > 0) { encoding = encoding + (referenceAncestor - id) + " " + bitlistAncestor + ""; //keep only remaining nodes remainingNodesAncestor.removeAll(referenceAncestorList); } else { encoding = encoding + "_"; } //encode consecutive nodes and delta encoding Integer previousNode = id; int countConsecutives = 0; for (Integer nodeID : remainingNodesAncestor) { Integer delta = nodeID - previousNode; if (delta == 1) { countConsecutives++; } else { if (countConsecutives > 0) { encoding = encoding + ":" + countConsecutives; countConsecutives = 1; } encoding = encoding + " " + delta; countConsecutives = 0; } previousNode = nodeID; } // encode successor list SortedSet<Integer> remainingNodesSuccessor = new TreeSet<Integer>(); remainingNodesSuccessor.addAll(successors); //encode reference encoding = encoding + " / " + layerSuccessor + " "; if (maxNodesInCommonSuccessor.first() > 0) { encoding = encoding + (referenceSuccessor - id) + " " + bitlistSuccessor + ""; //keep only remaining nodes remainingNodesSuccessor.removeAll(referenceSuccessorList); } else { encoding = encoding + "_ "; } //encode consecutive nodes and delta encoding previousNode = id; countConsecutives = 0; for (Integer nodeID : remainingNodesSuccessor) { Integer delta = nodeID - previousNode; if (delta == 1) { countConsecutives++; } else { if (countConsecutives > 0) { encoding = encoding + ":" + countConsecutives; countConsecutives = 1; } encoding = encoding + " " + delta; countConsecutives = 0; } previousNode = nodeID; } put(scaffoldWriter, id, encoding); //System.out.println(id + " " + encoding); return true; }
From source file:net.sourceforge.fenixedu.presentationTier.docs.academicAdministrativeOffice.ApprovementInfoForEquivalenceProcess.java
public static String getApprovementsInfo(final Registration registration) { final StringBuilder res = new StringBuilder(); final SortedSet<ICurriculumEntry> entries = new TreeSet<ICurriculumEntry>( ICurriculumEntry.COMPARATOR_BY_EXECUTION_PERIOD_AND_NAME_AND_ID); final Map<Unit, String> ids = new HashMap<Unit, String>(); if (registration.isBolonha()) { reportCycles(res, entries, ids, registration); } else {/*w w w.j a v a 2 s . co m*/ final ICurriculum curriculum = registration.getCurriculum(); filterEntries(entries, curriculum); reportEntries(res, entries, ids, registration); } entries.clear(); entries.addAll(getExtraCurricularEntriesToReport(registration)); if (!entries.isEmpty()) { reportRemainingEntries(res, entries, ids, registration.getLastStudentCurricularPlan().getExtraCurriculumGroup(), registration); } entries.clear(); entries.addAll(getPropaedeuticEntriesToReport(registration)); if (!entries.isEmpty()) { reportRemainingEntries(res, entries, ids, registration.getLastStudentCurricularPlan().getPropaedeuticCurriculumGroup(), registration); } res.append(getRemainingCreditsInfo(registration.getCurriculum())); res.append(LINE_BREAK); if (!ids.isEmpty()) { res.append(LINE_BREAK).append(getAcademicUnitInfo(ids)); } return res.toString(); }
From source file:org.deegree.tools.feature.gml.ApplicationSchemaTool.java
private static void createDDL(InputFormat inputFormat, String inputFileName, String dbSchema) throws JAXBException { switch (inputFormat) { case deegree_oracle: System.out.println("Not implemented yet."); break;/*from w w w .j a v a2 s .c om*/ case deegree_postgis: try { DefaultResourceLocation<FeatureStore> loc; ResourceIdentifier<FeatureStore> id = new DefaultResourceIdentifier<FeatureStore>( FeatureStoreProvider.class, "deegree_postgis"); loc = new DefaultResourceLocation<FeatureStore>(new File(inputFileName), id); Workspace ws = new DefaultWorkspace(new File("nix")); ws.initAll(); ws.add(loc); ws.prepare(id); SQLFeatureStore fs = (SQLFeatureStore) ws.init(id, null); String[] sql = DDLCreator.newInstance(fs.getSchema(), fs.getDialect()).getDDL(); for (String string : sql) { System.out.println(string + ";"); } } catch (ResourceInitException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case gml32: { try { List<String> inputURLs = new ArrayList<String>(); File inputFile = new File(inputFileName); if (!inputFile.exists()) { throw new IllegalArgumentException("Specified schema (directory) does not exist."); } if (inputFile.isDirectory()) { System.out.println("Specified input file is a directory -- scanning for .xsd files."); String[] inputFiles = inputFile.list(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".xsd"); } }); for (String file : inputFiles) { System.out.println("Adding '" + file + "'"); inputURLs.add(new URL(inputFile.toURI().toURL(), URLEncoder.encode(file, "UTF-8")) .toExternalForm()); } } else { inputURLs.add(inputFile.toURI().toURL().toExternalForm()); } GMLAppSchemaReader xsdDecoder = new GMLAppSchemaReader(GML_32, null, inputURLs.toArray(new String[inputURLs.size()])); AppSchema schema = xsdDecoder.extractAppSchema(); System.out.println("- Total feature types: " + schema.getFeatureTypes().length); System.out.println( "- Non-abstract feature types: " + schema.getFeatureTypes(null, true, false).size()); System.out.println("- Non-abstract feature types w/o collections: " + schema.getFeatureTypes(null, false, false).size()); SortedSet<FeatureType> sortedFts = new TreeSet<FeatureType>(new Comparator<FeatureType>() { @Override public int compare(FeatureType ft1, FeatureType ft2) { return ft1.getName().toString().compareTo(ft2.getName().toString()); } }); sortedFts.addAll(schema.getFeatureTypes(null, false, false)); int i = 0; for (FeatureType ft : sortedFts) { System.out.println( "INSERT INTO feature_types (id,qname) VALUES (" + i + ",'" + ft.getName() + "');"); i++; } break; } catch (Exception e) { e.printStackTrace(); } } default: { System.out.println( "Action " + Action.create_ddl + " is only supported for " + InputFormat.deegree_postgis.name() + " and " + InputFormat.deegree_oracle.name() + " input formats."); return; } } }
From source file:org.apache.sysml.utils.lite.BuildLite.java
/** * Consolidate the loaded classes and all the log4j classes and potentially * all the commons-math3 classes.//from ww w . ja va2 s . c o m * * @param loadedClasses * the loaded classes * @param log4jClassPathNames * the log4j class names * @param commonsMath3ClassPathNames * the commons-math3 class names * @return the set of unique class names that combines the loaded classes * and the log4j classes */ private static Set<String> consolidateClassPathNames(List<Class<?>> loadedClasses, List<String> log4jClassPathNames, List<String> commonsMath3ClassPathNames) { SortedSet<String> allClassPathNames = new TreeSet<>(log4jClassPathNames); if (includeAllCommonsMath3) { System.out.println( "\nConsolidating loaded class names, log4j class names, and commons-math3 class names"); allClassPathNames.addAll(commonsMath3ClassPathNames); } else { System.out.println("\nConsolidating loaded class names and log4j class names"); } for (Class<?> clazz : loadedClasses) { String loadedClassPathName = clazz.getName(); loadedClassPathName = loadedClassPathName.replace(".", "/"); loadedClassPathName = loadedClassPathName + ".class"; allClassPathNames.add(loadedClassPathName); } return allClassPathNames; }
From source file:org.opencastproject.runtimeinfo.RuntimeInfo.java
/** * Returns the array of references sorted by their {@link Constants.SERVICE_DESCRIPTION} property. * //from ww w . ja v a2 s . c o m * @param references * the referencens * @return the sorted set of references */ protected static SortedSet<ServiceReference> sort(ServiceReference[] references) { // Sort the service references SortedSet<ServiceReference> sortedServiceRefs = new TreeSet<ServiceReference>( new Comparator<ServiceReference>() { @Override public int compare(ServiceReference o1, ServiceReference o2) { String o1Description = (String) o1.getProperty(Constants.SERVICE_DESCRIPTION); if (StringUtils.isBlank(o1Description)) o1Description = o1.toString(); String o2Description = (String) o2.getProperty(Constants.SERVICE_DESCRIPTION); if (StringUtils.isBlank(o2Description)) o2Description = o2.toString(); return o1Description.compareTo(o2Description); } }); sortedServiceRefs.addAll(Arrays.asList(references)); return sortedServiceRefs; }
From source file:com.liangc.hq.base.utils.BizappUtils.java
public static List sortAppdefResourceType(List resourceType) { List sortedList = new ArrayList(); SortedSet sSet = new TreeSet(COMPARE_NAME); sSet.addAll(resourceType); CollectionUtils.addAll(sortedList, sSet.iterator()); return sortedList; }