Java Code Examples for java.util.TreeSet#descendingSet()

The following examples show how to use java.util.TreeSet#descendingSet() . 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: OverseerTaskQueue.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 *
 * Gets last element of the Queue without removing it.
 */
public String getTailId() throws KeeperException, InterruptedException {
  // TODO: could we use getChildren here?  Unsure what freshness guarantee the caller needs.
  TreeSet<String> orderedChildren = fetchZkChildren(null);

  for (String headNode : orderedChildren.descendingSet())
    if (headNode != null) {
      try {
        QueueEvent queueEvent = new QueueEvent(dir + "/" + headNode, zookeeper.getData(dir + "/" + headNode,
            null, null, true), null);
        return queueEvent.getId();
      } catch (KeeperException.NoNodeException e) {
        // Another client removed the node first, try next
      }
    }
  return null;
}
 
Example 2
Source File: TreeSetTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Test that TreeSet never attempts to serialize a non-serializable
 * comparator. http://b/5552608
 */
public void testDescendingSetSerialization() {
    String s = "aced0005737200116a6176612e7574696c2e54726565536574dd98509395ed87"
            + "5b0300007870737200276a6176612e7574696c2e436f6c6c656374696f6e73245"
            + "2657665727365436f6d70617261746f7264048af0534e4ad00200007870770400"
            + "000002740001627400016178";
    TreeSet<String> set = new TreeSet<String>();
    set.add("a");
    set.add("b");
    NavigableSet<String> descendingSet = set.descendingSet();
    new SerializationTester<NavigableSet<String>>(descendingSet, s) {
        @Override protected void verify(NavigableSet<String> deserialized) {
            assertEquals("b", deserialized.first());
        }
    }.test();
}
 
Example 3
Source File: TreeSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private NavigableSet dset5() {
    TreeSet q = new TreeSet();
    assertTrue(q.isEmpty());
    q.add(m1);
    q.add(m2);
    q.add(m3);
    q.add(m4);
    q.add(m5);
    NavigableSet s = q.descendingSet();
    assertEquals(5, s.size());
    return s;
}
 
Example 4
Source File: RowDataPacketGrouper.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
private void mergAvg(RowDataPacket toRow) {
		if (mergCols == null) {
			return;
		}
		
		

		TreeSet<Integer> rmIndexSet = new TreeSet<Integer>();
		for (MergeCol merg : mergCols) {
			if(merg.mergeType==MergeCol.MERGE_AVG)
			{
				byte[] result = mertFields(
						toRow.fieldValues.get(merg.colMeta.avgSumIndex),
						toRow.fieldValues.get(merg.colMeta.avgCountIndex),
						merg.colMeta.colType, merg.mergeType);
				if (result != null)
				{
					toRow.fieldValues.set(merg.colMeta.avgSumIndex, result);
//					toRow.fieldValues.remove(merg.colMeta.avgCountIndex) ;
//					toRow.fieldCount=toRow.fieldCount-1;
					rmIndexSet.add(merg.colMeta.avgCountIndex);
				}
			}
		}
		// remove by index from large to small, to make sure each element deleted correctly
		for(int index : rmIndexSet.descendingSet()) {
			toRow.fieldValues.remove(index);
			toRow.fieldCount = toRow.fieldCount - 1;
		}


	}
 
Example 5
Source File: MapTaskExecutionDao.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Override
public Page<TaskExecution> findAll(Pageable pageable) {
	TreeSet<TaskExecution> sortedSet = getTaskExecutionTreeSet();
	sortedSet.addAll(this.taskExecutions.values());
	List<TaskExecution> result = new ArrayList<>(sortedSet.descendingSet());
	return getPageFromList(result, pageable, getTaskExecutionCount());
}
 
Example 6
Source File: TreeSubSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private NavigableSet dset5() {
    TreeSet q = new TreeSet();
    assertTrue(q.isEmpty());
    q.add(m1);
    q.add(m2);
    q.add(m3);
    q.add(m4);
    q.add(m5);
    NavigableSet s = q.descendingSet();
    assertEquals(5, s.size());
    return s;
}
 
Example 7
Source File: Histogram.java    From bluima with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    TreeSet<T> ordered = new TreeSet<T>(map.keySet());
    StringBuilder sb = new StringBuilder();
    sb.append("cnt\tkey\n");
    for (T key : ordered.descendingSet()) {
        sb.append(map.get(key) + "\t" + key + "\n"); // count tab entry
    }
    return sb.toString();
}