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