All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.moviejukebox.model.Index Maven / Gradle / Ivy

There is a newer version: 2.9
Show newest version
/*
 *      Copyright (c) 2004-2012 YAMJ Members
 *      http://code.google.com/p/moviejukebox/people/list
 *
 *      Web: http://code.google.com/p/moviejukebox/
 *
 *      This software is licensed under a Creative Commons License
 *      See this page: http://code.google.com/p/moviejukebox/wiki/License
 *
 *      For any reuse or distribution, you must make clear to others the
 *      license terms of this work.
 */
package com.moviejukebox.model;

import com.moviejukebox.tools.StringTools;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeMap;

public class Index extends TreeMap> {
    private int maxCategories = -1;
    private boolean display = true;

    private static final long serialVersionUID = -6240040588085931654L;

    public Index(Comparator comp) {
        super(comp);
    }

    public Index() {
        super();
    }

    public Index(boolean display) {
        this();
        this.display = display;
    }

    public boolean display() {
        return display;
    }

    protected void addMovie(String category, Movie movie) {
        if (StringTools.isNotValidString(category)) {
            return;
        }

        if (movie == null) {
            return;
        }

        List list = get(category);

        if (list == null) {
            if (maxCategories > 0 && size() >= maxCategories) {
                return;
            }
            list = new ArrayList();
            put(category, list);
        }

        if (!list.contains(movie)) {
            list.add(movie);
        }
    }

    public void removeMovie(String category, Movie movie) {
        if (StringTools.isNotValidString(category)) {
            return;
        }

        if (movie == null) {
            return;
        }

        List list = get(category);

        if (list == null || list.isEmpty()) {
            return;
        }

        if (list.contains(movie)) {
            list.remove(movie);
        }
    }

    public int getMaxCategories() {
        return maxCategories;
    }

    public void setMaxCategories(int maxCategories) {
        this.maxCategories = maxCategories;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy