Search in sources :

Example 1 with MediaComparator

use of retrospector.util.MediaComparator in project Retrospector by NonlinearFruit.

the class ListsTabController method updateListTab.

private void updateListTab() {
    listTableData.clear();
    if (!listGroupCreator.isSelected())
        return;
    boolean creator = listGroupCreator.isSelected();
    boolean title = listGroupTitle.isSelected();
    boolean season = listGroupSeason.isSelected();
    boolean episode = listGroupEpisode.isSelected();
    Chartagories chartagory = episode ? Chartagories.CURRENT_MEDIA : season ? Chartagories.SEASON : title ? Chartagories.TITLE : Chartagories.CREATOR;
    Integer top = listTop10.isSelected() ? 10 : listTop25.isSelected() ? 25 : listTop50.isSelected() ? 50 : listTop100.isSelected() ? 100 : listTop500.isSelected() ? 500 : 1000;
    LocalDate start = listCustomDateRange.isSelected() ? listStartDate.getValue().minus(1, ChronoUnit.DAYS) : LocalDate.of(Integer.parseInt(listYear.getText()) - 1, 12, 31);
    start = listUseAllTime.isSelected() ? LocalDate.MIN : start;
    LocalDate end = listCustomDateRange.isSelected() ? listEndDate.getValue().plus(1, ChronoUnit.DAYS) : LocalDate.of(Integer.parseInt(listYear.getText()) + 1, 1, 1);
    end = listUseAllTime.isSelected() ? LocalDate.MAX : end;
    String user = listUser.getText();
    for (Media media : DataManager.getMedia()) {
        for (Stroolean stroolean : strooleans) {
            if (stroolean.isBoolean() && media.getCategory().equals(stroolean.getString())) {
                boolean homeless = true;
                for (Media data : listTableData) {
                    Media temp = new Media();
                    temp.clone(media);
                    temp.setCategory(data.getCategory());
                    temp.setType(data.getType());
                    if (UtilityCloset.isSameMedia(chartagory, data, temp)) {
                        homeless = false;
                        for (Review review : media.getReviews()) {
                            if (review.getDate().isBefore(end) && review.getDate().isAfter(start) && review.getUser().equals(user)) {
                                data.getReviews().add(review);
                            }
                        }
                        break;
                    }
                }
                if (homeless) {
                    Media m = new Media();
                    if (creator)
                        m.setCreator(media.getCreator());
                    if (title)
                        m.setTitle(media.getTitle());
                    if (season)
                        m.setSeasonId(media.getSeasonId());
                    if (episode)
                        m.setEpisodeId(media.getEpisodeId());
                    m.setCategory(media.getCategory());
                    for (Review review : media.getReviews()) {
                        if (review.getUser().equals(user)) {
                            if (review.getDate().isBefore(end) && review.getDate().isAfter(start)) {
                                m.getReviews().add(review);
                            }
                        }
                    }
                    listTableData.add(m);
                }
            }
        }
    }
    List rankedResults = listTableData.stream().sorted(new MediaComparator()).limit(top).collect(Collectors.toList());
    listTable.setItems(FXCollections.observableArrayList(rankedResults));
    listRankColumn.setCellValueFactory(p -> new ReadOnlyObjectWrapper(1 + rankedResults.indexOf(p.getValue())));
    listTable.refresh();
}
Also used : Stroolean(retrospector.util.Stroolean) MediaComparator(retrospector.util.MediaComparator) Media(retrospector.model.Media) List(java.util.List) ObservableList(javafx.collections.ObservableList) Review(retrospector.model.Review) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) LocalDate(java.time.LocalDate)

Aggregations

LocalDate (java.time.LocalDate)1 List (java.util.List)1 ReadOnlyObjectWrapper (javafx.beans.property.ReadOnlyObjectWrapper)1 ObservableList (javafx.collections.ObservableList)1 Media (retrospector.model.Media)1 Review (retrospector.model.Review)1 MediaComparator (retrospector.util.MediaComparator)1 Stroolean (retrospector.util.Stroolean)1