1 //---------------------------------------------------------------------- 2 // 3 // PerfectJPattern: "Design patterns are good but components are better!" 4 // Product.java Copyright (c) 2009 Giovanni Azua Garcia 5 // bravegag@hotmail.com 6 // 7 // This program is free software; you can redistribute it and/or 8 // modify it under the terms of the GNU General Public License 9 // as published by the Free Software Foundation; either version 3 10 // of the License, or (at your option) any later version. 11 // 12 // This program is distributed in the hope that it will be useful, 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 // GNU General Public License for more details. 16 // 17 // You should have received a copy of the GNU General Public License 18 // along with this program; if not, see <http://www.gnu.org/licenses/>. 19 // 20 //---------------------------------------------------------------------- 21 package org.perfectjpattern.example.datamodel; 22 23 import java.util.*; 24 25 /** 26 * Product Data model object 27 * 28 * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a> 29 * @version $ $Date: Dec 5, 2008 2:59:45 AM $ 30 */ 31 public 32 class Product 33 { 34 //------------------------------------------------------------------------ 35 // public 36 //------------------------------------------------------------------------ 37 public 38 Product() 39 { 40 // do nothing 41 } 42 43 //------------------------------------------------------------------------ 44 public 45 Product(String aName, double aListPrice) 46 { 47 theName = aName; 48 theListPrice = aListPrice; 49 theOrders = new HashSet<Order>(); 50 } 51 52 //------------------------------------------------------------------------ 53 /** 54 * Returns the id 55 * 56 * @return the id 57 */ 58 public long 59 getId() 60 { 61 return theId; 62 } 63 64 //------------------------------------------------------------------------ 65 /** 66 * Sets the id of the person 67 * 68 * @param anId the id to set 69 */ 70 public void 71 setId(long anId) 72 { 73 theId = anId; 74 } 75 76 //------------------------------------------------------------------------ 77 /** 78 * Returns the name 79 * 80 * @return the name 81 */ 82 public String 83 getName() 84 { 85 return theName; 86 } 87 88 //------------------------------------------------------------------------ 89 /** 90 * Sets the name of the person 91 * 92 * @param anName the name to set 93 */ 94 public void 95 setName(String anName) 96 { 97 theName = anName; 98 } 99 100 //------------------------------------------------------------------------ 101 /** 102 * Returns the listPrice 103 * 104 * @return the listPrice 105 */ 106 public double 107 getListPrice() 108 { 109 return theListPrice; 110 } 111 112 //------------------------------------------------------------------------ 113 /** 114 * Sets the listPrice 115 * 116 * @param aListPrice the listPrice to set 117 */ 118 public void 119 setListPrice(double aListPrice) 120 { 121 theListPrice = aListPrice; 122 } 123 124 //------------------------------------------------------------------------ 125 /** 126 * Returns the orders 127 * 128 * @return the orders 129 */ 130 public Set<Order> 131 getOrders() 132 { 133 return theOrders; 134 } 135 136 //------------------------------------------------------------------------ 137 /** 138 * Sets the orders 139 * 140 * @param anOrders the orders to set 141 */ 142 public void 143 setOrders(Set<Order> anOrders) 144 { 145 theOrders = anOrders; 146 } 147 148 //------------------------------------------------------------------------ 149 /** 150 * {@inheritDoc} 151 */ 152 @Override 153 public final int 154 hashCode() 155 { 156 final int myPrime = 31; 157 158 int myResult = 1; 159 myResult = myPrime * myResult + ((theName == null) 160 ? 0 : theName.hashCode()); 161 162 return myResult; 163 } 164 165 //------------------------------------------------------------------------ 166 /** 167 * {@inheritDoc} 168 */ 169 @Override 170 public final boolean 171 equals(Object anAnother) 172 { 173 if (this == anAnother) 174 { 175 return true; 176 } 177 178 if (anAnother == null) 179 { 180 return false; 181 } 182 183 if (!(anAnother instanceof Product)) 184 { 185 return false; 186 } 187 188 final Product myAnother = (Product) anAnother; 189 return (getName() == null && myAnother.getName() == null) || 190 (getName() != null && myAnother.getName() != null 191 && getName().equals(myAnother.getName())); 192 } 193 194 //------------------------------------------------------------------------ 195 // members 196 //------------------------------------------------------------------------ 197 private long theId; 198 private String theName; 199 private double theListPrice; 200 private Set<Order> theOrders; 201 }