Java SortedSet sortedSet()

Here you can find the source of sortedSet()

Description

Creates an empty SortedSet.

License

Apache License

Return

new empty SortedSet

Declaration

public static <T> SortedSet<T> sortedSet() 

Method Source Code

//package com.java2s;
/*/*from   www  .j  a  v  a 2  s . com*/
Copyright 1996-2010 Ariba, Inc.
    
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
    
$Id: //ariba/platform/util/core/ariba/util/core/SetUtil.java#16 $
*/

import java.util.Comparator;

import java.util.SortedSet;
import java.util.TreeSet;

public class Main {
    /**
    Creates an empty SortedSet. <p/>
        
    To construct a type-safe <code>Set</code>:<ul>
    <li><code>Set&lt;X> typesafe = SetUtil.sortedSet()</code>
    </ul>
    For a raw <code>Set</code>:<ul>
    <li><code>Set raw = SetUtil.set()</code>
    </ul>
    There will be no compile warnings either way.
        
    @return new empty SortedSet
    @see java.util.SortedSet
    @aribaapi documented
    */
    public static <T> SortedSet<T> sortedSet() {
        return new TreeSet<T>();
    }

    /**
    Creates an empty SortedSet <p/>
        
    Given that <code>compX</code> is a <code>Comparator&lt;X></code>,
    <code>compY</code> is a <code>Comparator&lt;Y></code> (and that <code>Y</code>
    extends <code>X</code>) and <code>comp</code> is a raw
    <code>Comparator</code>, the following all compile validly. <ul>
    <li><code>Set&lt;X> typesafe = SetUtil.sortedSet(compX)</code>
    <li><code>Set&lt;X> typesafe = SetUtil.&lt;X>sortedSet(compY)</code>
    <li><code>Set&lt;?> unknown = SetUtil.immutableSet(compX)</code>
    </ul>
    The following constructs compile with an unchecked warning:<ul>
    <li><code>Set&lt;X> typesafe = SetUtil.immutableSet(comp)</code>
    <li><code>Set raw = SetUtil.immutableSet(compX)</code>
    </ul>
        
    @param comparator the non-null comparator that will be used to
       sort the <code>Set</code>
    @return new empty SortedSet
    @see java.util.SortedSet
    @aribaapi documented
    */
    public static <T> SortedSet<T> sortedSet(Comparator<? super T> comparator) {
        return new TreeSet<T>(comparator);
    }

    /**
    Creates a new {@link SortedSet} with the same content as the given
    <code>SortedSet</code>. <p/>
        
    Given that <code>setOfX</code> is a <code>SortedSet&lt;X></code>,
    <code>setOfY</code> is a <code>SortedSet&lt;Y></code> (and that <code>Y</code>
    extends <code>X</code>) and <code>raw</code> is a raw
    <code>SortedSet</code>, the following all compile validly. <ul>
    <li><code>SortedSet&lt;X> typesafe = SetUtil.sortedSet(setOfX)</code>
    <li><code>SortedSet&lt;X> typesafe = SetUtil.&lt;X>sortedSet(setOfY)</code>
    <li><code>SortedSet&lt;?> unknown = SetUtil.sortedSet(setOfX)</code>
    </ul>
    The following constructs compile with an unchecked warning:<ul>
    <li><code>SortedSet&lt;X> typesafe = SetUtil.sortedSet(raw)</code>
    <li><code>SortedSet raw = SetUtil.sortedSet(setOfX)</code>
    </ul>
        
    @param source the non-null sorted set based on the given SortedSet
    @return SortedSet containing the elements of the source
    @see java.util.SortedSet
    @aribaapi documented
    */
    public static <T> SortedSet<T> sortedSet(SortedSet<? extends T> source) {
        return new TreeSet<T>(source);
    }
}

Related

  1. setDistance(SortedSet s1, SortedSet s2)
  2. setminus(SortedSet pSet1, SortedSet pSet2)
  3. sorted(Iterable input)
  4. sortedByValues(Map map, final boolean asc)
  5. sortedConfigKeys(Iterable> conf)
  6. splitSorted(String str, String sepStr)
  7. toSortedSet(Comparator comparator, Value... values)
  8. unionSortedSet(Set... sets)
  9. valueSortedMap(Map map, Comparator> comparator)