List of usage examples for java.util TreeSet TreeSet
public TreeSet(SortedSet<E> s)
From source file:Main.java
public static <T> Set<T> toTreeSet(Collection<T> collection, Comparator<T> comparator) { final Set<T> treeSet = new TreeSet<>(comparator); for (T t : collection) { treeSet.add(t);//from ww w . j ava2s . c o m } return treeSet; }
From source file:Main.java
private static boolean isList(Map temp) { Set s = new TreeSet(temp.keySet()); Object[] keyArray = s.toArray(new Object[] {}); for (int i = 0; i < keyArray.length; i++) { if (keyArray[i] instanceof Number) { if (((Number) keyArray[i]).intValue() != i) { return false; }//from ww w .j a va2 s.co m } else { return false; } } return true; }
From source file:Main.java
public static <T> TreeSet<T> toTreeSet(Collection<T> collection, Comparator<T> comparator) { final TreeSet<T> treeSet = new TreeSet<T>(comparator); for (T t : collection) { treeSet.add(t);/*from w w w. j ava2 s. c om*/ } return treeSet; }
From source file:Main.java
public static SortedSet reverseSortedSet(int[] ints) { TreeSet sortedSet = new TreeSet(Collections.reverseOrder()); for (int i = 0; i < ints.length; i++) { sortedSet.add(new Integer(ints[i])); }// www .ja v a 2 s. co m return sortedSet; }
From source file:Main.java
public static <K, V extends Comparable<? super V>> SortedSet<Map.Entry<K, V>> sortByValues(Map<K, V> map) { SortedSet<Map.Entry<K, V>> sortedEntries = new TreeSet<>((e1, e2) -> { int res = e1.getValue().compareTo(e2.getValue()); return res != 0 ? res : 1; });/* w w w . j a va 2 s .co m*/ sortedEntries.addAll(map.entrySet()); return sortedEntries; }
From source file:Main.java
public static void bindValores(SQLiteStatement statement, ContentValues contentValues) { Set<String> chaves = new TreeSet<>(contentValues.keySet()); int index = 1; for (String chave : chaves) { Object valor = contentValues.get(chave); if (valor == null) { statement.bindNull(index);/*from w w w . j ava2 s. c om*/ } else if (valor instanceof String) { statement.bindString(index, (String) valor); } else if (valor instanceof Double || valor instanceof Float) { statement.bindDouble(index, Double.valueOf(String.valueOf(valor))); } else if (valor instanceof Integer || valor instanceof Long) { statement.bindLong(index, Long.valueOf(String.valueOf(valor))); } else if (valor instanceof byte[]) { statement.bindBlob(index, (byte[]) valor); } index++; } }
From source file:Main.java
public static String[] clean(String[] input) { Set<String> unique = new TreeSet<>(Arrays.asList(input)); return unique.toArray(new String[unique.size()]); }
From source file:Main.java
/** * Constructs the sorted union of two sets * @param a//from w w w . j a v a 2s . c om * @param b * @return the sorted union */ public static <T> SortedSet<T> sortedUnion(Set<T> a, Set<T> b) { SortedSet<T> retVal = new TreeSet<T>(a); retVal.addAll(b); return retVal; }
From source file:Main.java
public static <E> TreeSet<E> getTreeSet(Collection<? extends E> collection) { return new TreeSet<E>(collection); }
From source file:Main.java
public static <K, V extends Comparable<? super V>> SortedSet<Entry<K, V>> sortMapByValueAsc(Map<K, V> map) { SortedSet<Entry<K, V>> sorted = new TreeSet<>(new Comparator<Entry<K, V>>() { @Override/* w w w .j a va 2 s . co m*/ public int compare(Entry<K, V> e1, Entry<K, V> e2) { int r = e1.getValue().compareTo(e2.getValue()); return r == 0 ? 1 : r; } }); for (Entry<K, V> entry : map.entrySet()) sorted.add(new SimpleEntry(entry)); return sorted; }