001// --------------------------------------------------------------------------------
002// Copyright 2002-2024 Echo Three, LLC
003//
004// Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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// --------------------------------------------------------------------------------
016// Generated File -- DO NOT EDIT BY HAND
017// --------------------------------------------------------------------------------
018
019/**
020 * QueuedEntityValue.java
021 */
022
023package com.echothree.model.data.queue.server.value;
024
025import com.echothree.model.data.queue.common.pk.QueuedEntityPK;
026
027import com.echothree.model.data.queue.server.factory.QueuedEntityFactory;
028
029import com.echothree.model.data.queue.common.pk.QueueTypePK;
030import com.echothree.model.data.core.common.pk.EntityInstancePK;
031
032import com.echothree.util.common.exception.PersistenceCloneException;
033import com.echothree.util.common.exception.PersistenceNotNullException;
034
035import com.echothree.util.server.persistence.BaseValue;
036
037import java.io.Serializable;
038
039public class QueuedEntityValue
040        extends BaseValue<QueuedEntityPK>
041        implements Cloneable, Serializable {
042    
043    private QueueTypePK queueTypePK;
044    private boolean queueTypePKHasBeenModified = false;
045    private EntityInstancePK entityInstancePK;
046    private boolean entityInstancePKHasBeenModified = false;
047    private Long time;
048    private boolean timeHasBeenModified = false;
049    
050    private transient Integer _hashCode = null;
051    private transient String _stringValue = null;
052    
053    private void constructFields(QueueTypePK queueTypePK, EntityInstancePK entityInstancePK, Long time)
054            throws PersistenceNotNullException {
055        checkForNull(queueTypePK);
056        this.queueTypePK = queueTypePK;
057        checkForNull(entityInstancePK);
058        this.entityInstancePK = entityInstancePK;
059        checkForNull(time);
060        this.time = time;
061    }
062    
063    /** Creates a new instance of QueuedEntityValue */
064    public QueuedEntityValue(QueuedEntityPK queuedEntityPK, QueueTypePK queueTypePK, EntityInstancePK entityInstancePK, Long time)
065            throws PersistenceNotNullException {
066        super(queuedEntityPK);
067        constructFields(queueTypePK, entityInstancePK, time);
068    }
069    
070    /** Creates a new instance of QueuedEntityValue */
071    public QueuedEntityValue(QueueTypePK queueTypePK, EntityInstancePK entityInstancePK, Long time)
072            throws PersistenceNotNullException {
073        super();
074        constructFields(queueTypePK, entityInstancePK, time);
075    }
076    
077   @Override
078   public QueuedEntityFactory getBaseFactoryInstance() {
079        return QueuedEntityFactory.getInstance();
080    }
081    
082    @Override
083    public QueuedEntityValue clone() {
084        Object result;
085        
086        try {
087            result = super.clone();
088        } catch (CloneNotSupportedException cnse) {
089            // This shouldn't happen, fail when it does.
090            throw new PersistenceCloneException(cnse);
091        }
092        
093        return (QueuedEntityValue)result;
094    }
095    
096   @Override
097    public QueuedEntityPK getPrimaryKey() {
098        if(_primaryKey == null) {
099            _primaryKey = new QueuedEntityPK(entityId);
100        }
101        
102        return _primaryKey;
103    }
104    
105    private void clearHashAndString() {
106        _hashCode = null;
107        _stringValue = null;
108    }
109    
110    @Override
111    public int hashCode() {
112        if(_hashCode == null) {
113            int hashCode = 17;
114            
115            hashCode = 37 * hashCode + ((entityId != null) ? entityId.hashCode() : 0);
116            
117            hashCode = 37 * hashCode + ((queueTypePK != null) ? queueTypePK.hashCode() : 0);
118            hashCode = 37 * hashCode + ((entityInstancePK != null) ? entityInstancePK.hashCode() : 0);
119            hashCode = 37 * hashCode + ((time != null) ? time.hashCode() : 0);
120            
121            _hashCode = hashCode;
122        }
123        
124        return _hashCode;
125    }
126    
127    @Override
128    public String toString() {
129        if(_stringValue == null) {
130            StringBuilder stringValue = new StringBuilder("{");
131            
132            stringValue.append("entityId=").append(getEntityId());
133            
134            stringValue.append(", queueTypePK=").append(getQueueTypePK());
135            stringValue.append(", entityInstancePK=").append(getEntityInstancePK());
136            stringValue.append(", time=").append(getTime());
137            
138            stringValue.append('}');
139            
140            _stringValue = stringValue.toString();
141        }
142        return _stringValue;
143    }
144    
145    @Override
146    public boolean equals(Object other) {
147        if(this == other)
148            return true;
149        
150        if(!hasIdentity())
151            return false;
152        
153        if(other instanceof  QueuedEntityValue) {
154            QueuedEntityValue that = (QueuedEntityValue)other;
155            
156            if(!that.hasIdentity())
157                return false;
158            
159            Long thisEntityId = getEntityId();
160            Long thatEntityId = that.getEntityId();
161            
162            boolean objectsEqual = thisEntityId.equals(thatEntityId);
163            if(objectsEqual)
164                objectsEqual = objectsEqual && isIdentical(that);
165            
166            return objectsEqual;
167        } else {
168            return false;
169        }
170    }
171    
172    public boolean isIdentical(Object other) {
173        if(other instanceof QueuedEntityValue) {
174            QueuedEntityValue that = (QueuedEntityValue)other;
175            boolean objectsEqual = true;
176            
177            
178            if(objectsEqual) {
179                QueueTypePK thisQueueTypePK = getQueueTypePK();
180                QueueTypePK thatQueueTypePK = that.getQueueTypePK();
181                
182                if(thisQueueTypePK == null) {
183                    objectsEqual = objectsEqual && (thatQueueTypePK == null);
184                } else {
185                    objectsEqual = objectsEqual && thisQueueTypePK.equals(thatQueueTypePK);
186                }
187            }
188            
189            if(objectsEqual) {
190                EntityInstancePK thisEntityInstancePK = getEntityInstancePK();
191                EntityInstancePK thatEntityInstancePK = that.getEntityInstancePK();
192                
193                if(thisEntityInstancePK == null) {
194                    objectsEqual = objectsEqual && (thatEntityInstancePK == null);
195                } else {
196                    objectsEqual = objectsEqual && thisEntityInstancePK.equals(thatEntityInstancePK);
197                }
198            }
199            
200            if(objectsEqual) {
201                Long thisTime = getTime();
202                Long thatTime = that.getTime();
203                
204                if(thisTime == null) {
205                    objectsEqual = objectsEqual && (thatTime == null);
206                } else {
207                    objectsEqual = objectsEqual && thisTime.equals(thatTime);
208                }
209            }
210            
211            return objectsEqual;
212        } else {
213            return false;
214        }
215    }
216    
217    @Override
218    public boolean hasBeenModified() {
219        return queueTypePKHasBeenModified || entityInstancePKHasBeenModified || timeHasBeenModified;
220    }
221    
222    @Override
223    public void clearHasBeenModified() {
224        queueTypePKHasBeenModified = false;
225        entityInstancePKHasBeenModified = false;
226        timeHasBeenModified = false;
227    }
228    
229    public QueueTypePK getQueueTypePK() {
230        return queueTypePK;
231    }
232    
233    public void setQueueTypePK(QueueTypePK queueTypePK)
234            throws PersistenceNotNullException {
235        checkForNull(queueTypePK);
236        
237        boolean update = true;
238        
239        if(this.queueTypePK != null) {
240            if(this.queueTypePK.equals(queueTypePK)) {
241                update = false;
242            }
243        } else if(queueTypePK == null) {
244            update = false;
245        }
246        
247        if(update) {
248            this.queueTypePK = queueTypePK;
249            queueTypePKHasBeenModified = true;
250            clearHashAndString();
251        }
252    }
253    
254    public boolean getQueueTypePKHasBeenModified() {
255        return queueTypePKHasBeenModified;
256    }
257    
258    public EntityInstancePK getEntityInstancePK() {
259        return entityInstancePK;
260    }
261    
262    public void setEntityInstancePK(EntityInstancePK entityInstancePK)
263            throws PersistenceNotNullException {
264        checkForNull(entityInstancePK);
265        
266        boolean update = true;
267        
268        if(this.entityInstancePK != null) {
269            if(this.entityInstancePK.equals(entityInstancePK)) {
270                update = false;
271            }
272        } else if(entityInstancePK == null) {
273            update = false;
274        }
275        
276        if(update) {
277            this.entityInstancePK = entityInstancePK;
278            entityInstancePKHasBeenModified = true;
279            clearHashAndString();
280        }
281    }
282    
283    public boolean getEntityInstancePKHasBeenModified() {
284        return entityInstancePKHasBeenModified;
285    }
286    
287    public Long getTime() {
288        return time;
289    }
290    
291    public void setTime(Long time)
292            throws PersistenceNotNullException {
293        checkForNull(time);
294        
295        boolean update = true;
296        
297        if(this.time != null) {
298            if(this.time.equals(time)) {
299                update = false;
300            }
301        } else if(time == null) {
302            update = false;
303        }
304        
305        if(update) {
306            this.time = time;
307            timeHasBeenModified = true;
308            clearHashAndString();
309        }
310    }
311    
312    public boolean getTimeHasBeenModified() {
313        return timeHasBeenModified;
314    }
315    
316}