TreeSet last - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for TreeSet last method.

This code example shows how to use the following methods:add, first, isEmpty, last
	/** 
	 * @tests java.util.TreeSet#TreeSet(java.util.Comparator) 
	 */ 
	public void test_ConstructorLjava_util_Comparator() { 
		// Test for method java.util.TreeSet(java.util.Comparator) 
		TreeSet myTreeSet = new TreeSet(new ReversedIntegerComparator());
		assertTrue("Did not construct correct TreeSet", myTreeSet.isEmpty());
		myTreeSet.add(new Integer(1));
		myTreeSet.add(new Integer(2));
		assertTrue(
				"Answered incorrect first element--did not use custom comparator ", 
				myTreeSet.first().equals(new Integer(2)));
		assertTrue(
				"Answered incorrect last element--did not use custom comparator ", 
				myTreeSet.last().equals(new Integer(1)));
	} 
 
	/** 
	 * @tests java.util.TreeSet#TreeSet(java.util.SortedSet) 
	 */ 
6
CodeRank
This code example shows how to use the following methods:add, last, remove, size
        this.size = size;
        set = new TreeSet<E>();
    } 
 
    public void add(E e) {
        set.add(e);
        if (set.size() > size) {
            set.remove(set.last());
        } 
    } 
 
    public Iterator<E> iterator() {
        return set.iterator();
    } 
 
    public static void main(String[] args) {
        FixedSizeHeap<Integer> heap = new FixedSizeHeap<Integer>(3);
        heap.add(10);
        heap.add(20);
        heap.add(5);
6
CodeRank
This code example shows how to use the following methods:add, last, remove, size
        list = new TreeSet<PortalRequestTrace>( new PortalRequestTraceComparatorByLongestTime() );
    } 
 
    public synchronized void add( PortalRequestTrace item )
    { 
        list.add( item );
        doRetainSize(); 
    } 
 
    public synchronized List<PortalRequestTrace> getList()
    { 
        return ImmutableList.copyOf( list );
    } 
 
    private void doRetainSize() 
    { 
        if ( list.size() > maxSize )
        { 
            list.remove( list.last() );
        } 

6
CodeRank
This code example shows how to use the following methods:add, first, last
     
    String tableName = tableNames.get(rand.nextInt(tableNames.size()));
     
    // TODO need to sometimes do null start and end ranges 
     
    TreeSet<Text> range = new TreeSet<Text>();
    range.add(new Text(String.format("%016x", Math.abs(rand.nextLong()))));
    range.add(new Text(String.format("%016x", Math.abs(rand.nextLong()))));
     
    try { 
      conn.tableOperations().merge(tableName, range.first(), range.last());
      log.debug("merged " + tableName);
    } catch (TableOfflineException toe) {
      log.debug("merge " + tableName + " failed, table is not online");
    } catch (TableNotFoundException tne) {
      log.debug("merge " + tableName + " failed, doesnt exist");
    } 
     
  } 
} 
6
CodeRank
This code example shows how to use the following methods:add, first, last
     
    String tableName = tableNames.get(rand.nextInt(tableNames.size()));
     
    // TODO need to sometimes do null start and end ranges 
     
    TreeSet<Text> range = new TreeSet<Text>();
    range.add(new Text(String.format("%016x", Math.abs(rand.nextLong()))));
    range.add(new Text(String.format("%016x", Math.abs(rand.nextLong()))));
     
    try { 
      boolean wait = rand.nextBoolean();
      conn.tableOperations().compact(tableName, range.first(), range.last(), false, wait);
      log.debug((wait ? "compacted " : "initiated compaction ") + tableName);
    } catch (TableNotFoundException tne) {
      log.debug("compact " + tableName + " failed, doesnt exist");
    } catch (TableOfflineException toe) {
      log.debug("compact " + tableName + " failed, offline");
    } 
     
  } 
6
CodeRank
This code example shows how to use the following methods:last
        // When running InVM we will have con:0 and externally con:1 
 
        HashMap<Integer, List<String>> connectionData = splitResultsOnConnectionID(results);
 
        // Get the last Integer from keySet of the ConnectionData 
        int connectionID = new TreeSet<Integer>(connectionData.keySet()).last();
 
        //Use just the data from the last connection for the test 
        results = connectionData.get(connectionID);
 
        // If we are running inVM or with 0-10 we will get three open messagse 
	    // if running externally with 0-8/0-9 we will also have open and close messages from the failed 0-10 negotiation  
	    assertTrue("CON messages not logged:" + results.size(), results.size() >= 3);
 
        String log = getLogMessage(results, 0);
        //  MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open 
        //1 & 2 
        validateMessageID("CON-1001",log);
 
        // validate the last three CON- messages. 
5
CodeRank
This code example shows how to use the following methods:last
        // When running InVM we will have con:0 and externally con:1 
 
        HashMap<Integer, List<String>> connectionData = splitResultsOnConnectionID(results);
 
        // Get the last Integer from keySet of the ConnectionData 
        int connectionID = new TreeSet<Integer>(connectionData.keySet()).last();
 
        //Use just the data from the last connection for the test 
        results = connectionData.get(connectionID);
 
        // If we are running inVM or with 0-10 we will get three open messagse 
	    // if running externally with 0-8/0-9 we will also have open and close messages from the failed 0-10 negotiation  
	    assertTrue("CON messages not logged:" + results.size(), results.size() >= 3);
 
        String log = getLogMessage(results, 0);
        //  MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open 
        //1 & 2 
        validateMessageID("CON-1001",log);
 
        // validate the last three CON- messages. 
5
CodeRank
This code example shows how to use the following methods:last
    public void test_last() { 
        // Test for method java.lang.Object java.util.TreeSet.last() 
        assertTrue("Returned incorrect last element",
                ts.last() == objArray[objArray.length - 1]);
 
        ts = new TreeSet();
        try { 
            ts.last();
            fail("NoSuchElementException expected");
        } catch (NoSuchElementException e) {
            //expected 
        } 
    } 
 
    public void test_subSetLjava_lang_ObjectLjava_lang_Object() { 
        // Test for method java.util.SortedSet 
        // java.util.TreeSet.subSet(java.lang.Object, java.lang.Object) 
        final int startPos = objArray.length / 4;
        final int endPos = 3 * objArray.length / 4;
        SortedSet aSubSet = ts.subSet(objArray[startPos], objArray[endPos]);
5
CodeRank
This code example shows how to use the following methods:last
        // MESSAGE [con:0(/127.0.0.1:46927)] CON-1002 : Close 
 
        HashMap<Integer, List<String>> connectionData = splitResultsOnConnectionID(results);
 
        // Get the last Integer from keySet of the ConnectionData 
        int connectionID = new TreeSet<Integer>(connectionData.keySet()).last();
 
        //Use just the data from the last connection for the test 
        results = connectionData.get(connectionID);
 
	    assertEquals("Unexpected CON-1001 messages count", 3, results.size());
 
        String log = getLogMessage(results, 0);
        //  MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open 
        //1 & 2 
        validateMessageID("CON-1001",log);
 
        // validate the last three CON-1001 messages. 
        //  MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open : Client ID : clientid : Protocol Version : 0-9 : Client Version : 1.2.3_4 : Client Product : product 
        validateConnectionOpen(results, 0, true, true, clientid, true, QpidProperties.getReleaseVersion(), true, QpidProperties.getProductName());
5
CodeRank
This code example shows how to use the following methods:first, last
    public void addColorAt(float p, ReadonlyTColor c) {
        gradient.add(new GradPoint(p, c));
    } 
 
    public ColorList calcGradient() { 
        float start = gradient.first().getPosition();
        return calcGradient(start,
                (int) (gradient.last().getPosition() - start));
    } 
 
    /** 
     * Calculates the gradient from specified position. 
     *  
     * @param pos 
     * @param width 
     * @return list of interpolated gradient colors 
     */ 
    public ColorList calcGradient(float pos, int width) {
        ColorList result = new ColorList();
 
5
CodeRank
last Method Overview
Returns the last (highest) element currently in this set.
See Code Examples for other Java 8 TreeSet Methods: