W
W
Wilson2020-05-11 11:40:43
Java
Wilson, 2020-05-11 11:40:43

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);
}


Can you tell what each piece of code does?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-05-11
@sergey-gornostaev

EJB is not for beginners.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question