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

com.urbanairship.api.push.model.notification.ios.Crop Maven / Gradle / Ivy

There is a newer version: 9.4.2
Show newest version
/*
 * Copyright (c) 2013-2016.  Urban Airship and Contributors
 */
package com.urbanairship.api.push.model.notification.ios;

import com.urbanairship.api.push.model.PushModelObject;

import java.math.BigDecimal;
import java.util.Optional;

/**
 * Crop for iOS specific media push messages.
 */
public final class Crop extends PushModelObject{

    private final Optional x;
    private final Optional y;
    private final Optional height;
    private final Optional width;

    private Crop(Optional x, Optional y, Optional height, Optional width) {
        this.x = x;
        this.y = y;
        this.height = height;
        this.width = width;
    }

    /**
     * Get a Crop builder object that describes the crop parameters to be used in the thumbnail.
     * Each field is a decimal, normalized from 0 to 1
     * @return Builder
     */
    public static Builder newBuilder() {
        return new Builder();
    }

    /**
     * Get the x BigDecimal offset value where the crop begins.
     * @return Optional BigDecimal representation of x
     */
    public Optional getX() {
        return x;
    }

    /**
     * Get the y BigDecimal offset value where the crop begins.
     * @return Optional BigDecimal representation of y
     */
    public Optional getY() {
        return y;
    }

    /**
     * Get the BigDecimal height of the final crop.
     * @return Optional BigDecimal representation of the height
     */
    public Optional getHeight() {
        return height;
    }

    /**
     * Get the BigDecimal width of the final crop.
     * @return Optional BigDecimal representation of the width
     */
    public Optional getWidth() {
        return width;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Crop that = (Crop)o;
        if (x != null ? !x.equals(that.x) : that.x != null) {
            return false;
        }
        if (y != null ? !y.equals(that.y) : that.y != null) {
            return false;
        }
        if (height != null ? !height.equals(that.height) : that.height != null) {
            return false;
        }
        if (width != null ? !width.equals(that.width) : that.width != null) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int result = (x != null ? x.hashCode() : 0);
        result = 31 * result + (y != null ? y.hashCode() : 0);
        result = 31 * result + (height != null ? height.hashCode() : 0);
        result = 31 * result + (width != null ? width.hashCode() : 0);
        return  result;
    }

    @Override
    public String toString() {
        return "Crop{" +
                "x=" + x +
                ", y=" + y +
                ", height=" + height +
                ", width=" + width +
                '}';
    }

    public static class Builder {
        private BigDecimal x = null;
        private BigDecimal y = null;
        private BigDecimal height = null;
        private BigDecimal width = null;

        private Builder() { }

        /**
         * Set the x value where offset crop begins
         * @param x BigDecimal
         * @return Builder
         **/
        public Builder setX(BigDecimal x) {
            this.x = x;
            return this;
        }

        /**
         * Set the y value where offset crop begins
         * @param y BigDecimal
         * @return Builder
         **/
        public Builder setY(BigDecimal y) {
            this.y = y;
            return this;
        }

        /**
         * Set the height of the final crop
         * @param height BigDecimal
         * @return Builder
         **/
        public Builder setHeight(BigDecimal height) {
            this.height = height;
            return this;
        }

        /**
         * Set the width of the final crop
         * @param width BigDecimal
         * @return Builder
         **/
        public Builder setWidth(BigDecimal width) {
            this.width = width;
            return this;
        }

        /**
         * Build Crop
         * @return Crop
         */
        public Crop build() {
            return new Crop(Optional.ofNullable(x),
                            Optional.ofNullable(y),
                            Optional.ofNullable(height),
                            Optional.ofNullable(width));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy