Created
January 12, 2017 08:42
-
-
Save JosePaumard/4bf06fbdbc7830f0f79598a5d42828f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.paumard.movies.model; | |
import java.util.HashSet; | |
import java.util.Set; | |
import javax.xml.bind.annotation.XmlAccessType; | |
import javax.xml.bind.annotation.XmlAccessorType; | |
import javax.xml.bind.annotation.XmlAttribute; | |
import javax.xml.bind.annotation.XmlElement; | |
import javax.xml.bind.annotation.XmlElementWrapper; | |
import javax.xml.bind.annotation.XmlRootElement; | |
@XmlRootElement | |
@XmlAccessorType(XmlAccessType.FIELD) | |
public class Movie { | |
@XmlAttribute | |
private long id; | |
@XmlElement(name="title") | |
private String title; | |
@XmlElement(name="release-year") | |
private int releaseYear; | |
@XmlElementWrapper(name="actors") | |
@XmlElement(name="actor") | |
private Set<Actor> actors = new HashSet<>(); | |
public long getId() { | |
return id; | |
} | |
public void setId(long id) { | |
this.id = id; | |
} | |
public String getTitle() { | |
return title; | |
} | |
public void setTitle(String title) { | |
this.title = title; | |
} | |
public int getReleaseYear() { | |
return releaseYear; | |
} | |
public void setReleaseYear(int releaseYear) { | |
this.releaseYear = releaseYear; | |
} | |
public Set<Actor> getActors() { | |
return actors; | |
} | |
public boolean addActor(Actor actor) { | |
return this.actors.add(actor); | |
} | |
public void setActors(Set<Actor> actors) { | |
this.actors = actors; | |
} | |
@Override | |
public String toString() { | |
return "Movie [id=" + id + ", title=" + title + ", releaseYear=" + releaseYear + ", actors=" + actors.size() + "]"; | |
} | |
public static Movie of(long id, String title, int releaseYear) { | |
Movie movie = new Movie(); | |
movie.id = id; | |
movie.title = title; | |
movie.releaseYear = releaseYear; | |
return movie; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment