List of usage examples for java.util TreeSet TreeSet
public TreeSet()
From source file:Main.java
public static <T> TreeSet<T> newTreeSet() { return new TreeSet<T>(); }
From source file:Main.java
private static Set<String> getTree(Node doc) { final Set<String> set = new TreeSet<String>(); if (doc == null) return set; String path = new String(); if (doc.getPrefix() != null && doc.getLocalName() != null) { path = new String(doc.getPrefix() + ":" + doc.getLocalName()); set.add(path);//from w ww. jav a 2 s.co m } final NamedNodeMap attributes = doc.getAttributes(); for (int i = 0; attributes != null && i < attributes.getLength(); i++) { final Node attribute = attributes.item(i); String name = attribute.getLocalName(); if (attribute.getPrefix() != null) name = attribute.getPrefix() + ":" + name; set.add(path + "/@" + name); } final NodeList nodes = doc.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { final Node node = nodes.item(i); if (node instanceof Element) { final Set<String> children = getTree(node); for (final String child : children) { set.add(path + "/" + child); } } } return set; }
From source file:Main.java
public static void sortDates(final List<DAY> dayList) { final Set<DAY> set = new TreeSet<DAY>(); set.addAll(dayList);/*from ww w.j a v a2 s . c o m*/ for (final DAY day : set) { System.out.println(day); } }
From source file:edu.ucdenver.ccp.nlp.ae.dict_util.OboToDictionary.java
public static void main(String args[]) { BasicConfigurator.configure();/*from www . ja v a 2 s. c o m*/ if (args.length < 2) { usage(); } else { try { File oboFile = new File(args[0]); File outputFile = new File(args[1]); String namespaceName = ""; if (args.length > 2) { namespaceName = args[2]; } if (!oboFile.canRead()) { System.out.println("can't read input file;" + oboFile.getAbsolutePath()); usage(); System.exit(-2); } if (outputFile.exists() && !outputFile.canWrite()) { System.out.println("can't write output file;" + outputFile.getAbsolutePath()); usage(); System.exit(-3); } logger.warn("running with: " + oboFile.getAbsolutePath()); OboToDictionary converter = null; if (namespaceName != null && namespaceName.length() > 0) { Set<String> namespaceSet = new TreeSet<String>(); namespaceSet.add(namespaceName); converter = new OboToDictionary(true, SynonymType.EXACT_ONLY, namespaceSet); } else { converter = new OboToDictionary(); } converter.convert(oboFile, outputFile); } catch (Exception e) { System.out.println("error:" + e); e.printStackTrace(); System.exit(-1); } } }
From source file:Main.java
public static <K, V> void addToMap(K key, V value, Map<K, Set<V>> map) { if (key != null && value != null) if (map.containsKey(key)) map.get(key).add(value);/*from w w w.j a va 2 s . co m*/ else { Set<V> values = new TreeSet<V>(); values.add(value); map.put(key, values); } }
From source file:Main.java
/** * Constructs a SortedSet<T> with all the elements available from i * @param i an iterator to pull elements from * @param <T> The type of the elements * @return a SortedSet of the elements//from www . ja v a 2s. c o m */ public static <T> SortedSet<T> sortedSetFromIterator(Iterator<T> i) { SortedSet<T> retval = new TreeSet<T>(); while (i.hasNext()) retval.add(i.next()); return retval; }
From source file:Set2.java
public static void test(Set a) { fill(a, 10);// w w w . j a v a 2s . c o m fill(a, 10); // Try to add duplicates fill(a, 10); a.addAll(fill(new TreeSet(), 10)); System.out.println(a); }
From source file:Main.java
public static List sortedUnion(List args1, List args2) { SortedSet set = new TreeSet(); set.addAll(args1);//w ww.j av a 2 s .c om set.addAll(args2); List lst = new ArrayList(set.size()); for (Iterator it = set.iterator(); it.hasNext();) { Object o = it.next(); lst.add(o); } return lst; }
From source file:Main.java
private static boolean levelExist(int level) { if (mLevelSet == null) mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET, null);//ww w .jav a2s .c o m if (mLevelSet == null) { mLevelSet = new TreeSet<String>(); mLevelSet.add(String.valueOf(level)); mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_WRITEABLE).edit() .putStringSet(LEVELSET, mLevelSet).commit(); return false; } if (mLevelSet.contains(String.valueOf(level))) return true; else { mLevelSet.add(String.valueOf(level)); mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_WRITEABLE).edit() .putStringSet(LEVELSET, mLevelSet).commit(); } return false; }
From source file:Main.java
/** * Given any of the known collection types, this method will return an instance of the collection. * @param collectionType the type of the collection * @return the collection instance// w w w .j a v a 2 s . com */ public static Collection<?> getCollection(Class<?> collectionType) { if (HashSet.class.equals(collectionType)) { return new HashSet<Object>(); } else if (TreeSet.class.equals(collectionType)) { return new TreeSet<Object>(); } else if (CopyOnWriteArraySet.class.equals(collectionType)) { return new CopyOnWriteArraySet<Object>(); } else if (LinkedHashSet.class.equals(collectionType)) { return new LinkedHashSet<Object>(); } else if (ArrayList.class.equals(collectionType)) { return new ArrayList<Object>(); } else if (LinkedList.class.equals(collectionType)) { return new LinkedList<Object>(); } else if (Vector.class.equals(collectionType)) { return new Vector<Object>(); } else if (Stack.class.equals(collectionType)) { return new Stack<Object>(); } else if (PriorityQueue.class.equals(collectionType)) { return new PriorityQueue<Object>(); } else if (PriorityBlockingQueue.class.equals(collectionType)) { return new PriorityBlockingQueue<Object>(); } else if (ArrayDeque.class.equals(collectionType)) { return new ArrayDeque<Object>(); } else if (ConcurrentLinkedQueue.class.equals(collectionType)) { return new ConcurrentLinkedQueue<Object>(); } else if (LinkedBlockingQueue.class.equals(collectionType)) { return new LinkedBlockingQueue<Object>(); } else if (LinkedBlockingDeque.class.equals(collectionType)) { return new LinkedBlockingDeque<Object>(); } else if (List.class.equals(collectionType)) { return new LinkedList<Object>(); } else if (Set.class.equals(collectionType)) { return new HashSet<Object>(); } else if (Queue.class.equals(collectionType)) { return new PriorityQueue<Object>(); } else if (Deque.class.equals(collectionType)) { return new ArrayDeque<Object>(); } else if (Collection.class.equals(collectionType)) { return new LinkedList<Object>(); } throw new IllegalArgumentException("Unsupported collection type: " + collectionType); }