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

com.wrapper.spotify.model_objects.specification.AlbumSimplified Maven / Gradle / Ivy

There is a newer version: 9.0.0-RC1
Show newest version
package com.wrapper.spotify.model_objects.specification;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.neovisionaries.i18n.CountryCode;
import com.wrapper.spotify.enums.AlbumType;
import com.wrapper.spotify.enums.ModelObjectType;
import com.wrapper.spotify.model_objects.AbstractModelObject;
import com.wrapper.spotify.requests.data.search.interfaces.ISearchModelObject;

/**
 * Retrieve information about 
 * simplified Album objects by building instances from this class.
 */
public class AlbumSimplified extends AbstractModelObject implements ISearchModelObject {
  private final AlbumType albumType;
  private final ArtistSimplified[] artists;
  private final CountryCode[] availableMarkets;
  private final ExternalUrl externalUrls;
  private final String href;
  private final String id;
  private final Image[] images;
  private final String name;
  private final ModelObjectType type;
  private final String uri;

  private AlbumSimplified(final Builder builder) {
    super(builder);

    this.albumType = builder.albumType;
    this.artists = builder.artists;
    this.availableMarkets = builder.availableMarkets;
    this.externalUrls = builder.externalUrls;
    this.href = builder.href;
    this.id = builder.id;
    this.images = builder.images;
    this.name = builder.name;
    this.type = builder.type;
    this.uri = builder.uri;
  }

  /**
   * Get the type of the album.
   *
   * @return The {@link AlbumType}.
   */
  public AlbumType getAlbumType() {
    return albumType;
  }

  /**
   * Get the artists of the album.
   *
   * @return An array of {@link ArtistSimplified} objects.
   */
  public ArtistSimplified[] getArtists() {
    return artists;
  }

  /**
   * Get the country codes of all countries, in which the album is available.
   *
   * @return An array of ISO 3166-1 alpha-2 country
   * codes.
   */
  public CountryCode[] getAvailableMarkets() {
    return availableMarkets;
  }

  /**
   * Get the external URLs of the album. 
* Example: Spotify-URL * * @return An {@link ExternalUrl} object. */ public ExternalUrl getExternalUrls() { return externalUrls; } /** * Get the full Spotify Web API endpoint URL of the album. * * @return A Spotify Web API endpoint URL. */ public String getHref() { return href; } /** * Get the Spotify ID of the album. * * @return A Spotify album ID. */ public String getId() { return id; } /** * Get the album cover art of the album in different sizes. * * @return An array of {@link Image} objects. */ public Image[] getImages() { return images; } /** * Get the name of the album. * * @return Album name. */ public String getName() { return name; } /** * Get the model object type. In this case "album". * * @return A {@link ModelObjectType}. */ public ModelObjectType getType() { return type; } /** * Get the Spotify URI of the album. * * @return Spotify album URI. */ public String getUri() { return uri; } @Override public Builder builder() { return new Builder(); } /** * Builder class for building {@link AlbumSimplified} instances. */ public static final class Builder extends AbstractModelObject.Builder { private AlbumType albumType; private ArtistSimplified[] artists; private CountryCode[] availableMarkets; private ExternalUrl externalUrls; private String href; private String id; private Image[] images; private String name; private ModelObjectType type; private String uri; /** * Set the type of the album to be built. * * @param albumType The {@link AlbumType}. * @return A {@link Album.Builder}. */ public Builder setAlbumType(AlbumType albumType) { this.albumType = albumType; return this; } /** * Set the artists of the album to be built. * * @param artists {@link ArtistSimplified} objects. * @return A {@link Album.Builder}. */ public Builder setArtists(ArtistSimplified... artists) { this.artists = artists; return this; } /** * Set the available markets of the album to be built. * * @param availableMarkets * ISO 3166-1 alpha-2 country codes. * @return A {@link Album.Builder}. */ public Builder setAvailableMarkets(CountryCode... availableMarkets) { this.availableMarkets = availableMarkets; return this; } /** * Set external URLs of the album to be built. * * @param externalUrls {@link ExternalUrl} object. * @return A {@link Album.Builder}. */ public Builder setExternalUrls(ExternalUrl externalUrls) { this.externalUrls = externalUrls; return this; } /** * Set href of Spotify Web API endpoint of the album to be built. * * @param href Spotify Web API endpoint URL. * @return A {@link Album.Builder}. */ public Builder setHref(String href) { this.href = href; return this; } /** * Set album ID of the album to be built. * * @param id Spotify album ID. * @return A {@link Album.Builder}. */ public Builder setId(String id) { this.id = id; return this; } /** * Set the cover art in different sizes of the album to be built. * * @param images {@link Image} objects. * @return A {@link Album.Builder}. */ public Builder setImages(Image... images) { this.images = images; return this; } /** * Set the name of the album to be built. * * @param name The album name. * @return A {@link Album.Builder}. */ public Builder setName(String name) { this.name = name; return this; } /** * Set the type of the model object. In this case "album". * * @param type The {@link ModelObjectType}. * @return A {@link Album.Builder}. */ public Builder setType(ModelObjectType type) { this.type = type; return this; } /** * Set the Spotify album URI of the album to be built. * * @param uri * Spotify album URI. * @return A {@link Album.Builder}. */ public Builder setUri(String uri) { this.uri = uri; return this; } @Override public AlbumSimplified build() { return new AlbumSimplified(this); } } /** * JsonUtil class for building {@link AlbumSimplified} instances. */ public static final class JsonUtil extends AbstractModelObject.JsonUtil { public AlbumSimplified createModelObject(JsonObject jsonObject) { if (jsonObject == null || jsonObject.isJsonNull()) { return null; } return new AlbumSimplified.Builder() .setAlbumType( hasAndNotNull(jsonObject, "album_type") ? AlbumType.keyOf( jsonObject.get("album_type").getAsString().toLowerCase()) : null) .setArtists( hasAndNotNull(jsonObject, "artists") ? new ArtistSimplified.JsonUtil().createModelObjectArray( jsonObject.getAsJsonArray("artists")) : null) .setAvailableMarkets( hasAndNotNull(jsonObject, "available_markets") ? new Gson().fromJson( jsonObject.get("available_markets"), CountryCode[].class) : null) .setExternalUrls( hasAndNotNull(jsonObject, "external_urls") ? new ExternalUrl.JsonUtil().createModelObject( jsonObject.getAsJsonObject("external_urls")) : null) .setHref( hasAndNotNull(jsonObject, "href") ? jsonObject.get("href").getAsString() : null) .setId( hasAndNotNull(jsonObject, "id") ? jsonObject.get("id").getAsString() : null) .setImages( hasAndNotNull(jsonObject, "images") ? new Image.JsonUtil().createModelObjectArray( jsonObject.getAsJsonArray("images")) : null) .setName( hasAndNotNull(jsonObject, "name") ? jsonObject.get("name").getAsString() : null) .setType( hasAndNotNull(jsonObject, "type") ? ModelObjectType.keyOf( jsonObject.get("type").getAsString().toLowerCase()) : null) .setUri( hasAndNotNull(jsonObject, "uri") ? jsonObject.get("uri").getAsString() : null) .build(); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy