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

io.sphere.sdk.products.Image Maven / Gradle / Ivy

There is a newer version: 1.0.0-M26
Show newest version
package io.sphere.sdk.products;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import javax.annotation.Nullable;

@JsonDeserialize(as=ImageImpl.class)
public interface Image {
    String getUrl();

    ImageDimensions getDimensions();

    @Nullable
    String getLabel();

    static Image of(final String url, final ImageDimensions dimensions, @Nullable final String label) {
        return ImageImpl.of(url, dimensions, label);
    }

    static Image ofWidthAndHeight(final String url, final Integer width, final Integer height, @Nullable final String label) {
        return of(url, ImageDimensions.of(width, height), label);
    }

    static Image ofWidthAndHeight(final String url, final Integer width, final Integer height) {
        return of(url, ImageDimensions.of(width, height), null);
    }

    static Image of(final String url, final ImageDimensions dimensions) {
        return of(url, dimensions, null);
    }

    @JsonIgnore
    default Integer getWidth() {
        return getDimensions().getWidth();
    }

    @JsonIgnore
    default Integer getHeight() {
        return getDimensions().getHeight();
    }

    static TypeReference typeReference() {
        return new TypeReference() {
            @Override
            public String toString() {
                return "TypeReference";
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy