import java.util.*;
/**
* A class designed to illustrate the use of type parameters
* and the mutation of the {@link ArrayList ArrayList}
.
* Data consists of three elements ordered by the given
* {@link Comparator Comparator}
.
*
* @since 31 October 2007
* @author Viera K. Proulx
*/
public class TopThree {
/**
* An ArrayList
to hold the three
* data elements.
*/
public ArrayList all;
/**
* The comparator that defines the ordering of the elements.
*/
public Comparator comp;
/**
* The full constructor.
*/
public TopThree(T one, T two, T three, Comparator comp){
this.all = new ArrayList(3);
this.all.add(0, one);
this.all.add(1, two);
this.all.add(2, three);
this.comp = comp;
this.reorder();
}
/**
* Change each element to the given one and re-order the data.
*
* @param d1 the first of the three {@link Balloon Balloon}
s
* @param d2 the second of the three {@link Balloon Balloon}
s
* @param d3 the third of the three {@link Balloon Balloon}
s
*/
public void reset(T d1, T d2, T d3){
this.all.set(0, d1);
this.all.set(1, d2);
this.all.set(2, d3);
this.reorder();
}
/**
* Reorder the data using the 'resident' Comparator
.
*/
public void reorder(){
T temp = this.all.get(0);
if (this.comp.compare(this.all.get(0), this.all.get(1)) < 0){
// ...
}
// ...
}
}