Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.savvasdalkitsis.jtmdb;
  
  import java.util.Date;
  import java.util.Set;
  
This class contains the options used in the Movie.browse method.

Author(s):
Savvas Dalkitsis
 
 public class BrowseOptions implements Serializable {
 
 	private static final long serialVersionUID = 3834662739424850032L;

Enumeration of the types of order for the results.

Author(s):
Savvas Dalkitsis
 
 	public static enum ORDER_BY {
Order by rating.
 
 		RATING("rating"),
Order by release date (default).
 
 		RELEASE("release"),
Order by title.
 
 		TITLE("title");
 
 		private String name;
 
 		private ORDER_BY(String name) {
 			this. = name;
 		}
 
 		protected String getName() {
 			return ;
 		}
 	}

Enumeration of the order of the results.

Author(s):
Savvas Dalkitsis
 
 	public static enum ORDER {
Ascending order (default).
 
 		ASC("asc"),
Descending order.
 
 		DESC("desc");
 
 		private String name;
 
 		private ORDER(String name) {
 			this. = name;
 		}
 
 		protected String getName() {
 			return ;
 		}
 	}

Enumeration providing AND, OR operators.

Author(s):
Savvas Dalkitsis
 
 	public static enum BOOLEAN {
Boolean AND.
 
 		AND("and"),
Boolean OR.
 
 		OR("or");
 
 		private String name;
 
 		private BOOLEAN(String name) {
 			this. = name;
 		}
 
 		protected String getName() {
			return ;
		}
	}

The type of ordering for the results.
The order of the results.
	private ORDER order = .;
The page of the results.
	private Integer page = null;
The amount of results per page.
	private Integer perPage = null;
The query of the search.
	private String query = null;
The minimum rating of the results.
	private Float ratingMin = null;
The maximum rating of the results.
	private Float ratingMax = null;
The genres of the search.
	private Set<Integergenres = null;
The boolean operator to apply to the genres search.
The minimum release date for the search.
	private Date releaseMin = null;
The maximum release date for the search.
	private Date releaseMax = null;
The year in which movies where released.
	private Integer year = null;
The certifications of the search.
	private Set<Stringcertifications = null;
The companies of the search.
	private Set<Stringcompanies = null;
The countries of the search.
	private Set<Stringcountries = null;
The minimum amount of votes a Movie must have to appear in the results.
	private Integer minVotes = null;

Gets the type of the ordering of the results. Default is ORDER_BY.RELEASE.

Returns:
The type of the ordering of the results. Default is ORDER_BY.RELEASE.
	public ORDER_BY getOrderBy() {
		return ;
	}

Sets the type of the ordering of the results.

Parameters:
orderBy The type of the ordering of the results.
	public void setOrderBy(ORDER_BY orderBy) {
		this. = orderBy;
	}

Gets the order of the results. Default is ORDER.ASC.

Returns:
The order of the results. Default is ORDER.ASC.
	public ORDER getOrder() {
		return ;
	}

Sets the order of the results.

Parameters:
order The order of the results.
	public void setOrder(ORDER order) {
		this. = order;
	}

Clears the page information from the search. Also clears the PerPage information.
	public void clearPage() {
		this. = null;
		this. = null;
	}

Gets the current page of the results.

Returns:
The current page of the results. Will be null if the page is not set or has been cleared.
	public Integer getPage() {
		return ;
	}

Sets the page of the results. Must be greater than 0.

Parameters:
page The page of the results. Must be greater than 0.
	public void setPage(int page) {
		if (page > 0) {
			this. = page;
		}
	}

Clears the per page information from the search. Does NOT clear the page information as it can be used without this setting.
	public void clearPerPage() {
		this. = null;
	}

Gets the amount of results displayed in each page of the results. Will be null if the per page is not set or has been cleared.

Returns:
The amount of results displayed in each page of the results. Will be null if the per page is not set or has been cleared.
	public Integer getPerPage() {
		return ;
	}

Sets the amount of results to display per page. Must be greater than 0.

Parameters:
perPage The amount of results to display per page. Must be greater than 0.
	public void setPerPage(int perPage) {
		if (perPage > 0) {
			this. = perPage;
		}
	}

Clears the query from the search.
	public void clearQuery() {
		this. = null;
	}

Gets the query for the search. Will be null if it has not been set or has been cleared.

Returns:
The query for the search. Will be null if it has not been set or has been cleared.
	public String getQuery() {
		return ;
	}

Sets the query for the search. If you pass null it acts like clearQuery().

Parameters:
query The query for the search. If you pass null it acts like clearQuery().
	public void setQuery(String query) {
		this. = query;
	}

Clears the ratingMin and ratingMax settings from the search.
	public void clearRatings() {
		 = null;
		 = null;
	}

Gets the minimum rating a movie must have to appear in the results.

Returns:
The minimum rating a movie must have to appear in the results.
	public Float getRatingMin() {
		return ;
	}

Gets the maximum rating a movie must have to appear in the results.

Returns:
The maximum rating a movie must have to appear in the results.
	public Float getRatingMax() {
		return ;
	}

Sets the minimum rating a movie must have to appear in the results. Must be greater or equal to 0 and smaller than or equal to 10. If the maximum rating has not been set or if it has been set but is smaller than this value, this will set it to 10.

Parameters:
ratingMin The minimum rating a movie must have to appear in the results. Must be greater or equal to 0 and smaller than or equal to 10. If the maximum rating has not been set or if it has been set but is smaller than this value, this will set it to 10.
	public void setRatingMin(float ratingMin) {
		if (ratingMin < 0 || ratingMin > 10) {
			return;
		}
		this. = ratingMin;
		if ( == null ||  < ratingMin) {
			 = 10F;
		}
	}

Sets the maximum rating a movie must have to appear in the results. Must be greater or equal to 0 and smaller than or equal to 10. If the minimum rating has not been set or if it has been set but is greater than this value, this will set it to 0.

Parameters:
ratingMax The maximum rating a movie must have to appear in the results. Must be greater or equal to 0 and smaller than or equal to 10. If the minimum rating has not been set or if it has been set but is greater than this value, this will set it to 0.
	public void setRatingMax(float ratingMax) {
		if (ratingMax > 10 || ratingMax < 0) {
			return;
		}
		this. = ratingMax;
		if ( == null ||  > ratingMax) {
			 = 0F;
		}
	}

Clears the genres from the search.
	public void clearGenres() {
		 = null;
	}

Gets the set of genres for the search.

Returns:
The set of genres for the search.
	public Set<IntegergetGenres() {
		return ;
	}

Adds the genres to the list for the search.

Parameters:
genreIDs The IDs of the genres to add.
	public void addGenres(int... genreIDs) {
		if ( == null) {
		}
		for (int ID : genreIDs) {
		}
	}

Adds the genres to the list for the search.

Parameters:
genres The genres to add.
	public void addGenres(Genre... genres) {
		if (this. == null) {
			this. = new LinkedHashSet<Integer>();
		}
		for (Genre g : genres) {
			this..add(g.getID());
		}
	}

Attempts to add genres to the list for the search by name.

NOTE:
This calls the method Genre.getList which connects to the server to request a list of all the genres. Also note that depending on the language you have specified in the GeneralSettings, the list returned may be translated to another language and therefore there may be mismatches between the names you specified and the returned names, in which case the genres will not be added.

Parameters:
genreNames The names of genres to add.
	public void addGenres(String... genreNames) {
		try {
			Set<Genregenres = Genre.getList().getSecond();
			addGenres(genresgenreNames);
catch (Exception e) {
		}
	}

Attempts to add genres to the list for the search by name. It assumes that the genre name matches the name of one of the genres in the specified set. This method is useful because calling the method addGenres(java.lang.String[]), a connection to the server is made making it costly to use. With this method you can cache the list of genres initially by manually calling Genre.getList() and pass it to this method.

NOTE:
As with the method addGenres(java.lang.String[]), the list returned by the method Genre.getList() may be translated and thus, the names may not match.

Parameters:
genreList The set of genres in which to look for the genre by name.
genreNames The names of genres to add.
	public void addGenres(Set<GenregenreListString... genreNames) {
		for (Genre g : genreList) {
			for (String genreName : genreNames) {
				if (g.getName().equals(genreName)) {
				}
			}
		}
	}

Removes the genres from the search.

Parameters:
genreIDs The IDs of the genres to remove.
	public void removeGenres(int... genreIDs) {
		if ( != null) {
			for (int ID : genreIDs) {
			}
		}
	}

Removes the genres from the search.

Parameters:
genres The genres to remove.
	public void removeGenres(Genre... genres) {
		if (this. != null) {
			for (Genre g : genres) {
				this..remove(g.getID());
			}
		}
	}

Attempts to remove genres from the list for the search by name.

NOTE:
This calls the method Genre.getList which connects to the server to request a list of all the genres. Also note that depending on the language you have specified in the GeneralSettings, the list returned may be translated to another language and therefore there may be mismatches between the names you specified and the returned names, in which case the genres will not be removed.

Parameters:
genreNames The names of genres to remove.
	public void removeGenres(String... genreNames) {
		try {
			Set<Genregenres = Genre.getList().getSecond();
			removeGenres(genresgenreNames);
catch (Exception e) {
		}
	}

Attempts to remove genres to the list for the search by name. It assumes that the genre name matches the name of one of the genres in the specified set. This method is useful because calling the method removeGenres(java.lang.String[]), a connection to the server is made making it costly to use. With this method you can cache the list of genres initially by manually calling Genre.getList() and pass it to this method.

NOTE:
As with the method removeGenres(java.lang.String[]), the list returned by the method Genre.getList() may be translated and thus, the names may not match.

Parameters:
genreList The set of genres in which to look for the genre by name.
genreNames The names of genres to remove.
	public void removeGenres(Set<GenregenreListString... genreNames) {
		for (Genre g : genreList) {
			for (String genreName : genreNames) {
				if (g.getName().equals(genreName)) {
				}
			}
		}
	}

Gets the genre selector for the search. Default is BOOLEAN.AND.

Returns:
The genre selector for the search. Default is BOOLEAN.AND.
	}

Sets the genre selector for the search.

Parameters:
genreSelector The genre selector for the search.
	public void setGenreSelector(BOOLEAN genreSelector) {
		this. = genreSelector;
	}

Clears the releaseMin and releaseMax from the search.
	public void clearReleases() {
		 = null;
		 = null;
	}

Gets the minimum release date a movie must have to appear in the results.

Returns:
The minimum release date a movie must have to appear in the results.
	public Date getReleaseMin() {
		return ;
	}

Gets the maximum release date a movie must have to appear in the results.

Returns:
The maximum release date a movie must have to appear in the results.
	public Date getReleaseMax() {
		return ;
	}

Sets the minimum release date a movie must have to appear in the results. If the maximum release date has not been set or if it has been set but is earlier than this date, this will set it to the latest date that can be represented. If null is passed, it acts like calling clearReleases(). If not, this method calls clearYear() since they cannot be used side by side.

Parameters:
ratingMin The minimum release date a movie must have to appear in the results. If the maximum release date has not been set or if it has been set but is earlier than this date, this will set it to the latest date that can be represented. If null is passed, it acts like calling clearReleases(). If not, this method calls clearYear() since they cannot be used side by side.
	public void setReleaseMin(Date releaseMin) {
		if (releaseMin == null) {
			return;
		}
		this. = releaseMin;
		if ( == null || .before(releaseMin)) {
		}
	}

Sets the maximum release date a movie must have to appear in the results. If the minimum release date has not been set or if it has been set but is later than this date, this will set it to the earliest date available (epoch). If null is passed, it acts like calling clearReleases() . If not, this method calls clearYear() since they cannot be used side by side.

Parameters:
ratingMin The maximum release date a movie must have to appear in the results. If the minimum release date has not been set or if it has been set but is later than this date, this will set it to the earliest date available (epoch). If null is passed, it acts like calling clearReleases() . If not, this method calls clearYear() since they cannot be used side by side.
	public void setReleaseMax(Date releaseMax) {
		if (releaseMax == null) {
			return;
		}
		this. = releaseMax;
		if ( == null || .after(releaseMax)) {
			 = new Date(0);
		}
	}

Clears the year from the search.
	public void clearYear() {
		 = null;
	}

Gets the year setting for the search.

Returns:
The year setting for the search.
	public Integer getYear() {
		return ;
	}

Sets the year setting for the search. Must be greater or equal to 0. This will call clearReleases() since these settings cannot exist side by side.

Parameters:
year The year setting for the search. Must be greater or equal to 0. This will call clearReleases() since these settings cannot exist side by side.
	public void setYear(int year) {
		if (year < 0) {
			return;
		}
		this. = year;
	}

Clears the certifications from the search.
	public void clearCertifications() {
	}

Gets the certifications for the search.

Returns:
The certifications for the search.
	}

Add certifications to the search.

Parameters:
certifications The certifications to add to the search.
	public void addCertifications(String... certifications) {
		if (this. == null) {
		}
		for (String certification : certifications) {
			this..add(certification);
		}
	}

Removes certifications from the search.

Parameters:
certifications The certifications to remove from the search.
	public void removeCertifications(String... certifications) {
		if (this. != null) {
			for (String certification : certifications) {
				this..remove(certification);
			}
		}
	}

Clears the companies from the search.
	public void clearCompanies() {
		 = null;
	}

Gets the companies for the search.

Returns:
The companies for the search.
	public Set<StringgetCompanies() {
		return ;
	}

Adds companies to the search.

Parameters:
companies The companies to add to the search.
	public void addCompanies(String... companies) {
		if (this. == null) {
			this. = new LinkedHashSet<String>();
		}
		for (String company : companies) {
			this..add(company);
		}
	}

Removes companies from the search.

Parameters:
companies The companies to remove from the search.
	public void removeCompanies(String... companies) {
		if (this. != null) {
			for (String company : companies) {
				this..remove(company);
			}
		}
	}

Clears the countries from the search.
	public void clearCountries() {
		 = null;
	}

Gets the countries for the search.

Returns:
The countries for the search.
	public Set<StringgetCountries() {
		return ;
	}

Adds countries to the search.

Parameters:
countries The countries to add to the search.
	public void addCountries(String... countries) {
		if (this. == null) {
			this. = new LinkedHashSet<String>();
		}
		for (String country : countries) {
			this..add(country);
		}
	}

Removes countries from the search.

Parameters:
countries The countries to remove from the search.
	public void removeCountries(String... countries) {
		if (this. != null) {
			for (String country : countries) {
				this..remove(country);
			}
		}
	}

Clears the minimum amount of votes from the search.
	public void clearMinVotes() {
		this. = null;
	}

Gets the minimum amount of votes a Movie must have to appear in the results.

Returns:
The minimum amount of votes a Movie must have to appear in the results.
	public Integer getMinVotes() {
		return ;
	}

Sets the minimum amount of votes a Movie must have in order to appear in the results. Must be greater or equal to 0.

Parameters:
minVotes The minimum amount of votes a Movie must have in order to appear in the results. Must be greater or equal to 0.
	public void setMinVotes(int minVotes) {
		if (minVotes < 0) {
			return;
		}
		this. = minVotes;
	}

Builds the query to be appended to the call to the server.

Returns:
The query to be appended to the call to the server.
	protected String buildQuery() {
		StringBuffer buffer = new StringBuffer();
		buffer.append("order_by=").append(.getName()).append("&order=")
						(getPage() == null) ? "" : "&page=" + getPage())
						(getPerPage() == null) ? "" : "&per_page="
		String query = getQuery();
		if (query != null) {
			try {
				query = URLEncoder.encode(query"UTF-8");
				query = query.replaceAll(" ""%20");
			}
			buffer.append("&query=" + query);
		}
		buffer.append((getRatingMin() == null) ? "" : "&rating_min="
getRatingMin() + "&rating_max=" + getRatingMax());
		if (getGenres() != null && getGenres().size() > 0) {
			buffer.append("&genres=");
			for (int ID : getGenres()) {
				buffer.append(ID).append(",");
			}
			buffer.deleteCharAt(buffer.length() - 1);
			if (getGenres().size() > 1) {
				buffer.append("&genres_selector="
			}
		}
		buffer.append(
				( == null) ? "" : "&release_min="
						+ (getReleaseMin().getTime() / 1000) + "&release_max="
						+ (getReleaseMax().getTime() / 1000)).append(
				(getYear() == null) ? "" : "&year=" + getYear());
		if (getCertifications() != null && getCertifications().size() > 0) {
			buffer.append("&certifications=");
			for (String certification : getCertifications()) {
				buffer.append(certification).append(",");
			}
			buffer.deleteCharAt(buffer.length() - 1);
		}
		if (getCompanies() != null && getCompanies().size() > 0) {
			buffer.append("&companies=");
			for (String company : getCompanies()) {
				buffer.append(company).append(",");
			}
			buffer.deleteCharAt(buffer.length() - 1);
		}
		if (getCountries() != null && getCountries().size() > 0) {
			buffer.append("&countries=");
			for (String country : getCountries()) {
				buffer.append(country).append(",");
			}
			buffer.deleteCharAt(buffer.length() - 1);
		}
		buffer.append((getMinVotes() == null) ? "" : "&min_votes="
		return buffer.toString();
	}
New to GrepCode? Check out our FAQ X