@bbbbb123654

Что делает этот класс в Java?

Я новичок в Java и у меня есть следующий код:

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


Можете рассказать что делает каждый участок кода?
  • Вопрос задан
  • 132 просмотра
Пригласить эксперта
Ответы на вопрос 1
sergey-gornostaev
@sergey-gornostaev Куратор тега Java
Седой и строгий
EJB не для новичков.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы