Java tutorial
/* * Copyright 2013-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.tudresden.ecatering.model.stock; import java.time.LocalDate; import javax.persistence.Entity; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; import org.javamoney.moneta.Money; import org.salespointframework.catalog.Product; import org.salespointframework.inventory.InventoryItem; import org.salespointframework.quantity.Quantity; @Entity public class Ingredient extends InventoryItem { private static final long serialVersionUID = 8953308785426506433L; private LocalDate expirationDate; //need default constructor @SuppressWarnings({ "unused", "deprecation" }) private Ingredient() { } protected Ingredient(String name, Money price, Quantity quantity, LocalDate expirationDate) { super(new Product(name, price, quantity.getMetric()), quantity); if (expirationDate != null) if (expirationDate.isBefore(LocalDate.now())) throw new IllegalArgumentException("expirationDate already expired"); this.expirationDate = expirationDate; } protected Ingredient(String name, Money price, Quantity quantity) { this(name, price, quantity, null); } public LocalDate getExpirationDate() { return this.expirationDate; } @Override public int hashCode() { return new HashCodeBuilder(19, 91).append(super.hashCode()).append(expirationDate).toHashCode(); } @Override public boolean equals(Object obj) { return EqualsBuilder.reflectionEquals(this, obj); } @Override public String toString() { return ToStringBuilder.reflectionToString(this); } }