001/**
002 * Copyright 2004-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.kpme.tklm.api.time.timehourdetail;
017
018import java.io.Serializable;
019import java.math.BigDecimal;
020import java.util.Collection;
021import javax.xml.bind.annotation.XmlAccessType;
022import javax.xml.bind.annotation.XmlAccessorType;
023import javax.xml.bind.annotation.XmlAnyElement;
024import javax.xml.bind.annotation.XmlElement;
025import javax.xml.bind.annotation.XmlRootElement;
026import javax.xml.bind.annotation.XmlType;
027
028import org.apache.commons.lang.builder.EqualsBuilder;
029import org.kuali.kpme.core.api.util.KpmeUtils;
030import org.kuali.rice.core.api.CoreConstants;
031import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
032import org.kuali.rice.core.api.mo.ModelBuilder;
033import org.w3c.dom.Element;
034
035@XmlRootElement(name = TimeHourDetail.Constants.ROOT_ELEMENT_NAME)
036@XmlAccessorType(XmlAccessType.NONE)
037@XmlType(name = TimeHourDetail.Constants.TYPE_NAME, propOrder = {
038        TimeHourDetail.Elements.HOURS,
039        TimeHourDetail.Elements.TK_TIME_BLOCK_ID,
040        TimeHourDetail.Elements.TK_TIME_HOUR_DETAIL_ID,
041        TimeHourDetail.Elements.EARN_CODE,
042        TimeHourDetail.Elements.AMOUNT,
043        CoreConstants.CommonElements.VERSION_NUMBER,
044        CoreConstants.CommonElements.OBJECT_ID,
045        CoreConstants.CommonElements.FUTURE_ELEMENTS
046})
047public final class TimeHourDetail
048        extends AbstractDataTransferObject
049        implements TimeHourDetailContract
050{
051
052    @XmlElement(name = Elements.HOURS, required = false)
053    private final BigDecimal hours;
054    @XmlElement(name = Elements.TK_TIME_BLOCK_ID, required = false)
055    private final String tkTimeBlockId;
056    @XmlElement(name = Elements.TK_TIME_HOUR_DETAIL_ID, required = false)
057    private final String tkTimeHourDetailId;
058    @XmlElement(name = Elements.EARN_CODE, required = false)
059    private final String earnCode;
060    @XmlElement(name = Elements.AMOUNT, required = false)
061    private final BigDecimal amount;
062    @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
063    private final Long versionNumber;
064    @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
065    private final String objectId;
066    @SuppressWarnings("unused")
067    @XmlAnyElement
068    private final Collection<Element> _futureElements = null;
069
070    /**
071     * Private constructor used only by JAXB.
072     *
073     */
074    private TimeHourDetail() {
075        this.hours = null;
076        this.tkTimeBlockId = null;
077        this.tkTimeHourDetailId = null;
078        this.earnCode = null;
079        this.amount = null;
080        this.versionNumber = null;
081        this.objectId = null;
082    }
083
084    private TimeHourDetail(Builder builder) {
085        this.hours = builder.getHours();
086        this.tkTimeBlockId = builder.getTkTimeBlockId();
087        this.tkTimeHourDetailId = builder.getTkTimeHourDetailId();
088        this.earnCode = builder.getEarnCode();
089        this.amount = builder.getAmount();
090        this.versionNumber = builder.getVersionNumber();
091        this.objectId = builder.getObjectId();
092    }
093
094    @Override
095    public BigDecimal getHours() {
096        return this.hours;
097    }
098
099    @Override
100    public String getTkTimeBlockId() {
101        return this.tkTimeBlockId;
102    }
103
104    @Override
105    public String getTkTimeHourDetailId() {
106        return this.tkTimeHourDetailId;
107    }
108
109    @Override
110    public String getEarnCode() {
111        return this.earnCode;
112    }
113
114    @Override
115    public BigDecimal getAmount() {
116        return this.amount;
117    }
118
119    @Override
120    public Long getVersionNumber() {
121        return this.versionNumber;
122    }
123
124    @Override
125    public String getObjectId() {
126        return this.objectId;
127    }
128
129    @Override
130    public boolean equals(Object obj) {
131        if (obj == null) {
132            return false;
133        }
134        if (obj == this) {
135            return true;
136        }
137        if (obj.getClass() != getClass()) {
138            return false;
139        }
140        TimeHourDetailContract timeHourDetail = (TimeHourDetailContract) obj;
141        return new EqualsBuilder()
142                .append(earnCode, timeHourDetail.getEarnCode())
143                .append(KpmeUtils.nullSafeCompare(amount, timeHourDetail.getAmount()), 0)
144                .append(KpmeUtils.nullSafeCompare(hours, timeHourDetail.getHours()), 0)
145                .isEquals();
146    }
147
148    /**
149     * A builder which can be used to construct {@link TimeHourDetail} instances.  Enforces the constraints of the {@link TimeHourDetailContract}.
150     *
151     */
152    public final static class Builder
153            implements Serializable, TimeHourDetailContract, ModelBuilder
154    {
155
156        private BigDecimal hours;
157        private String tkTimeBlockId;
158        private String tkTimeHourDetailId;
159        private String earnCode;
160        private BigDecimal amount;
161        private Long versionNumber;
162        private String objectId;
163
164        private Builder() {
165
166        }
167
168        public static Builder create() {
169
170            return new Builder();
171        }
172
173        public static Builder create(TimeHourDetailContract contract) {
174            if (contract == null) {
175                throw new IllegalArgumentException("contract was null");
176            }
177
178            Builder builder = create();
179            builder.setHours(contract.getHours());
180            builder.setTkTimeBlockId(contract.getTkTimeBlockId());
181            builder.setTkTimeHourDetailId(contract.getTkTimeHourDetailId());
182            builder.setEarnCode(contract.getEarnCode());
183            builder.setAmount(contract.getAmount());
184            builder.setVersionNumber(contract.getVersionNumber());
185            builder.setObjectId(contract.getObjectId());
186            return builder;
187        }
188
189        public TimeHourDetail build() {
190            return new TimeHourDetail(this);
191        }
192
193        @Override
194        public BigDecimal getHours() {
195            return this.hours;
196        }
197
198        @Override
199        public String getTkTimeBlockId() {
200            return this.tkTimeBlockId;
201        }
202
203        @Override
204        public String getTkTimeHourDetailId() {
205            return this.tkTimeHourDetailId;
206        }
207
208        @Override
209        public String getEarnCode() {
210            return this.earnCode;
211        }
212
213        @Override
214        public BigDecimal getAmount() {
215            return this.amount;
216        }
217
218        @Override
219        public Long getVersionNumber() {
220            return this.versionNumber;
221        }
222
223        @Override
224        public String getObjectId() {
225            return this.objectId;
226        }
227
228        public void setHours(BigDecimal hours) {
229
230            this.hours = hours;
231        }
232
233        public void setTkTimeBlockId(String tkTimeBlockId) {
234
235            this.tkTimeBlockId = tkTimeBlockId;
236        }
237
238        public void setTkTimeHourDetailId(String tkTimeHourDetailId) {
239
240            this.tkTimeHourDetailId = tkTimeHourDetailId;
241        }
242
243        public void setEarnCode(String earnCode) {
244
245            this.earnCode = earnCode;
246        }
247
248        public void setAmount(BigDecimal amount) {
249
250            this.amount = amount;
251        }
252
253        public void setVersionNumber(Long versionNumber) {
254
255            this.versionNumber = versionNumber;
256        }
257
258        public void setObjectId(String objectId) {
259
260            this.objectId = objectId;
261        }
262
263        @Override
264        public boolean equals(Object obj) {
265            if (obj == null) {
266                return false;
267            }
268            if (obj == this) {
269                return true;
270            }
271            if (obj.getClass() != getClass()) {
272                return false;
273            }
274            TimeHourDetailContract timeHourDetail = (TimeHourDetailContract) obj;
275            return new EqualsBuilder()
276                    .append(earnCode, timeHourDetail.getEarnCode())
277                    .append(amount, timeHourDetail.getAmount())
278                    .append(hours, timeHourDetail.getHours())
279                    .isEquals();
280        }
281
282    }
283
284
285    /**
286     * Defines some internal constants used on this class.
287     *
288     */
289    static class Constants {
290
291        final static String ROOT_ELEMENT_NAME = "timeHourDetail";
292        final static String TYPE_NAME = "TimeHourDetailType";
293
294    }
295
296
297    /**
298     * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
299     *
300     */
301    static class Elements {
302
303        final static String HOURS = "hours";
304        final static String TK_TIME_BLOCK_ID = "tkTimeBlockId";
305        final static String TK_TIME_HOUR_DETAIL_ID = "tkTimeHourDetailId";
306        final static String EARN_CODE = "earnCode";
307        final static String AMOUNT = "amount";
308
309    }
310
311}