Java Code Examples for java.util.SortedSet#subSet()
The following examples show how to use
java.util.SortedSet#subSet() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntSortedSetTest.java From JSAT with GNU General Public License v3.0 | 6 votes |
private void testSubSet(SortedSet<Integer> groundTruth, SortedSet<Integer> testSet, Random rand, int depth) { if(groundTruth.isEmpty() || groundTruth.last() - groundTruth.first() <= 0)//avoid bad tests return; int fromElement = groundTruth.first() + rand.nextInt(groundTruth.last() - groundTruth.first()); int toElement = fromElement + rand.nextInt(groundTruth.last() - fromElement); SortedSet<Integer> g_s = groundTruth.subSet(fromElement, toElement); SortedSet<Integer> t_s = testSet.subSet(fromElement, toElement); assertSameContent(g_s, t_s); for(int i = 0; i < 5; i++) { if(fromElement == toElement) continue;//we can't add anything int new_val = fromElement+rand.nextInt(toElement-fromElement); g_s.add(new_val); t_s.add(new_val); } assertSameContent(g_s, t_s); assertSameContent(groundTruth, testSet); if(depth-- > 0) testSubSet(g_s, t_s, rand, depth); assertSameContent(groundTruth, testSet); }
Example 2
Source File: AccumuloOperations.java From geowave with Apache License 2.0 | 6 votes |
/** */ @Override public void deleteAll() throws Exception { SortedSet<String> tableNames = connector.tableOperations().list(); if ((tableNamespace != null) && !tableNamespace.isEmpty()) { tableNames = tableNames.subSet(tableNamespace, tableNamespace + '\uffff'); } for (final String tableName : tableNames) { connector.tableOperations().delete(tableName); } DataAdapterAndIndexCache.getInstance( RowMergingAdapterOptionProvider.ROW_MERGING_ADAPTER_CACHE_ID, tableNamespace, AccumuloStoreFactoryFamily.TYPE).deleteAll(); locGrpCache.clear(); ensuredAuthorizationCache.clear(); ensuredPartitionCache.clear(); }
Example 3
Source File: WhenUsingTreeSet.java From tutorials with MIT License | 6 votes |
@Test public void whenUsingSubSet_shouldReturnSubSetElements() { SortedSet<Integer> treeSet = new TreeSet<>(); treeSet.add(1); treeSet.add(2); treeSet.add(3); treeSet.add(4); treeSet.add(5); treeSet.add(6); Set<Integer> expectedSet = new TreeSet<>(); expectedSet.add(2); expectedSet.add(3); expectedSet.add(4); expectedSet.add(5); Set<Integer> subSet = treeSet.subSet(2, 6); Assert.assertEquals(expectedSet, subSet); }
Example 4
Source File: QuetzalSummary.java From CostFed with GNU Affero General Public License v3.0 | 5 votes |
static Set<String> getCut(SortedSet<String> coll, String[] arr, String pattern) { int startpos = Arrays.binarySearch(arr, pattern); if (startpos == -1 || (startpos < 0 && !pattern.startsWith(arr[-startpos - 2]))) return new TreeSet<String>(); if (startpos < 0) { startpos = -startpos - 2; } int endpos = Arrays.binarySearch(arr, startpos, arr.length, pattern + Character.MAX_VALUE); assert(endpos < 0); endpos = -endpos - 1; return endpos == arr.length ? coll.tailSet(arr[startpos]) : coll.subSet(arr[startpos], arr[endpos]); }
Example 5
Source File: TreeSetRange.java From learntosolveit with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void main(String[] args) { SortedSet<String> filenames = new TreeSet<String>(); File cwd = new File("."); for(File f: cwd.listFiles()) filenames.add(f.getName()); for(String filename: filenames.subSet("P", "T")) System.out.println(filename); }
Example 6
Source File: UnmodSortedSetTest.java From Paguro with Apache License 2.0 | 4 votes |
@Override public UnmodSortedSet<E> subSet(E fromElement, E toElement) { SortedSet<E> next = dup(inner); return new TestSortSet<>(next.subSet(fromElement, toElement), inner.comparator()); }
Example 7
Source File: ImSortedSetTest.java From Paguro with Apache License 2.0 | 4 votes |
@Override public ImSortedSet<T> subSet(T fromElement, T toElement) { SortedSet<T> next = dup(inner); return new TestSortSet<>(next.subSet(fromElement, toElement), inner.comparator()); }