Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete static fields #11

Open
manland opened this issue Feb 28, 2017 · 1 comment
Open

Delete static fields #11

manland opened this issue Feb 28, 2017 · 1 comment

Comments

@manland
Copy link
Owner

manland commented Feb 28, 2017

Delete static fields :

public static final class Builder {}
@jmclagniez
Copy link
Contributor

import java.time.LocalDate;
import java.util.Objects;

public class WeatherDailyOutputDto {

    private final double minTemp;
    private final double maxTemp;
    private final LocalDate date;
    private final double precipitation;

    public WeatherDailyOutputDto(double minTemp, double maxTemp, LocalDate date, double precipitation) {
        this.minTemp = minTemp;
        this.maxTemp = maxTemp;
        this.date = date;
        this.precipitation = precipitation;
    }

    private WeatherDailyOutputDto(Builder builder) {
        minTemp = builder.minTemp;
        maxTemp = builder.maxTemp;
        date = builder.date;
        precipitation = builder.precipitation;
    }

    public static Builder builder() {
        return new Builder();
    }

    public LocalDate getDate() {
        return date;
    }

    public double getMinTemp() {
        return minTemp;
    }

    public double getMaxTemp() {
        return maxTemp;
    }

    public double getPrecipitation() {
        return precipitation;
    }

    @Override
    public final boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof WeatherDailyOutputDto)) return false;
        WeatherDailyOutputDto that = (WeatherDailyOutputDto) o;
        return Double.compare(that.minTemp, minTemp) == 0 &&
                Double.compare(that.maxTemp, maxTemp) == 0 &&
                Double.compare(that.precipitation, precipitation) == 0 &&
                Objects.equals(date, that.date);
    }

    @Override
    public final int hashCode() {
        return Objects.hash(minTemp, maxTemp, date, precipitation);
    }


    public static final class Builder {
        private double minTemp;
        private double maxTemp;
        private LocalDate date;
        private double precipitation;

        public Builder() {
        }

        public Builder setMinTemp(double val) {
            minTemp = val;
            return this;
        }

        public Builder setMaxTemp(double val) {
            maxTemp = val;
            return this;
        }

        public Builder setDate(LocalDate val) {
            date = val;
            return this;
        }

        public Builder setPrecipitation(double val) {
            precipitation = val;
            return this;
        }

        public WeatherDailyOutputDto build() {
            return new WeatherDailyOutputDto(this);
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants