Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.savvasdalkitsis.jtmdb;
  
  import java.net.URL;
  import java.util.Set;
  
 
 import  org.json.JSONArray;
 import  org.json.JSONException;
 import  org.json.JSONObject;
 
This class represents a movie Genre.

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

The url of the Genre.
 
 	private URL url;
The name of the Genre.
 
 	private String name;
The ID of the Genre.
 
 	private int ID;

Constructs a Genre with the given URL, name and ID.

Parameters:
url The URL of the Genre.
name The name of the Genre.
ID The ID of the Genre.
 
 	public Genre(URL urlString nameint ID) {
 		Log.log("Creating Genre object with url: "
 				+ ((url == null) ? "NULL" : url.toString()) + ", name: " + name
 				+ " and ID: " + ID.);
 		setUrl(url);
 		setName(name);
 		setID(ID);
 	}
 
 	public boolean equals(Object obj) {
 		if (obj == this) {
 			return true;
 		}
 		if (obj instanceof Genre) {
 			return ((Genreobj).getID() == getID();
 		}
 		return false;
 	}
 
 	public int hashCode() {
 		return getID();
 	}

The URL of the Genre.

Returns:
The URL of the Genre.
 
 	public URL getUrl() {
 		return ;
 	}

Sets the URL of the Genre.

Parameters:
url The URL of the Genre.
 
 	public void setUrl(URL url) {
 		this. = url;
 	}

The name of the Genre.

Returns:
The name of the Genre.
 
 	public String getName() {
		return ;
	}

Sets the name of the Genre.

Parameters:
name The name of the Genre.
	public void setName(String name) {
		this. = name;
	}

The ID of the Genre.

Returns:
The ID of the Genre.
	public int getID() {
		return ;
	}

Sets the ID of the Genre.

Parameters:
ID The ID of the Genre.
	public void setID(int ID) {
		this. = ID;
	}

Gets the list of valid genres within TMDb. You can also request the translated values by setting the language option in the GeneralSettings. Returns a Pair of objects. The first object is a boolean that denotes if the list is translated. The second is the list of Genres. Will return null if a valid API key was not supplied to the GeneralSettings.

Returns:
Returns a Pair of objects. The first object is a boolean that denotes if the list is translated. The second is the list of Genres. Will return null if a valid API key was not supplied to the GeneralSettings.
Throws:
IOException
JSONException
	public static Pair<BooleanSet<Genre>> getList() throws IOException,
			JSONException {
		Log.log("Getting list of Genres".);
		if (GeneralSettings.getApiKey() != null
				&& !GeneralSettings.getApiKey().equals("")) {
			try {
						+ GeneralSettings.getAPILocaleFormatted() + "/"
						+ GeneralSettings.getApiKey());
				String jsonString = Utilities.readUrlResponse(call).trim();
				if ((jsonString.startsWith("[") || jsonString.startsWith("{"))
						&& !jsonString.equals("[\"Nothing found.\"]")) {
					JSONArray jsonArray = new JSONArray(jsonString.toString());
					JSONObject jsonObject = jsonArray.getJSONObject(0);
					boolean translated = jsonObject.getBoolean("translated");
					Set<Genregenres = new LinkedHashSet<Genre>();
					for (int i = 1; i < jsonArray.length(); i++) {
						jsonObject = jsonArray.getJSONObject(i);
						String genreName = jsonObject.getString("name");
						URL genreUrl = null;
						try {
							genreUrl = new URL(jsonObject.getString("url"));
catch (MalformedURLException e) {
						}
						int ID = jsonObject.getInt("id");
						genres.add(new Genre(genreUrlgenreNameID));
					}
					return new Pair<BooleanSet<Genre>>(translatedgenres);
else {
					Log.log("Getting list of Genres returned no results",
				}
catch (IOException e) {
				throw e;
catch (JSONException e) {
				throw e;
			}
else {
			Log.log("Error with the API key".);
		}
		return null;
	}
New to GrepCode? Check out our FAQ X