javastrava.api.v3.model.reference.StravaPhotoSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javastrava-api Show documentation
Show all versions of javastrava-api Show documentation
Java implementation of the Strava API
/**
*
*/
package javastrava.api.v3.model.reference;
import javastrava.config.Messages;
import javastrava.config.StravaConfig;
import javastrava.json.impl.gson.serializer.ClimbCategorySerializer;
/**
* Identifies the source of a photo which has been attached to an activity
* @author Dan Shannon
*
*/
public enum StravaPhotoSource {
/**
* Photo uploaded directly to Strava
*/
STRAVA(StravaConfig.integer("StravaPhotoSource.strava"),Messages.string("StravaPhotoSource.strava.description")), //$NON-NLS-1$ //$NON-NLS-2$
/**
* Photo from Instagram
*/
INSTAGRAM(StravaConfig.integer("StravaPhotoSource.instagram"),Messages.string("StravaPhotoSource.instagram.description")), //$NON-NLS-1$ //$NON-NLS-2$
/**
* Unknown
*/
UNKNOWN(StravaConfig.integer("Common.unknown.integer"),Messages.string("Common.unknown.description")); //$NON-NLS-1$ //$NON-NLS-2$
/**
* Used by JSON deserialisation
* @param id The integer representation of the {@link StravaClimbCategory} as returned by the Strava API
* @return The matching {@link StravaClimbCategory}, or {@link StravaClimbCategory#UNKNOWN} if there is no match
* @see ClimbCategorySerializer#deserialize(com.google.gson.JsonElement, java.lang.reflect.Type, com.google.gson.JsonDeserializationContext)
*/
public static StravaPhotoSource create(final Integer id) {
final StravaPhotoSource[] sources = StravaPhotoSource.values();
for (final StravaPhotoSource source : sources) {
if (source.getId().equals(id)) {
return source;
}
}
return StravaPhotoSource.UNKNOWN;
}
/**
* Identifier
*/
private Integer id;
/**
* Description
*/
private String description;
/**
* Private constructor used by declarations
* @param id Identifier - also used when serialising/deserialising to JSON
* @param description Description
*/
private StravaPhotoSource(final Integer id, final String description) {
this.id = id;
this.description = description;
}
/**
* @return the description
*/
public String getDescription() {
return this.description;
}
/**
* @return the id
*/
public Integer getId() {
return this.id;
}
/**
* Used by JSON serialisation
* @return The integer value to be used with the Strava API
* @see ClimbCategorySerializer#serialize(StravaClimbCategory, java.lang.reflect.Type, com.google.gson.JsonSerializationContext)
*/
public Integer getValue() {
return this.id;
}
/**
* @see java.lang.Enum#toString()
*/
@Override
public String toString() {
return this.id.toString();
}
}