package fachklassen;

public class Produkt {

    private static int idGenerator = 1000;
    private int id;
    private String name;
    private long preis; // in Cent

    public Produkt() {
        this.id = idGenerator++;
    }

    public Produkt(String name, long preis) {
        this.id = idGenerator++;
        this.name = name;
        this.preis = preis;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public long getPreis() {
        return preis;
    }

    public void setPreis(long preis) {
        this.preis = preis;
    }

    @Override
    public String toString() {
        return "Produkt [id=" + id + ", name=" + name 
                + ", preis=" + preis + "]";
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + id;
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        result = prime * result + (int) (preis ^ (preis >>> 32));
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        Produkt other = (Produkt) obj;
        if (id != other.id) {
            return false;
        }
        if (name == null) {
            if (other.name != null) {
                return false;
            }
        } else if (!name.equals(other.name)) {
            return false;
        }
        if (preis != other.preis) {
            return false;
        }
        return true;
    }

}
