SortedSet first - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:isEmpty, first, tailSet
    if(confException != null) {
      LOG.error(confException.getMessage(), confException);
      return -1; 
    } 
 
    if(tabletInfoSet.isEmpty()) {
      LOG.error("tablet partition size is zero");
      return -1; 
    } 
    int partitionNumber = 0;
    Row.Key rowKey = new Row.Key(key.toString());
     
    SortedSet<RowKeyItem> tailSet = tabletInfoSet.tailSet(new RowKeyItem(rowKey, 0));
    if(!tailSet.isEmpty()) {
      partitionNumber = tailSet.first().index;
    } else { 
      partitionNumber = tabletInfoSet.last().index;
    } 
     
    if(partitionNumber >= numPartitions) {
7
CodeRank
This code example shows how to use the following methods:isEmpty, first
     *        whether the value being retrieved should be percent decoded 
     * @return the first value found for this parameter 
     */ 
    public String getFirst(Object key, boolean percentDecode) {
        SortedSet<String> values = wrappedMap.get(key);
        if (values == null || values.isEmpty()) {
            return null; 
        } 
        String value = values.first();
        return percentDecode ? OAuth.percentDecode(value) : value;
    } 
 
    /** 
     * Concatenates all values for the given key to a list of key/value pairs 
     * suitable for use in a URL query string. 
     *  
     * @param key 
     *        the parameter name 
     * @return the query string 
     */ 
6
CodeRank
This code example shows how to use the following methods:add, isEmpty, remove, first
    assertEquals(0, new VersionString("3.0").compareTo(new VersionString("3")));
    assertEquals(+1, new VersionString("1.8.11").compareTo(new VersionString("1.8")));
  } 
 
  public void testSorting() throws Exception { 
    SortedSet<VersionString> set = new TreeSet<VersionString>();
    set.add(v3);
    set.add(v0);
    set.add(v1);
    set.add(v4);
    set.add(v2);
    assertEquals(v0, set.first());
    assertTrue(set.remove(v0));
    assertEquals(v1, set.first());
    assertTrue(set.remove(v1));
    assertEquals(v2, set.first());
    assertTrue(set.remove(v2));
    assertEquals(v3, set.first());
    assertTrue(set.remove(v3));
    assertEquals(v4, set.first());

6
CodeRank
This code example shows how to use the following methods:first
    return internalSet.tailSet(fromElement);
  } 
 
  @Override 
  public E first() { 
    return internalSet.first();
  } 
 
  @Override 
  public E last() { 
    return internalSet.last();
  } 
} 
6
CodeRank
This code example shows how to use the following methods:size, first, last
    ob.addAsk(new OrderbookOrder(-3.3, 24.0))
      .addAsk(new OrderbookOrder(-2.1, 20.2)) 
      .addAsk(new OrderbookOrder(-5.6, 22.4)) 
      .addAsk(new OrderbookOrder(-6.2, null)); 
    SortedSet<OrderbookOrder> asks = ob.getAsks();
    assertEquals("correct number", 4, asks.size());
    assertEquals("no bids", 0, ob.getBids().size());
    assertNull("correct first", asks.first().getLimitPrice());
    assertEquals("correct last", 24.0, asks.last().getLimitPrice(), 1e-6);
  } 
 
  @Test 
  public void xmlSerializationTest () 
  { 
    Orderbook ob1 = new Orderbook(timeslot, 22.1, now)
      .addBid(new OrderbookOrder(3.3, -20.0)) 
      .addBid(new OrderbookOrder(2.1, -18.2)) 
      .addBid(new OrderbookOrder(5.6, -19.4)) 
      .addBid(new OrderbookOrder(6.2, null)) 
      .addAsk(new OrderbookOrder(-3.1, 23.4)); 
6
CodeRank
This code example shows how to use the following methods:add, remove, first
This code example shows how to use the following methods:comparator, first, headSet, last, subSet
 
  public void testSortedKeySet() { 
    TreeMultimap<String, Integer> multimap = createPopulate();
    SortedSet<String> keySet = multimap.keySet();
 
    assertEquals(null, keySet.first());
    assertEquals("google", keySet.last());
    assertEquals(StringLength.COMPARATOR, keySet.comparator());
    assertEquals(Sets.newHashSet(null, "tree"), keySet.headSet("yahoo"));
    assertEquals(Sets.newHashSet("google"), keySet.tailSet("yahoo"));
    assertEquals(Sets.newHashSet("tree"), keySet.subSet("ask", "yahoo"));
  } 
 
  @GwtIncompatible("SerializableTester") 
  public void testExplicitComparatorSerialization() { 
    TreeMultimap<String, Integer> multimap = createPopulate();
    TreeMultimap<String, Integer> copy
        = SerializableTester.reserializeAndAssert(multimap);
    ASSERT.that(copy.values()).hasContentsInOrder(7, 3, 1, null, 0, 6, 2);
    ASSERT.that(copy.keySet()).hasContentsInOrder(null, "tree", "google");
6
CodeRank
This code example shows how to use the following methods:isEmpty, first
        return SortedSetAdapter.adapt(this.delegate.tailSet(fromElement));
    } 
 
    public T first() 
    { 
        if (this.delegate.isEmpty())
        { 
            throw new NoSuchElementException();
        } 
        return this.delegate.first();
    } 
 
    public T last() 
    { 
        if (this.delegate.isEmpty())
        { 
            throw new NoSuchElementException();
        } 
        return this.delegate.last();
    } 
6
CodeRank
This code example shows how to use the following methods:isEmpty, first
     *        whether the value being retrieved should be percent decoded 
     * @return the first value found for this parameter 
     */ 
    public String getFirst(Object key, boolean percentDecode) {
        SortedSet<String> values = wrappedMap.get(key);
        if (values == null || values.isEmpty()) {
            return null; 
        } 
        String value = values.first();
        return percentDecode ? OAuth.percentDecode(value) : value;
    } 
 
    /** 
     * Concatenates all values for the given key to a list of key/value pairs 
     * suitable for use in a URL query string. 
     *  
     * @param key 
     *        the parameter name 
     * @return the query string 
     */ 
6
CodeRank
This code example shows how to use the following methods:add, first, last
		assertEquals(20120405135316L, mFailed.getId()); 
	} 
 
	@Test 
	public void testCompareToInOrder() { 
		SortedSet<IBuild> treeSet = new TreeSet<IBuild>(); 
		treeSet.add(mGood); 
		treeSet.add(mFailed); 
		 
		assertEquals(mGood,treeSet.first()); 
		assertEquals(mFailed,treeSet.last()); 
 
	} 
 
	@Test 
	public void testCompareToOutOffOrder() { 
		SortedSet<IBuild> treeSet = new TreeSet<IBuild>(); 
		treeSet.add(mFailed);  
		treeSet.add(mGood); 
		 
6
CodeRank
first Method Overview
Returns the first (lowest) element currently in this set.
See Code Examples for other Java 8 SortedSet Methods: