Answer the question
In order to leave comments, you need to log in
What does this class do in Java?
I am new to Java and I have the following code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package subject.ejb;
import java.util.ArrayList;
import java.util.Collections;
import javax.ejb.Stateful;
import java.util.Comparator;
import java.util.List;
@Stateful
public class Subject implements SubjectLocal {
ArrayList content;
public static Comparator<String[]> cmp = new Comparator<String[]>() {
@Override
public int compare(String[] s1, String[] s2) {
return s2[1].compareTo(s1[1]);
}
};
public Subject() {
content = new ArrayList();
}
@Override
public ArrayList getList() {
return content;
}
@Override
public void remove(int index) {
content.remove(index);
}
@Override
public void add(String departure, String arrival, String price, String classe) {
content.add(new String[]{departure, arrival, price, classe});
}
@Override
public ArrayList getMostExpensive(int number) {
ArrayList clone = (ArrayList )content.clone();
Collections.sort(clone, cmp);
if (clone.size() > number){
clone = new ArrayList(clone.subList(0, number));
}
return clone;
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package subject.ejb;
import java.util.ArrayList;
import javax.ejb.Local;
@Local
public interface SubjectLocal {
ArrayList getList();
void remove(int index);
void add(String departure, String arrival, String price, String classe);
ArrayList getMostExpensive(int number);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question