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 * EntityTimeValue.java
021 */
022
023package com.echothree.model.data.core.server.value;
024
025import com.echothree.model.data.core.common.pk.EntityTimePK;
026
027import com.echothree.model.data.core.server.factory.EntityTimeFactory;
028
029import com.echothree.model.data.core.common.pk.EntityInstancePK;
030
031import com.echothree.util.common.exception.PersistenceCloneException;
032import com.echothree.util.common.exception.PersistenceNotNullException;
033
034import com.echothree.util.server.persistence.BaseValue;
035
036import java.io.Serializable;
037
038public class EntityTimeValue
039        extends BaseValue<EntityTimePK>
040        implements Cloneable, Serializable {
041    
042    private EntityInstancePK entityInstancePK;
043    private boolean entityInstancePKHasBeenModified = false;
044    private Long createdTime;
045    private boolean createdTimeHasBeenModified = false;
046    private Long modifiedTime;
047    private boolean modifiedTimeHasBeenModified = false;
048    private Long deletedTime;
049    private boolean deletedTimeHasBeenModified = false;
050    
051    private transient Integer _hashCode = null;
052    private transient String _stringValue = null;
053    
054    private void constructFields(EntityInstancePK entityInstancePK, Long createdTime, Long modifiedTime, Long deletedTime)
055            throws PersistenceNotNullException {
056        checkForNull(entityInstancePK);
057        this.entityInstancePK = entityInstancePK;
058        checkForNull(createdTime);
059        this.createdTime = createdTime;
060        this.modifiedTime = modifiedTime;
061        this.deletedTime = deletedTime;
062    }
063    
064    /** Creates a new instance of EntityTimeValue */
065    public EntityTimeValue(EntityTimePK entityTimePK, EntityInstancePK entityInstancePK, Long createdTime, Long modifiedTime, Long deletedTime)
066            throws PersistenceNotNullException {
067        super(entityTimePK);
068        constructFields(entityInstancePK, createdTime, modifiedTime, deletedTime);
069    }
070    
071    /** Creates a new instance of EntityTimeValue */
072    public EntityTimeValue(EntityInstancePK entityInstancePK, Long createdTime, Long modifiedTime, Long deletedTime)
073            throws PersistenceNotNullException {
074        super();
075        constructFields(entityInstancePK, createdTime, modifiedTime, deletedTime);
076    }
077    
078   @Override
079   public EntityTimeFactory getBaseFactoryInstance() {
080        return EntityTimeFactory.getInstance();
081    }
082    
083    @Override
084    public EntityTimeValue clone() {
085        Object result;
086        
087        try {
088            result = super.clone();
089        } catch (CloneNotSupportedException cnse) {
090            // This shouldn't happen, fail when it does.
091            throw new PersistenceCloneException(cnse);
092        }
093        
094        return (EntityTimeValue)result;
095    }
096    
097   @Override
098    public EntityTimePK getPrimaryKey() {
099        if(_primaryKey == null) {
100            _primaryKey = new EntityTimePK(entityId);
101        }
102        
103        return _primaryKey;
104    }
105    
106    private void clearHashAndString() {
107        _hashCode = null;
108        _stringValue = null;
109    }
110    
111    @Override
112    public int hashCode() {
113        if(_hashCode == null) {
114            int hashCode = 17;
115            
116            hashCode = 37 * hashCode + ((entityId != null) ? entityId.hashCode() : 0);
117            
118            hashCode = 37 * hashCode + ((entityInstancePK != null) ? entityInstancePK.hashCode() : 0);
119            hashCode = 37 * hashCode + ((createdTime != null) ? createdTime.hashCode() : 0);
120            hashCode = 37 * hashCode + ((modifiedTime != null) ? modifiedTime.hashCode() : 0);
121            hashCode = 37 * hashCode + ((deletedTime != null) ? deletedTime.hashCode() : 0);
122            
123            _hashCode = hashCode;
124        }
125        
126        return _hashCode;
127    }
128    
129    @Override
130    public String toString() {
131        if(_stringValue == null) {
132            StringBuilder stringValue = new StringBuilder("{");
133            
134            stringValue.append("entityId=").append(getEntityId());
135            
136            stringValue.append(", entityInstancePK=").append(getEntityInstancePK());
137            stringValue.append(", createdTime=").append(getCreatedTime());
138            stringValue.append(", modifiedTime=").append(getModifiedTime());
139            stringValue.append(", deletedTime=").append(getDeletedTime());
140            
141            stringValue.append('}');
142            
143            _stringValue = stringValue.toString();
144        }
145        return _stringValue;
146    }
147    
148    @Override
149    public boolean equals(Object other) {
150        if(this == other)
151            return true;
152        
153        if(!hasIdentity())
154            return false;
155        
156        if(other instanceof  EntityTimeValue) {
157            EntityTimeValue that = (EntityTimeValue)other;
158            
159            if(!that.hasIdentity())
160                return false;
161            
162            Long thisEntityId = getEntityId();
163            Long thatEntityId = that.getEntityId();
164            
165            boolean objectsEqual = thisEntityId.equals(thatEntityId);
166            if(objectsEqual)
167                objectsEqual = objectsEqual && isIdentical(that);
168            
169            return objectsEqual;
170        } else {
171            return false;
172        }
173    }
174    
175    public boolean isIdentical(Object other) {
176        if(other instanceof EntityTimeValue) {
177            EntityTimeValue that = (EntityTimeValue)other;
178            boolean objectsEqual = true;
179            
180            
181            if(objectsEqual) {
182                EntityInstancePK thisEntityInstancePK = getEntityInstancePK();
183                EntityInstancePK thatEntityInstancePK = that.getEntityInstancePK();
184                
185                if(thisEntityInstancePK == null) {
186                    objectsEqual = objectsEqual && (thatEntityInstancePK == null);
187                } else {
188                    objectsEqual = objectsEqual && thisEntityInstancePK.equals(thatEntityInstancePK);
189                }
190            }
191            
192            if(objectsEqual) {
193                Long thisCreatedTime = getCreatedTime();
194                Long thatCreatedTime = that.getCreatedTime();
195                
196                if(thisCreatedTime == null) {
197                    objectsEqual = objectsEqual && (thatCreatedTime == null);
198                } else {
199                    objectsEqual = objectsEqual && thisCreatedTime.equals(thatCreatedTime);
200                }
201            }
202            
203            if(objectsEqual) {
204                Long thisModifiedTime = getModifiedTime();
205                Long thatModifiedTime = that.getModifiedTime();
206                
207                if(thisModifiedTime == null) {
208                    objectsEqual = objectsEqual && (thatModifiedTime == null);
209                } else {
210                    objectsEqual = objectsEqual && thisModifiedTime.equals(thatModifiedTime);
211                }
212            }
213            
214            if(objectsEqual) {
215                Long thisDeletedTime = getDeletedTime();
216                Long thatDeletedTime = that.getDeletedTime();
217                
218                if(thisDeletedTime == null) {
219                    objectsEqual = objectsEqual && (thatDeletedTime == null);
220                } else {
221                    objectsEqual = objectsEqual && thisDeletedTime.equals(thatDeletedTime);
222                }
223            }
224            
225            return objectsEqual;
226        } else {
227            return false;
228        }
229    }
230    
231    @Override
232    public boolean hasBeenModified() {
233        return entityInstancePKHasBeenModified || createdTimeHasBeenModified || modifiedTimeHasBeenModified || deletedTimeHasBeenModified;
234    }
235    
236    @Override
237    public void clearHasBeenModified() {
238        entityInstancePKHasBeenModified = false;
239        createdTimeHasBeenModified = false;
240        modifiedTimeHasBeenModified = false;
241        deletedTimeHasBeenModified = false;
242    }
243    
244    public EntityInstancePK getEntityInstancePK() {
245        return entityInstancePK;
246    }
247    
248    public void setEntityInstancePK(EntityInstancePK entityInstancePK)
249            throws PersistenceNotNullException {
250        checkForNull(entityInstancePK);
251        
252        boolean update = true;
253        
254        if(this.entityInstancePK != null) {
255            if(this.entityInstancePK.equals(entityInstancePK)) {
256                update = false;
257            }
258        } else if(entityInstancePK == null) {
259            update = false;
260        }
261        
262        if(update) {
263            this.entityInstancePK = entityInstancePK;
264            entityInstancePKHasBeenModified = true;
265            clearHashAndString();
266        }
267    }
268    
269    public boolean getEntityInstancePKHasBeenModified() {
270        return entityInstancePKHasBeenModified;
271    }
272    
273    public Long getCreatedTime() {
274        return createdTime;
275    }
276    
277    public void setCreatedTime(Long createdTime)
278            throws PersistenceNotNullException {
279        checkForNull(createdTime);
280        
281        boolean update = true;
282        
283        if(this.createdTime != null) {
284            if(this.createdTime.equals(createdTime)) {
285                update = false;
286            }
287        } else if(createdTime == null) {
288            update = false;
289        }
290        
291        if(update) {
292            this.createdTime = createdTime;
293            createdTimeHasBeenModified = true;
294            clearHashAndString();
295        }
296    }
297    
298    public boolean getCreatedTimeHasBeenModified() {
299        return createdTimeHasBeenModified;
300    }
301    
302    public Long getModifiedTime() {
303        return modifiedTime;
304    }
305    
306    public void setModifiedTime(Long modifiedTime) {
307        boolean update = true;
308        
309        if(this.modifiedTime != null) {
310            if(this.modifiedTime.equals(modifiedTime)) {
311                update = false;
312            }
313        } else if(modifiedTime == null) {
314            update = false;
315        }
316        
317        if(update) {
318            this.modifiedTime = modifiedTime;
319            modifiedTimeHasBeenModified = true;
320            clearHashAndString();
321        }
322    }
323    
324    public boolean getModifiedTimeHasBeenModified() {
325        return modifiedTimeHasBeenModified;
326    }
327    
328    public Long getDeletedTime() {
329        return deletedTime;
330    }
331    
332    public void setDeletedTime(Long deletedTime) {
333        boolean update = true;
334        
335        if(this.deletedTime != null) {
336            if(this.deletedTime.equals(deletedTime)) {
337                update = false;
338            }
339        } else if(deletedTime == null) {
340            update = false;
341        }
342        
343        if(update) {
344            this.deletedTime = deletedTime;
345            deletedTimeHasBeenModified = true;
346            clearHashAndString();
347        }
348    }
349    
350    public boolean getDeletedTimeHasBeenModified() {
351        return deletedTimeHasBeenModified;
352    }
353    
354}