Pojo classes film database

Tags: iText 5iText 5 examples

These are some Pojo that can be used in combination with the movie database. These examples were written in the context of the book "iText in Action - Second Edition".

Files: 
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */
 
package com.lowagie.filmfestival;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * POJO for an object that corresponds with a record
 * in the table film_movietitle.
 */
public class Movie implements Comparable<Movie> {
 
    /** The title of the movie. */
    protected String title;
    /** The original title (if different from title). */
    protected String originalTitle = null;
    /** Code used by IMDB */
    protected String imdb;
    /** The year the movie was released. */
    protected int year;
    /** The duration of the movie in minutes. */
    protected int duration;
    /** The list of directors. */
    protected List<Director> directors = new ArrayList<Director>();
    /** The list of countries. */
    protected List<Country> countries= new ArrayList<Country>();
    /** The filmfestival entry info. */
    protected Entry entry = null;
 
    /**
     * Adds a director.
     * @param director one of the directors of the movie
     */
    public void addDirector(Director director) {
        directors.add(director);
    }
 
    /**
     * Adds a country.
     * @param country  one of the countries the movie was made by.
     */
    public void addCountry(Country country) {
        countries.add(country);
    }
 
    /**
     * Returns the title in the correct form.
     * @return a title
     */
    public String getMovieTitle() {
        if (title.endsWith(", A"))
            return "A " + title.substring(0, title.length() - 3);
        if (title.endsWith(", The"))
            return "The " + title.substring(0, title.length() - 5);
        return title;
    }
 
    /**
     * Returns the title in the correct form.
     * @return a title
     */
    public String getMovieTitle(boolean prefix) {
        if (title.endsWith(", A"))
        	if (prefix)
        		return "A ";
        	else
        		return title.substring(0, title.length() - 3);
        if (title.endsWith(", The"))
        	if (prefix)
        		return "The ";
        	else
        		return title.substring(0, title.length() - 5);
        if (prefix)
        	return null;
        else
        	return title;
    }
 
    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }
    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }
    /**
     * @return the originalTitle
     */
    public String getOriginalTitle() {
        return originalTitle;
    }
    /**
     * @param originalTitle the originalTitle to set
     */
    public void setOriginalTitle(String originalTitle) {
        this.originalTitle = originalTitle;
    }
    /**
     * @return the imdb
     */
    public String getImdb() {
        return imdb;
    }
    /**
     * @param imdb the imdb to set
     */
    public void setImdb(String imdb) {
        this.imdb = imdb;
    }
    /**
     * @return the year
     */
    public int getYear() {
        return year;
    }
    /**
     * @param year the year to set
     */
    public void setYear(int year) {
        this.year = year;
    }
    /**
     * @return the duration
     */
    public int getDuration() {
        return duration;
    }
    /**
     * @param duration the duration to set
     */
    public void setDuration(int duration) {
        this.duration = duration;
    }
    /**
     * @return the directors
     */
    public List<Director> getDirectors() {
        return directors;
    }
    /**
     * @return the countries
     */
    public List<Country> getCountries() {
        return countries;
    }
    /**
     * @return the entry
     */
    public Entry getEntry() {
        return entry;
    }
    /**
     * @param entry the entry to set
     */
    public void setEntry(Entry entry) {
        this.entry = entry;
        if (entry.getMovie() == null)
            entry.setMovie(this);
    }
 
	public int compareTo(Movie o) {
		return title.compareTo(o.title);
	}
 
}
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */
 
package com.lowagie.filmfestival;
 
/**
 * POJO for an object that corresponds with a record
 * in the table film_director.
 */
public class Director {
 
    /** The family name of the director. */
    protected String name;
    /** The given name of the director. */
    protected String givenName;
 
    /**
     * @return the name
     */
    public String getName() {
        return name;
    }
    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }
    /**
     * @return the givenName
     */
    public String getGivenName() {
        return givenName;
    }
    /**
     * @param givenName the givenName to set
     */
    public void setGivenName(String givenName) {
        this.givenName = givenName;
    }
}
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */
 
package com.lowagie.filmfestival;
 
/**
 * POJO for an object that corresponds with a record
 * in the table film_country.
 */
public class Country {
    /** The name of a country. */
    protected String country;
 
    /**
     * @return the country
     */
    public String getCountry() {
        return country;
    }
 
    /**
     * @param country the country to set
     */
    public void setCountry(String country) {
        this.country = country;
    }
}
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */
 
package com.lowagie.filmfestival;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * POJO for an object that corresponds with a record
 * in the table festival_entry.
 */
public class Entry {
 
    /** The festival year. */
    protected int year;
    /** The movie. */
    protected Movie movie;
    /** The category. */
    protected Category category;
    /** The screenings. */
    protected List<Screening> screenings = new ArrayList<Screening>();
 
    /**
     * Adds a screening to this entry.
     */
    public void addScreening(Screening screening) {
        screenings.add(screening);
    }
 
    /**
     * @return the year
     */
    public int getYear() {
        return year;
    }
    /**
     * @param year the year to set
     */
    public void setYear(int year) {
        this.year = year;
    }
    /**
     * @return the movie
     */
    public Movie getMovie() {
        return movie;
    }
    /**
     * @param movie the movie to set
     */
    public void setMovie(Movie movie) {
        this.movie = movie;
        if (movie.getEntry() == null)
            movie.setEntry(this);
    }
    /**
     * @return the category
     */
    public Category getCategory() {
        return category;
    }
    /**
     * @param category the category to set
     */
    public void setCategory(Category category) {
        this.category = category;
    }
    /**
     * @return the screenings
     */
    public List<Screening> getScreenings() {
        return screenings;
    }
}
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */
 
package com.lowagie.filmfestival;
 
/**
 * POJO for an object that corresponds with a record
 * in the table festival_category.
 */
public class Category {
 
    /** The name of the category. */
    protected String name;
    /** A short keyword for the category. */
    protected String keyword;
    /** The color code of the category. */
    protected String color;
    /** The parent category (if any). */
    protected Category parent = null;
 
    /**
     * @return the name
     */
    public String getName() {
        return name;
    }
    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }
    /**
     * @return the keyword
     */
    public String getKeyword() {
        return keyword;
    }
    /**
     * @param keyword the keyword to set
     */
    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }
    /**
     * @return the parent
     */
    public Category getParent() {
        return parent;
    }
    /**
     * @param parent the parent to set
     */
    public void setParent(Category parent) {
        this.parent = parent;
    }
    /**
     * @return the color
     */
    public String getColor() {
        return color;
    }
    /**
     * @param color the color to set
     */
    public void setColor(String color) {
        this.color = color;
    }
}
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */
 
package com.lowagie.filmfestival;
 
import java.sql.Date;
import java.sql.Time;
 
/**
 * POJO for an object that corresponds with a record
 * in the table festival_screening.
 */
public class Screening {
    /** The date of the screening. */
    protected Date date;
    /** The time of the screening. */
    protected Time time;
    /** The location of the screening. */
    protected String location;
    /** Is this a screening for the press only? */
    protected boolean press;
    /** The movie that will be screened. */
    protected Movie movie = null;
 
    /**
     * @return the date
     */
    public Date getDate() {
        return date;
    }
    /**
     * @param date the date to set
     */
    public void setDate(Date date) {
        this.date = date;
    }
    /**
     * @return the time
     */
    public Time getTime() {
        return time;
    }
    /**
     * @param time the time to set
     */
    public void setTime(Time time) {
        this.time = time;
    }
    /**
     * @return the location
     */
    public String getLocation() {
        return location;
    }
    /**
     * @param location the location to set
     */
    public void setLocation(String location) {
        this.location = location;
    }
    /**
     * @return the press
     */
    public boolean isPress() {
        return press;
    }
    /**
     * @param press the press to set
     */
    public void setPress(boolean press) {
        this.press = press;
    }
    /**
     * @return the movie
     */
    public Movie getMovie() {
        return movie;
    }
    /**
     * @param movie the movie to set
     */
    public void setMovie(Movie movie) {
        this.movie = movie;
    }
}
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */
 
package com.lowagie.filmfestival;
 
import java.io.UnsupportedEncodingException;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
 
import com.lowagie.database.DatabaseConnection;
 
/**
 * A factory that makes it easy to query the database using
 * a series of static methods.
 */
public class PojoFactory {
    /** SQL statement to get all the movies of the festival. */
    public static final String MOVIES =
        "SELECT m.id, m.title, m.original_title, m.imdb, m.year, m.duration, "
        + "e.year, c.name, c.keyword, c.color "
        + "FROM film_movietitle m, festival_entry e, festival_category c "
        + "WHERE m.id = e.film_id AND e.category_id = c.id "
        + "ORDER BY m.title";
    /** SQL statement to get the directors of a specific movie. */
    public static final String DIRECTORS =
        "SELECT d.name, d.given_name "
        + "FROM film_director d, film_movie_director md "
        + "WHERE md.film_id = ? AND md.director_id = d.id";
    /** SQL statement to get the movies of a specific director. */
    public static final String MOVIEDIRECTORS =
        "SELECT m.id, m.title, m.original_title, m.imdb, m.year, m.duration "
        + "FROM film_movietitle m, film_movie_director md "
        + "WHERE md.director_id = ? AND md.film_id = m.id "
        + "ORDER BY m.title";
    /** SQL statement to get the countries of a specific movie. */
    public static final String COUNTRIES =
        "SELECT c.country "
        + "FROM film_country c, film_movie_country mc "
        + "WHERE mc.film_id = ? AND mc.country_id = c.id";
    /** SQL statement to get the movies from a specific country. */
    public static final String MOVIECOUNTRIES =
        "SELECT m.id, m.title, m.original_title, m.imdb, m.year, m.duration "
        + "FROM film_movietitle m, film_movie_country mc "
        + "WHERE mc.country_id = ? AND mc.film_id = m.id "
        + "ORDER BY m.title";
    /** SQL statement to get all the days of the festival. */
    public static final String DAYS =
        "SELECT DISTINCT day FROM festival_screening ORDER BY day";
    /** SQL statament to get all the locations at the festival */
    public static final String LOCATIONS =
        "SELECT DISTINCT location FROM festival_screening ORDER by location";
    /** SQL statement to get screenings. */
    public static final String SCREENINGS =
        "SELECT m.title, m.original_title, m.imdb, m.year, m.duration,"
        + "s.day, s.time, s.location, s.press, "
        + "e.year, c.name, c.keyword, c.color, m.id "
        + "FROM festival_screening s, film_movietitle m, "
        + "festival_entry e, festival_category c "
        + "WHERE day = ? AND s.film_id = m.id "
        + "AND m.id = e.film_id AND e.category_id = c.id";
    /** SQL statement to get screenings. */
    public static final String MOVIESCREENINGS =
        "SELECT s.day, s.time, s.location, s.press "
        + "FROM festival_screening s "
        + "WHERE s.film_id = ?";
    /** SQL statement to get screenings. */
    public static final String PRESS =
        "SELECT m.title, m.original_title, m.imdb, m.year, m.duration,"
        + "s.day, s.time, s.location, s.press, "
        + "e.year, c.name, c.keyword, c.color, m.id "
        + "FROM festival_screening s, film_movietitle m, "
        + "festival_entry e, festival_category c "
        + "WHERE s.press=1 AND s.film_id = m.id "
        + "AND m.id = e.film_id AND e.category_id = c.id "
        + "ORDER BY day, time ASC";
 
    /**
     * Fills a Movie POJO using a ResultSet.
     * @param rs a ResultSet with records from table film_movietitle
     * @return a Movie POJO
     * @throws UnsupportedEncodingException 
     */
    public static Movie getMovie(ResultSet rs)
        throws SQLException, UnsupportedEncodingException {
        Movie movie = new Movie();
        movie.setTitle(new String(rs.getBytes("title"), "UTF-8"));
        if (rs.getObject("original_title") != null)
            movie.setOriginalTitle(
               new String(rs.getBytes("original_title"), "UTF-8"));
        movie.setImdb(rs.getString("imdb"));
        movie.setYear(rs.getInt("year"));
        movie.setDuration(rs.getInt("duration"));
        return movie;
    }
 
    /**
     * Fills a Director POJO using a ResultSet.
     * @param rs a ResultSet with records from table file_director
     * @return a Director POJO
     */
    public static Director getDirector(ResultSet rs)
        throws SQLException, UnsupportedEncodingException {
        Director director = new Director();
        director.setName(new String(rs.getBytes("name"), "UTF-8"));
        director.setGivenName(new String(rs.getBytes("given_name"),"UTF-8"));
        return director;
    }
 
    /**
     * Fills a Country POJO using a ResultSet.
     * @param rs a ResultSet with records from table file_director
     * @return a Director POJO
     */
    public static Country getCountry(ResultSet rs) throws SQLException {
        Country country = new Country();
        country.setCountry(rs.getString("country"));
        return country;
    }
 
    /**
     * Fills an Entry POJO using a ResultSet.
     * @param rs a resultSet with records from table festival_entry
     * @return an Entry POJO
     */
    public static Entry getEntry(ResultSet rs) throws SQLException {
        Entry entry = new Entry();
        entry.setYear(rs.getInt("year"));
        return entry;
    }
 
    /**
     * Fills a Category POJO using a ResultSet.
     * @param rs a resultSet with records from table festival_category
     * @return a Category POJO
     */
    public static Category getCategory(ResultSet rs) throws SQLException {
        Category category = new Category();
        category.setName(rs.getString("name"));
        category.setKeyword(rs.getString("keyword"));
        category.setColor(rs.getString("color"));
        return category;
    }
 
    /**
     * Fills a Screening POJO using a ResultSet.
     * @param rs a ResultSet with records from table festival_screening
     * @return a Screening POJO
     */
    public static Screening getScreening(ResultSet rs) throws SQLException {
        Screening screening = new Screening();
        screening.setDate(rs.getDate("day"));
        screening.setTime(rs.getTime("time"));
        screening.setLocation(rs.getString("location"));
        screening.setPress(rs.getInt("press") == 1);
        return screening;
    }
 
    /**
     * Returns a list with Screening objects, if you pass
     * a DatabaseConnection and a day.
     * @param connection a connection to the film festival database
     * @param day a day (java.sql.Date)
     * @return a List of Screening POJOs
     * @throws UnsupportedEncodingException 
     */
    public static List<Screening> getScreenings(
        DatabaseConnection connection, Date day)
        throws SQLException, UnsupportedEncodingException {
        List<Screening> list = new ArrayList<Screening>();
        PreparedStatement stm =
            connection.createPreparedStatement(SCREENINGS);
        stm.setDate(1, day);
        ResultSet rs = stm.executeQuery();
        Screening screening;
        Movie movie;
        Entry entry;
        Category category;
        while (rs.next()) {
            screening = getScreening(rs);
            movie = getMovie(rs);
            for (Director director :
                getDirectors(connection, rs.getInt("id"))) {
                movie.addDirector(director);
            }
            for (Country country :
                getCountries(connection, rs.getInt("id"))) {
                movie.addCountry(country);
            }
            entry = getEntry(rs);
            category = getCategory(rs);
            entry.setCategory(category);
            entry.setMovie(movie);
            movie.setEntry(entry);
            screening.setMovie(movie);
            list.add(screening);
        }
        stm.close();
        return list;
    }
 
    /**
     * Returns a list with Screening objects, if you pass
     * a DatabaseConnection and a day.
     * @param connection a connection to the film festival database
     * @param film_id a movie id
     * @return a List of Screening POJOs
     * @throws UnsupportedEncodingException 
     */
    public static List<Screening> getScreenings(
        DatabaseConnection connection, int film_id)
        throws SQLException, UnsupportedEncodingException {
        List<Screening> list = new ArrayList<Screening>();
        PreparedStatement stm =
            connection.createPreparedStatement(MOVIESCREENINGS);
        stm.setInt(1, film_id);
        ResultSet rs = stm.executeQuery();
        Screening screening;
        while (rs.next()) {
            screening = getScreening(rs);
            list.add(screening);
        }
        stm.close();
        return list;
    }
 
    /**
     * Returns a list with Screening objects, if you pass
     * a DatabaseConnection and a day.
     * @param connection a connection to the film festival database
     * @param day a day (java.sql.Date)
     * @return a List of Screening POJOs
     * @throws UnsupportedEncodingException 
     */
    public static List<Screening> getPressPreviews(DatabaseConnection connection)
        throws SQLException, UnsupportedEncodingException {
        List<Screening> list = new ArrayList<Screening>();
        Statement stm = connection.createStatement();
        ResultSet rs = stm.executeQuery(PRESS);
        Screening screening;
        Movie movie;
        Entry entry;
        Category category;
        while (rs.next()) {
            screening = getScreening(rs);
            movie = getMovie(rs);
            for (Director director : getDirectors(connection, rs.getInt("id"))) {
                movie.addDirector(director);
            }
            for (Country country : getCountries(connection, rs.getInt("id"))) {
                movie.addCountry(country);
            }
            entry = getEntry(rs);
            category = getCategory(rs);
            entry.setCategory(category);
            entry.setMovie(movie);
            movie.setEntry(entry);
            screening.setMovie(movie);
            list.add(screening);
        }
        stm.close();
        return list;
    }
 
    /**
     * Returns a list with Movie objects.
     * @param connection a connection to the filmfestival database
     * @return a List of Screening POJOs
     * @throws SQLException 
     * @throws UnsupportedEncodingException 
     */
    public static List<Movie> getMovies(DatabaseConnection connection)
        throws SQLException, UnsupportedEncodingException {
        List<Movie> list = new ArrayList<Movie>();
        Statement stm = connection.createStatement();
        ResultSet rs = stm.executeQuery(MOVIES);
        Movie movie;
        Entry entry;
        Category category;
        while (rs.next()) {
            movie = getMovie(rs);
            entry = getEntry(rs);
            category = getCategory(rs);
            entry.setCategory(category);
            for (Screening screening : getScreenings(connection, rs.getInt("id"))) {
                entry.addScreening(screening);
            }
            movie.setEntry(entry);
            for (Director director : getDirectors(connection, rs.getInt("id"))) {
                movie.addDirector(director);
            }
            for (Country country : getCountries(connection, rs.getInt("id"))) {
                movie.addCountry(country);
            }
            list.add(movie);
        }
        return list;
    }
 
    /**
     * Returns a list with Director objects.
     * @param connection a connection to the filmfestival database
     * @param director_id the id of a movie
     * @return a List of Screening POJOs
     * @throws SQLException 
     * @throws UnsupportedEncodingException 
     */
    public static List<Director> getDirectors(
        DatabaseConnection connection, int movie_id)
        throws SQLException, UnsupportedEncodingException {
        List<Director> list = new ArrayList<Director>();
        PreparedStatement directors =
            connection.createPreparedStatement(DIRECTORS);
        directors.setInt(1, movie_id);
        ResultSet rs = directors.executeQuery();
        while (rs.next()) {
            list.add(getDirector(rs));
        }
        return list;
    }
 
    /**
     * Returns a list with Country objects.
     * @param connection a connection to the filmfestival database
     * @param movie_id the id of a movie
     * @return a List of Screening POJOs
     * @throws SQLException 
     * @throws UnsupportedEncodingException 
     */
    public static List<Country> getCountries(
        DatabaseConnection connection, int movie_id)
        throws SQLException, UnsupportedEncodingException {
        List<Country> list = new ArrayList<Country>();
        PreparedStatement countries =
            connection.createPreparedStatement(COUNTRIES);
        countries.setInt(1, movie_id);
        ResultSet rs = countries.executeQuery();
        while (rs.next()) {
            list.add(getCountry(rs));
        }
        return list;
    }
 
    /**
     * Returns a list with Movie objects.
     * @param connection a connection to the filmfestival database
     * @param director_id the id of a director
     * @return a List of Screening POJOs
     * @throws SQLException 
     * @throws UnsupportedEncodingException 
     */
    public static List<Movie> getMovies(
        DatabaseConnection connection, int director_id)
        throws SQLException, UnsupportedEncodingException {
        List<Movie> list = new ArrayList<Movie>();
        PreparedStatement movies =
            connection.createPreparedStatement(MOVIEDIRECTORS);
        movies.setInt(1, director_id);
        ResultSet rs = movies.executeQuery();
        Movie movie;
        while (rs.next()) {
            movie = getMovie(rs);
            for (Country country : getCountries(connection, rs.getInt("id"))) {
                movie.addCountry(country);
            }
            list.add(movie);
        }
        return list;
    }
 
    /**
     * Returns a list with Movie objects.
     * @param connection a connection to the filmfestival database
     * @param country_id the id of a country
     * @return a List of Screening POJOs
     * @throws SQLException 
     * @throws UnsupportedEncodingException 
     */
    public static List<Movie> getMovies(
       DatabaseConnection connection, String country_id)
        throws SQLException, UnsupportedEncodingException {
        List<Movie> list = new ArrayList<Movie>();
        PreparedStatement movies =
            connection.createPreparedStatement(MOVIECOUNTRIES);
        movies.setString(1, country_id);
        ResultSet rs = movies.executeQuery();
        while (rs.next()) {
            Movie movie = getMovie(rs);
            for (Director director : getDirectors(connection, rs.getInt("id"))) {
                movie.addDirector(director);
            }
            list.add(movie);
        }
        return list;
    }
 
    /**
     * Returns an ArrayList containing all the filmfestival days.
     * @param connection a connection to the database.
     * @return a list containing dates.
     */
    public static List<Date> getDays(DatabaseConnection connection)
        throws SQLException {
        List<Date> list = new ArrayList<Date>();
        Statement stm = connection.createStatement();
        ResultSet rs = stm.executeQuery(DAYS);
        while (rs.next()) {
            list.add(rs.getDate("day"));
        }
        stm.close();
        return list;
    }
 
    /**
     * Returns an ArrayList containing all the screening locations.
     * @param connection a connection to the database.
     * @return a list containing location codes.
     */
    public static List<String> getLocations(DatabaseConnection connection)
        throws SQLException {
        List<String> list = new ArrayList<String>();
        Statement stm = connection.createStatement();
        ResultSet rs =
            stm.executeQuery(LOCATIONS);
        while (rs.next()) {
            list.add(rs.getString("location"));
        }
        stm.close();
        return list;
    }
}
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */
 
package com.lowagie.filmfestival;
 
import com.itextpdf.text.Font;
import com.itextpdf.text.Font.FontFamily;
 
/**
 * Contains a series of static Font objects that are used throughout the book.
 */
public class FilmFonts {
 
    /** A font used in our PDF file */
    public static final Font NORMAL = new Font(FontFamily.HELVETICA, 12, Font.NORMAL);
    /** A font used in our PDF file */
    public static final Font BOLD = new Font(FontFamily.HELVETICA, 12, Font.BOLD);
    /** A font used in our PDF file */
    public static final Font ITALIC = new Font(FontFamily.HELVETICA, 12, Font.ITALIC);
    /** A font used in our PDF file */
    public static final Font BOLDITALIC = new Font(FontFamily.HELVETICA, 12, Font.BOLDITALIC);
 
}
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */
 
package com.lowagie.filmfestival;
 
import java.util.Comparator;
 
/**
 * Compares movies based on their title or the year, they're made in.
 */
public class MovieComparator implements Comparator<Movie> {
 
    /** Type for movies have to be sorted by title. */
    public static int BY_TITLE = 0;
    /** Type for movies have to be sorted by production year. */
    public static int BY_YEAR = 1;
 
    /** The type; can be BY_TITLE or BY_YEAR. */
    protected int type;
 
    /**
     * Creates an instance of the MovieComparator.
     * @param type defines how the movies will be sorted;
     * can be BY_TITLE or BY_YEAR
     */
    public MovieComparator(int type) {
        this.type = type;
    }
 
    /**
     * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
     */
    public int compare(Movie m1, Movie m2) {
        if (type == BY_YEAR) {
            int c = m1.getYear() - m2.getYear();
            if (c != 0)
                return c;
        }
        return m1.getTitle().compareTo(m2.getTitle());
    }
 
}
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */
 
package com.lowagie.filmfestival;
 
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Element;
import com.itextpdf.text.List;
import com.itextpdf.text.Phrase;
 
public class PojoToElementFactory {
 
    /**
     * Creates a Phrase containing the title of a Movie.
     * @param movie a Movie object
     * @return a Phrase object
     */
    public static final Phrase getMovieTitlePhrase(final Movie movie) {
        return new Phrase(movie.getMovieTitle(), FilmFonts.NORMAL);
    }
 
    /**
     * Creates a Phrase containing the original title of a Movie.
     * @param movie a Movie object
     * @return a Phrase object
     */
    public static final Phrase getOriginalTitlePhrase(final Movie movie) {
        if (movie.getOriginalTitle() == null)
            return new Phrase("", FilmFonts.NORMAL);
        return new Phrase(movie.getOriginalTitle(), FilmFonts.ITALIC);
    }
 
    /**
     * Creates a Phrase containing the name of a Director.
     * @param director a Director object
     * @return a Phrase object
     */
    public static final Phrase getDirectorPhrase(final Director director) {
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(director.getName(), FilmFonts.BOLD));
        phrase.add(new Chunk(", ", FilmFonts.BOLD));
        phrase.add(new Chunk(director.getGivenName(), FilmFonts.NORMAL));
        return phrase;
    }
 
    /**
     * Creates a Phrase containing the name of a Country.
     * @param country a Country object
     * @return a Phrase object
     */
    public static final Phrase getCountryPhrase(final Country country) {
        return new Phrase(country.getCountry(), FilmFonts.NORMAL);
    }
 
    /**
     * Creates a list with directors.
     * @param movie a Movie object
     * @return a List object
     */
    public static final List getDirectorList(Movie movie) {
        List list = new List();
        for (Director director : movie.getDirectors()) {
            list.add(String.format(
               "%s, %s", director.getName(), director.getGivenName()));
        }
        return list;
    }
 
    /**
     * Creates a list with countries.
     * @param movie a Movie object
     * @return a List object
     */
    public static final List getCountryList(Movie movie) {
        List list = new List();
        for (Country country : movie.getCountries()) {
            list.add(country.getCountry());
        }
        return list;
    }
 
    /**
     * Creates a phrase with the production year of a movie.
     * @param movie a Movie object
     * @return a Phrase object
     */
    public static final Element getYearPhrase(Movie movie) {
        Phrase p = new Phrase();
        p.add(new Chunk("Year: ", FilmFonts.BOLD));
        p.add(new Chunk(String.valueOf(movie.getYear()), FilmFonts.NORMAL));
        return p;
    }
 
    /**
     * Creates a phrase with the run length of a movie.
     * @param movie a Movie object
     * @return a Phrase object
     */
    public static final Element getDurationPhrase(Movie movie) {
        Phrase p = new Phrase();
        p.add(new Chunk("Duration: ", FilmFonts.BOLD));
        p.add(new Chunk(String.valueOf(movie.getDuration()), FilmFonts.NORMAL));
        return p;
    }
}
File nameRaw URLUpdated
Movie.javaMovie.java2015-10-10 2:10 pm
Director.javaDirector.java2015-10-10 2:10 pm
Country.javaCountry.java2015-10-10 2:10 pm
Entry.javaEntry.java2015-10-10 2:10 pm
Category.javaCategory.java2015-10-10 2:10 pm
Screening.javaScreening.java2015-10-10 2:10 pm
PojoFactory.javaPojoFactory.java2015-10-10 2:10 pm
FilmFonts.javaFilmFonts.java2015-10-10 2:10 pm
MovieComparator.javaMovieComparator.java2015-10-10 2:10 pm
PojoToElementFactory.javaPojoToElementFactory.java2015-10-10 2:10 pm
C# port: 
File nameRaw URLUpdated
Movie.csMovie.cs2015-10-10 2:16 pm
Director.csDirector.cs2015-10-10 2:16 pm
Country.csCountry.cs2015-10-10 2:16 pm
Entry.csEntry.cs2015-10-10 2:16 pm
Category.csCategory.cs2015-10-10 2:16 pm
Screening.csScreening.cs2015-10-10 2:17 pm
PojoFactory.csPojoFactory.cs2015-10-10 2:16 pm
FilmFonts.csFilmFonts.cs2015-10-10 2:17 pm
PojoToElementFactory.csPojoToElementFactory.cs2015-10-10 2:17 pm