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

info.freelibrary.iiif.presentation.v3.services.AbstractOtherService Maven / Gradle / Ivy

There is a newer version: 0.12.4
Show newest version

package info.freelibrary.iiif.presentation.v3.services;

import java.util.Optional;

import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;

import info.freelibrary.util.warnings.JDK;

import info.freelibrary.iiif.presentation.v3.MediaType;
import info.freelibrary.iiif.presentation.v3.Service;
import info.freelibrary.iiif.presentation.v3.utils.JsonKeys;

/**
 * An abstract class for other services.
 *
 * @param  The type of other service
 */
abstract class AbstractOtherService> extends AbstractService
        implements OtherService {

    /**
     * This service's format.
     */
    @JsonProperty(JsonKeys.FORMAT)
    protected MediaType myFormat;

    /**
     * This service's profile.
     */
    @JsonProperty(JsonKeys.PROFILE)
    protected OtherService.Profile myProfile;

    @Override
    @JsonGetter(JsonKeys.PROFILE)
    @JsonInclude(Include.NON_ABSENT)
    public Optional getProfile() {
        return Optional.ofNullable(myProfile);
    }

    @Override
    @SuppressWarnings(JDK.UNCHECKED)
    public T setProfile(final OtherService.Profile aProfile) {
        myProfile = aProfile;
        return (T) this;
    }

    @Override
    public abstract T setProfile(String aProfile);

    @Override
    @SuppressWarnings(JDK.UNCHECKED)
    public T setFormat(final MediaType aFormat) {
        myFormat = aFormat;
        return (T) this;
    }

    @Override
    @SuppressWarnings(JDK.UNCHECKED)
    public T setFormat(final String aFormat) {
        MediaType.fromString(aFormat).ifPresentOrElse(format -> myFormat = format, () -> myFormat = null);
        return (T) this;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy