Skip to content

Instantly share code, notes, and snippets.

@kostoww
Created June 16, 2019 17:44
Show Gist options
  • Save kostoww/84b224a681046691bf145cc554738d78 to your computer and use it in GitHub Desktop.
Save kostoww/84b224a681046691bf145cc554738d78 to your computer and use it in GitHub Desktop.
Sample beers class
package demo.demo.demo21;
import javax.persistence.*;
import java.util.Objects;
@Entity
public class Beer {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String name;
private String model;
private double quantity;
private double abv;
private String style;
private String country;
private String color;
private String pictureUrl;
@Lob
private String description;
public Beer() {
}
private Beer(String name, String model, double quantity, double abv, String style, String country, String color, String pictureUrl, String description) {
this.name = name;
this.model = model;
this.quantity = quantity;
this.abv = abv;
this.style = style;
this.country = country;
this.color = color;
this.pictureUrl = pictureUrl;
this.description = description;
}
@Override
public String toString() {
return "Beer{" +
"id='" + id + '\'' +
"name='" + name + '\'' +
", model='" + model + '\'' +
", quantity=" + quantity +
", abv=" + abv +
", style='" + style + '\'' +
", country='" + country + '\'' +
", color='" + color + '\'' +
", pictureUrl='" + pictureUrl + '\'' +
", description='" + description + '\'' +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Beer beer = (Beer) o;
return Double.compare(beer.quantity, quantity) == 0 &&
Double.compare(beer.abv, abv) == 0 &&
beer.id == id &&
Objects.equals(name, beer.name) &&
Objects.equals(model, beer.model) &&
Objects.equals(style, beer.style) &&
Objects.equals(country, beer.country) &&
Objects.equals(color, beer.color) &&
Objects.equals(pictureUrl, beer.pictureUrl) &&
Objects.equals(description, beer.description);
}
@Override
public int hashCode() {
return Objects.hash(id, name, model, quantity, abv, style, country, color, pictureUrl, description);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public double getQuantity() {
return quantity;
}
public void setQuantity(double quantity) {
this.quantity = quantity;
}
public double getAbv() {
return abv;
}
public void setAbv(double abv) {
this.abv = abv;
}
public String getStyle() {
return style;
}
public void setStyle(String style) {
this.style = style;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getPictureUrl() {
return pictureUrl;
}
public void setPictureUrl(String pictureUrl) {
this.pictureUrl = pictureUrl;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public static class Builder {
private String name;
private String model;
private double quantity;
private double abv;
private String style;
private String country;
private String color;
private String pictureUrl;
private String description;
public Builder name(String name) {
this.name = name;
return this;
}
public Builder model(String model) {
this.model = model;
return this;
}
public Builder quantity(double quantity) {
this.quantity = quantity;
return this;
}
public Builder abv(double abv) {
this.abv = abv;
return this;
}
public Builder style(String style) {
this.style = style;
return this;
}
public Builder country(String country) {
this.country = country;
return this;
}
public Builder color(String color) {
this.color = color;
return this;
}
public Builder pictureUrl(String pictureUrl) {
this.pictureUrl = pictureUrl;
return this;
}
public Builder description(String description) {
this.description = description;
return this;
}
public Beer createBeer() {
return new Beer(name, model, quantity, abv, style, country, color, pictureUrl, description);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment