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

com.moviejukebox.model.Artwork.Artwork 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.Artwork;

import com.moviejukebox.model.Movie;
import java.util.Collection;
import java.util.EnumMap;
import java.util.Map;

/**
 * A class to store all the artwork associated with a movie object
 *
 * @author stuart.boston
 *
 */
public class Artwork {

    private ArtworkType type;       // The type of the artwork.
    private String sourceSite; // Where the artwork originated from
    private String url;        // The original URL of the artwork (may be used as key)
    private Map sizes; // The hash should be the size that is passed as part of the ArtworkSize

    /**
     * Create an Artwork object with a set of sizes
     *
     * @param type The type of the artwork
     * @param sourceSite The source site the artwork came from
     * @param url The URL of the artwork
     * @param sizes A list of the artwork files to add
     */
    public Artwork(ArtworkType type, String sourceSite, String url, Collection sizes) {
        this.type = type;
        this.sourceSite = sourceSite;
        this.url = url;

        this.sizes = new EnumMap(ArtworkSize.class);
        for (ArtworkFile artworkFile : sizes) {
            this.addSize(artworkFile);
        }
    }

    /**
     * Create an Artwork object with a single size
     *
     * @param type The type of the artwork
     * @param sourceSite The source site the artwork came from
     * @param url The URL of the artwork
     * @param size An artwork files to add
     */
    public Artwork(ArtworkType type, String sourceSite, String url, ArtworkFile size) {
        this.type = type;
        this.sourceSite = sourceSite;
        this.url = url;
        this.sizes = new EnumMap(ArtworkSize.class);
        this.addSize(size);
    }

    /**
     * Create a blank Artwork object
     */
    public Artwork() {
        this.sourceSite = Movie.UNKNOWN;
        this.type = null;
        this.url = Movie.UNKNOWN;
        this.sizes = new EnumMap(ArtworkSize.class);
    }

    /**
     * Add the ArtworkFile to the list, overwriting anything already there
     *
     * @param size
     */
    public final void addSize(ArtworkFile size) {
        sizes.put(size.getSize(), size);
    }

    public Collection getSizes() {
        return sizes.values();
    }

    public ArtworkFile getSize(String size) {
        return sizes.get(ArtworkSize.valueOf(size.toUpperCase()));
    }

    public ArtworkFile getSize(ArtworkSize size) {
        return sizes.get(size);
    }

    /**
     * @return the sourceSite
     */
    public String getSourceSite() {
        return sourceSite;
    }

    /**
     * @return the type
     */
    public ArtworkType getType() {
        return type;
    }

    /**
     * @return the url
     */
    public String getUrl() {
        return url;
    }

    /**
     * @param sourceSite the sourceSite to set
     */
    public void setSourceSite(String sourceSite) {
        this.sourceSite = sourceSite;
    }

    /**
     * @param type the type to set
     */
    public void setType(ArtworkType type) {
        this.type = type;
    }

    /**
     * @param url the URL to set
     */
    public void setUrl(String url) {
        this.url = url;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 79 * hash + (this.type != null ? this.type.hashCode() : 0);
        hash = 79 * hash + (this.sourceSite != null ? this.sourceSite.hashCode() : 0);
        hash = 79 * hash + (this.url != null ? this.url.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return Boolean.FALSE;
        }

        if (getClass() != obj.getClass()) {
            return Boolean.FALSE;
        }

        final Artwork other = (Artwork) obj;
        if (this.type != other.type) {
            return Boolean.FALSE;
        }

        if ((this.sourceSite == null) ? (other.sourceSite != null) : !this.sourceSite.equals(other.sourceSite)) {
            return Boolean.FALSE;
        }

        if ((this.url == null) ? (other.url != null) : !this.url.equals(other.url)) {
            return Boolean.FALSE;
        }

        return Boolean.TRUE;
    }

    public int compareTo(Artwork anotherArtwork) {
        if (this.sourceSite.equals(anotherArtwork.getSourceSite())
                && this.type.equals(anotherArtwork.getType())
                && this.url.equals(anotherArtwork.getUrl())) {
            return 0;
        } else {
            return 1;
        }
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("[Artwork=");
        sb.append("[type=").append(type);
        sb.append("][sourceSite=").append(sourceSite);
        sb.append("][url=").append(url);
        sb.append("][sizes=").append(sizes);
        sb.append("]]");
        return sb.toString();
}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy