package com.jdbernard.teammaker

import javax.swing.AbstractListModel

public class SortedPlayerModel extends AbstractListModel {
    private TreeSet<Player> set = new TreeSet<Player>()

    public int getSize() { return set.size() }
    public Object getElementAt(int index) { 
        int i = 0
        for (player in set) { 
            if (i == index) return player
            i++
        }
        throw new ArrayIndexOutOfBoundsException()
    }

    public void addElement(Player p) {
        set.add(p)
        fireIntervalAdded(this, 0, set.size())
    }

    
    public void removeElement(Player p) {
        set.remove(p)
        fireIntervalRemoved(this, 0, set.size())
    }
}
