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 * EntityInstanceValue.java
021 */
022
023package com.echothree.model.data.core.server.value;
024
025import com.echothree.model.data.core.common.pk.EntityInstancePK;
026
027import com.echothree.model.data.core.server.factory.EntityInstanceFactory;
028
029import com.echothree.model.data.core.common.pk.EntityTypePK;
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 EntityInstanceValue
039        extends BaseValue<EntityInstancePK>
040        implements Cloneable, Serializable {
041    
042    private EntityTypePK entityTypePK;
043    private boolean entityTypePKHasBeenModified = false;
044    private Long entityUniqueId;
045    private boolean entityUniqueIdHasBeenModified = false;
046    private String key;
047    private boolean keyHasBeenModified = false;
048    private String guid;
049    private boolean guidHasBeenModified = false;
050    private String ulid;
051    private boolean ulidHasBeenModified = false;
052    
053    private transient Integer _hashCode = null;
054    private transient String _stringValue = null;
055    
056    private void constructFields(EntityTypePK entityTypePK, Long entityUniqueId, String key, String guid, String ulid)
057            throws PersistenceNotNullException {
058        checkForNull(entityTypePK);
059        this.entityTypePK = entityTypePK;
060        checkForNull(entityUniqueId);
061        this.entityUniqueId = entityUniqueId;
062        this.key = key;
063        this.guid = guid;
064        this.ulid = ulid;
065    }
066    
067    /** Creates a new instance of EntityInstanceValue */
068    public EntityInstanceValue(EntityInstancePK entityInstancePK, EntityTypePK entityTypePK, Long entityUniqueId, String key, String guid, String ulid)
069            throws PersistenceNotNullException {
070        super(entityInstancePK);
071        constructFields(entityTypePK, entityUniqueId, key, guid, ulid);
072    }
073    
074    /** Creates a new instance of EntityInstanceValue */
075    public EntityInstanceValue(EntityTypePK entityTypePK, Long entityUniqueId, String key, String guid, String ulid)
076            throws PersistenceNotNullException {
077        super();
078        constructFields(entityTypePK, entityUniqueId, key, guid, ulid);
079    }
080    
081   @Override
082   public EntityInstanceFactory getBaseFactoryInstance() {
083        return EntityInstanceFactory.getInstance();
084    }
085    
086    @Override
087    public EntityInstanceValue clone() {
088        Object result;
089        
090        try {
091            result = super.clone();
092        } catch (CloneNotSupportedException cnse) {
093            // This shouldn't happen, fail when it does.
094            throw new PersistenceCloneException(cnse);
095        }
096        
097        return (EntityInstanceValue)result;
098    }
099    
100   @Override
101    public EntityInstancePK getPrimaryKey() {
102        if(_primaryKey == null) {
103            _primaryKey = new EntityInstancePK(entityId);
104        }
105        
106        return _primaryKey;
107    }
108    
109    private void clearHashAndString() {
110        _hashCode = null;
111        _stringValue = null;
112    }
113    
114    @Override
115    public int hashCode() {
116        if(_hashCode == null) {
117            int hashCode = 17;
118            
119            hashCode = 37 * hashCode + ((entityId != null) ? entityId.hashCode() : 0);
120            
121            hashCode = 37 * hashCode + ((entityTypePK != null) ? entityTypePK.hashCode() : 0);
122            hashCode = 37 * hashCode + ((entityUniqueId != null) ? entityUniqueId.hashCode() : 0);
123            hashCode = 37 * hashCode + ((key != null) ? key.hashCode() : 0);
124            hashCode = 37 * hashCode + ((guid != null) ? guid.hashCode() : 0);
125            hashCode = 37 * hashCode + ((ulid != null) ? ulid.hashCode() : 0);
126            
127            _hashCode = hashCode;
128        }
129        
130        return _hashCode;
131    }
132    
133    @Override
134    public String toString() {
135        if(_stringValue == null) {
136            StringBuilder stringValue = new StringBuilder("{");
137            
138            stringValue.append("entityId=").append(getEntityId());
139            
140            stringValue.append(", entityTypePK=").append(getEntityTypePK());
141            stringValue.append(", entityUniqueId=").append(getEntityUniqueId());
142            stringValue.append(", key=").append(getKey());
143            stringValue.append(", guid=").append(getGuid());
144            stringValue.append(", ulid=").append(getUlid());
145            
146            stringValue.append('}');
147            
148            _stringValue = stringValue.toString();
149        }
150        return _stringValue;
151    }
152    
153    @Override
154    public boolean equals(Object other) {
155        if(this == other)
156            return true;
157        
158        if(!hasIdentity())
159            return false;
160        
161        if(other instanceof  EntityInstanceValue) {
162            EntityInstanceValue that = (EntityInstanceValue)other;
163            
164            if(!that.hasIdentity())
165                return false;
166            
167            Long thisEntityId = getEntityId();
168            Long thatEntityId = that.getEntityId();
169            
170            boolean objectsEqual = thisEntityId.equals(thatEntityId);
171            if(objectsEqual)
172                objectsEqual = objectsEqual && isIdentical(that);
173            
174            return objectsEqual;
175        } else {
176            return false;
177        }
178    }
179    
180    public boolean isIdentical(Object other) {
181        if(other instanceof EntityInstanceValue) {
182            EntityInstanceValue that = (EntityInstanceValue)other;
183            boolean objectsEqual = true;
184            
185            
186            if(objectsEqual) {
187                EntityTypePK thisEntityTypePK = getEntityTypePK();
188                EntityTypePK thatEntityTypePK = that.getEntityTypePK();
189                
190                if(thisEntityTypePK == null) {
191                    objectsEqual = objectsEqual && (thatEntityTypePK == null);
192                } else {
193                    objectsEqual = objectsEqual && thisEntityTypePK.equals(thatEntityTypePK);
194                }
195            }
196            
197            if(objectsEqual) {
198                Long thisEntityUniqueId = getEntityUniqueId();
199                Long thatEntityUniqueId = that.getEntityUniqueId();
200                
201                if(thisEntityUniqueId == null) {
202                    objectsEqual = objectsEqual && (thatEntityUniqueId == null);
203                } else {
204                    objectsEqual = objectsEqual && thisEntityUniqueId.equals(thatEntityUniqueId);
205                }
206            }
207            
208            if(objectsEqual) {
209                String thisKey = getKey();
210                String thatKey = that.getKey();
211                
212                if(thisKey == null) {
213                    objectsEqual = objectsEqual && (thatKey == null);
214                } else {
215                    objectsEqual = objectsEqual && thisKey.equals(thatKey);
216                }
217            }
218            
219            if(objectsEqual) {
220                String thisGuid = getGuid();
221                String thatGuid = that.getGuid();
222                
223                if(thisGuid == null) {
224                    objectsEqual = objectsEqual && (thatGuid == null);
225                } else {
226                    objectsEqual = objectsEqual && thisGuid.equals(thatGuid);
227                }
228            }
229            
230            if(objectsEqual) {
231                String thisUlid = getUlid();
232                String thatUlid = that.getUlid();
233                
234                if(thisUlid == null) {
235                    objectsEqual = objectsEqual && (thatUlid == null);
236                } else {
237                    objectsEqual = objectsEqual && thisUlid.equals(thatUlid);
238                }
239            }
240            
241            return objectsEqual;
242        } else {
243            return false;
244        }
245    }
246    
247    @Override
248    public boolean hasBeenModified() {
249        return entityTypePKHasBeenModified || entityUniqueIdHasBeenModified || keyHasBeenModified || guidHasBeenModified || ulidHasBeenModified;
250    }
251    
252    @Override
253    public void clearHasBeenModified() {
254        entityTypePKHasBeenModified = false;
255        entityUniqueIdHasBeenModified = false;
256        keyHasBeenModified = false;
257        guidHasBeenModified = false;
258        ulidHasBeenModified = false;
259    }
260    
261    public EntityTypePK getEntityTypePK() {
262        return entityTypePK;
263    }
264    
265    public void setEntityTypePK(EntityTypePK entityTypePK)
266            throws PersistenceNotNullException {
267        checkForNull(entityTypePK);
268        
269        boolean update = true;
270        
271        if(this.entityTypePK != null) {
272            if(this.entityTypePK.equals(entityTypePK)) {
273                update = false;
274            }
275        } else if(entityTypePK == null) {
276            update = false;
277        }
278        
279        if(update) {
280            this.entityTypePK = entityTypePK;
281            entityTypePKHasBeenModified = true;
282            clearHashAndString();
283        }
284    }
285    
286    public boolean getEntityTypePKHasBeenModified() {
287        return entityTypePKHasBeenModified;
288    }
289    
290    public Long getEntityUniqueId() {
291        return entityUniqueId;
292    }
293    
294    public void setEntityUniqueId(Long entityUniqueId)
295            throws PersistenceNotNullException {
296        checkForNull(entityUniqueId);
297        
298        boolean update = true;
299        
300        if(this.entityUniqueId != null) {
301            if(this.entityUniqueId.equals(entityUniqueId)) {
302                update = false;
303            }
304        } else if(entityUniqueId == null) {
305            update = false;
306        }
307        
308        if(update) {
309            this.entityUniqueId = entityUniqueId;
310            entityUniqueIdHasBeenModified = true;
311            clearHashAndString();
312        }
313    }
314    
315    public boolean getEntityUniqueIdHasBeenModified() {
316        return entityUniqueIdHasBeenModified;
317    }
318    
319    public String getKey() {
320        return key;
321    }
322    
323    public void setKey(String key) {
324        boolean update = true;
325        
326        if(this.key != null) {
327            if(this.key.equals(key)) {
328                update = false;
329            }
330        } else if(key == null) {
331            update = false;
332        }
333        
334        if(update) {
335            this.key = key;
336            keyHasBeenModified = true;
337            clearHashAndString();
338        }
339    }
340    
341    public boolean getKeyHasBeenModified() {
342        return keyHasBeenModified;
343    }
344    
345    public String getGuid() {
346        return guid;
347    }
348    
349    public void setGuid(String guid) {
350        boolean update = true;
351        
352        if(this.guid != null) {
353            if(this.guid.equals(guid)) {
354                update = false;
355            }
356        } else if(guid == null) {
357            update = false;
358        }
359        
360        if(update) {
361            this.guid = guid;
362            guidHasBeenModified = true;
363            clearHashAndString();
364        }
365    }
366    
367    public boolean getGuidHasBeenModified() {
368        return guidHasBeenModified;
369    }
370    
371    public String getUlid() {
372        return ulid;
373    }
374    
375    public void setUlid(String ulid) {
376        boolean update = true;
377        
378        if(this.ulid != null) {
379            if(this.ulid.equals(ulid)) {
380                update = false;
381            }
382        } else if(ulid == null) {
383            update = false;
384        }
385        
386        if(update) {
387            this.ulid = ulid;
388            ulidHasBeenModified = true;
389            clearHashAndString();
390        }
391    }
392    
393    public boolean getUlidHasBeenModified() {
394        return ulidHasBeenModified;
395    }
396    
397}