import java.io.File;
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;
import javax.swing.JOptionPane;
/*
 * TreeSetExample.java
 *
 * Created on February 16, 2006, 4:35 PM
 *
 */

/**
 *
 * @author Bill Kraynek
 */
public class TreeSetExample {
    
    /** Creates a new instance of TreeSetExample */
    public TreeSetExample() throws Exception {
        Scanner scan = new Scanner(new File("src/TreeSetExample.java"));
        scan.useDelimiter("[^a-zA-Z]+");
        TreeSet<String> words = new TreeSet<String>();
        while( scan.hasNext() ) words.add(scan.next() );
        JOptionPane.showMessageDialog(null,words);
        TreeSet<String> otherWords = new TreeSet<String>(new SLC());
        otherWords.addAll(words);
        JOptionPane.showMessageDialog(null,otherWords);
    }
    
    class SLC implements Comparator<String> {
        public int compare(String left,String right) {
            int diff = right.length() - left.length();
            if( diff != 0 ) return diff;
            return left.compareTo(right);
        }
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        new TreeSetExample();
    }
    
}

