TreeSet comparator - 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 comparator method.

This code example shows how to use the following methods:comparator
    return new TreeSet((Comparator) streamReader.readObject());
  } 
 
  public static void serialize(SerializationStreamWriter streamWriter,
      TreeSet instance) throws SerializationException {
    streamWriter.writeObject(instance.comparator());
    Collection_CustomFieldSerializerBase.serialize(streamWriter, instance);
  } 
 
  @Override 
  public void deserializeInstance(SerializationStreamReader streamReader,
      TreeSet instance) throws SerializationException {
    deserialize(streamReader, instance);
  } 
 
  @Override 
  public boolean hasCustomInstantiateInstance() { 
    return true; 
  } 
 
5
CodeRank
This code example shows how to use the following methods:comparator
   @Override 
   public void writeObject(ObjectOutput output, Set set) throws IOException {
      int number = numbers.get(set.getClass(), -1);
      output.writeByte(number);
      if (number == TREE_SET)
         output.writeObject(((TreeSet) set).comparator());
 
      MarshallUtil.marshallCollection(set, output);
   } 
 
   @Override 
   public Set readObject(ObjectInput input) throws IOException, ClassNotFoundException {
      int magicNumber = input.readUnsignedByte();
      Set<Object> subject = null;
      switch (magicNumber) {
         case HASH_SET:
            subject = new HashSet();
            break; 
         case TREE_SET:
            Comparator comparator = (Comparator) input.readObject();
5
CodeRank
This code example shows how to use the following methods:comparator
   * Test method for 'java.util.TreeSet.TreeSet(Comparator)'. 
   *  
   * @see java.util.TreeSet#TreeSet(Comparator) 
   */ 
  public void testConstructor_comparator() { 
    TreeSet<E> TreeSet = new TreeSet<E>(getComparator());
    _assertEmpty(TreeSet);
    if (isNaturalOrder()) { 
      assertNull(TreeSet.comparator());
    } else { 
      assertSame(getComparator(), TreeSet.comparator());
    } 
  } 
 
  /** 
   * Test method for 'java.util.TreeSet.TreeSet(Set)'. 
   *  
   * @see java.util.TreeSet#TreeSet(Set) 
   */ 
  public void testConstructor_Set() { 
5
CodeRank
This code example shows how to use the following methods:comparator
        return (Set<E>) _treeSet.clone();
    } 
 
    @Override 
    public IImmutableSortedSet<E> immutableCopy() { 
        return ImmutableSortedSet.copyOf( _treeSet.comparator(), _treeSet );
    } 
 
    @Override 
    public Comparator<? super E> comparator() {
        return _treeSet.comparator();
    } 
 
    @Override 
    public E first() { 
        return _treeSet.first();
    } 
 
    @Override 
    public IMutableSortedSetView<E> headSet( final E toElement ) {
5
CodeRank
This code example shows how to use the following methods:comparator
	 * @tests java.util.TreeSet#comparator() 
	 */ 
	public void test_comparator() { 
		// Test for method java.util.Comparator java.util.TreeSet.comparator() 
		ReversedIntegerComparator comp = new ReversedIntegerComparator();
		TreeSet myTreeSet = new TreeSet(comp);
		assertTrue("Answered incorrect comparator",
				myTreeSet.comparator() == comp);
	} 
 
	/** 
	 * @tests java.util.TreeSet#contains(java.lang.Object) 
	 */ 
	public void test_containsLjava_lang_Object() { 
		// Test for method boolean java.util.TreeSet.contains(java.lang.Object) 
		assertTrue("Returned false for valid Object", ts
				.contains(objArray[objArray.length / 2]));
		assertTrue("Returned true for invalid Object", !ts
				.contains(new Integer(-9)));
		try { 
5
CodeRank
This code example shows how to use the following methods:comparator
    return new TreeSet((Comparator) streamReader.readObject());
  } 
 
  public static void serialize(SerializationStreamWriter streamWriter,
      TreeSet instance) throws SerializationException {
    streamWriter.writeObject(instance.comparator());
    Collection_CustomFieldSerializerBase.serialize(streamWriter, instance);
  } 
 
  @Override 
  public void deserializeInstance(SerializationStreamReader streamReader,
      TreeSet instance) throws SerializationException {
    deserialize(streamReader, instance);
  } 
 
  @Override 
  public boolean hasCustomInstantiateInstance() { 
    return true; 
  } 
 
5
CodeRank
This code example shows how to use the following methods:comparator
   * Test method for 'java.util.TreeSet.TreeSet(Comparator)'. 
   *  
   * @see java.util.TreeSet#TreeSet(Comparator) 
   */ 
  public void testConstructor_comparator() { 
    TreeSet<E> TreeSet = new TreeSet<E>(getComparator());
    _assertEmpty(TreeSet);
    if (isNaturalOrder()) { 
      assertNull(TreeSet.comparator());
    } else { 
      assertSame(getComparator(), TreeSet.comparator());
    } 
  } 
 
  /** 
   * Test method for 'java.util.TreeSet.TreeSet(Set)'. 
   *  
   * @see java.util.TreeSet#TreeSet(Set) 
   */ 
  public void testConstructor_Set() { 
4
CodeRank
comparator Method Overview
Returns the comparator used to order the elements in this set, or null if this set uses the Comparable natural ordering of its elements.
See Code Examples for other Java 8 TreeSet Methods: