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 * QueuedLetterValue.java
021 */
022
023package com.echothree.model.data.letter.server.value;
024
025import com.echothree.model.data.letter.common.pk.QueuedLetterPK;
026
027import com.echothree.model.data.letter.server.factory.QueuedLetterFactory;
028
029import com.echothree.model.data.chain.common.pk.ChainInstancePK;
030import com.echothree.model.data.letter.common.pk.LetterPK;
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
039import javax.annotation.Nonnull;
040import javax.annotation.Nullable;
041
042public class QueuedLetterValue
043        extends BaseValue<QueuedLetterPK>
044        implements Cloneable, Serializable {
045    
046    private ChainInstancePK chainInstancePK;
047    private boolean chainInstancePKHasBeenModified = false;
048    private Integer queuedLetterSequence;
049    private boolean queuedLetterSequenceHasBeenModified = false;
050    private LetterPK letterPK;
051    private boolean letterPKHasBeenModified = false;
052    
053    private transient Integer _hashCode = null;
054    private transient String _stringValue = null;
055    
056    private void constructFields(ChainInstancePK chainInstancePK, Integer queuedLetterSequence, LetterPK letterPK)
057            throws PersistenceNotNullException {
058        checkForNull(chainInstancePK);
059        this.chainInstancePK = chainInstancePK;
060        checkForNull(queuedLetterSequence);
061        this.queuedLetterSequence = queuedLetterSequence;
062        checkForNull(letterPK);
063        this.letterPK = letterPK;
064    }
065    
066    /** Creates a new instance of QueuedLetterValue */
067    public QueuedLetterValue(QueuedLetterPK queuedLetterPK, ChainInstancePK chainInstancePK, Integer queuedLetterSequence, LetterPK letterPK)
068            throws PersistenceNotNullException {
069        super(queuedLetterPK);
070        constructFields(chainInstancePK, queuedLetterSequence, letterPK);
071    }
072    
073    /** Creates a new instance of QueuedLetterValue */
074    public QueuedLetterValue(ChainInstancePK chainInstancePK, Integer queuedLetterSequence, LetterPK letterPK)
075            throws PersistenceNotNullException {
076        super();
077        constructFields(chainInstancePK, queuedLetterSequence, letterPK);
078    }
079    
080    @Override
081    @Nonnull
082    public QueuedLetterFactory getBaseFactoryInstance() {
083        return QueuedLetterFactory.getInstance();
084    }
085    
086    @Override
087    @Nonnull
088    public QueuedLetterValue clone() {
089        Object result;
090        
091        try {
092            result = super.clone();
093        } catch (CloneNotSupportedException cnse) {
094            // This shouldn't happen, fail when it does.
095            throw new PersistenceCloneException(cnse);
096        }
097        
098        return (QueuedLetterValue)result;
099    }
100    
101    @Override
102    @Nonnull
103    public QueuedLetterPK getPrimaryKey() {
104        if(_primaryKey == null) {
105            _primaryKey = new QueuedLetterPK(entityId);
106        }
107        
108        return _primaryKey;
109    }
110    
111    private void clearHashAndString() {
112        _hashCode = null;
113        _stringValue = null;
114    }
115    
116    @Override
117    public int hashCode() {
118        if(_hashCode == null) {
119            int hashCode = 17;
120            
121            hashCode = 37 * hashCode + ((entityId != null) ? entityId.hashCode() : 0);
122            
123            hashCode = 37 * hashCode + ((chainInstancePK != null) ? chainInstancePK.hashCode() : 0);
124            hashCode = 37 * hashCode + ((queuedLetterSequence != null) ? queuedLetterSequence.hashCode() : 0);
125            hashCode = 37 * hashCode + ((letterPK != null) ? letterPK.hashCode() : 0);
126            
127            _hashCode = hashCode;
128        }
129        
130        return _hashCode;
131    }
132    
133    @Override
134    @Nonnull
135    public String toString() {
136        if(_stringValue == null) {
137            _stringValue = "{" + 
138                    "entityId=" + getEntityId() +
139                    ", chainInstancePK=" + getChainInstancePK() +
140                    ", queuedLetterSequence=" + getQueuedLetterSequence() +
141                    ", letterPK=" + getLetterPK() +
142                    "}";
143        }
144        return _stringValue;
145    }
146    
147    @Override
148    public boolean equals(Object other) {
149        if(this == other)
150            return true;
151        
152        if(!hasIdentity())
153            return false;
154        
155        if(other instanceof  QueuedLetterValue that) {
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 = isIdentical(that);
165            
166            return objectsEqual;
167        } else {
168            return false;
169        }
170    }
171    
172    public boolean isIdentical(Object other) {
173        if(other instanceof QueuedLetterValue that) {
174            boolean objectsEqual = true;
175            
176            
177            if(objectsEqual) {
178                ChainInstancePK thisChainInstancePK = getChainInstancePK();
179                ChainInstancePK thatChainInstancePK = that.getChainInstancePK();
180                
181                if(thisChainInstancePK == null) {
182                    objectsEqual = objectsEqual && (thatChainInstancePK == null);
183                } else {
184                    objectsEqual = objectsEqual && thisChainInstancePK.equals(thatChainInstancePK);
185                }
186            }
187            
188            if(objectsEqual) {
189                Integer thisQueuedLetterSequence = getQueuedLetterSequence();
190                Integer thatQueuedLetterSequence = that.getQueuedLetterSequence();
191                
192                if(thisQueuedLetterSequence == null) {
193                    objectsEqual = objectsEqual && (thatQueuedLetterSequence == null);
194                } else {
195                    objectsEqual = objectsEqual && thisQueuedLetterSequence.equals(thatQueuedLetterSequence);
196                }
197            }
198            
199            if(objectsEqual) {
200                LetterPK thisLetterPK = getLetterPK();
201                LetterPK thatLetterPK = that.getLetterPK();
202                
203                if(thisLetterPK == null) {
204                    objectsEqual = objectsEqual && (thatLetterPK == null);
205                } else {
206                    objectsEqual = objectsEqual && thisLetterPK.equals(thatLetterPK);
207                }
208            }
209            
210            return objectsEqual;
211        } else {
212            return false;
213        }
214    }
215    
216    @Override
217    public boolean hasBeenModified() {
218        return chainInstancePKHasBeenModified || queuedLetterSequenceHasBeenModified || letterPKHasBeenModified;
219    }
220    
221    @Override
222    public void clearHasBeenModified() {
223        chainInstancePKHasBeenModified = false;
224        queuedLetterSequenceHasBeenModified = false;
225        letterPKHasBeenModified = false;
226    }
227    
228    @Nonnull
229    public ChainInstancePK getChainInstancePK() {
230        return chainInstancePK;
231    }
232    
233    public void setChainInstancePK(@Nonnull ChainInstancePK chainInstancePK)
234            throws PersistenceNotNullException {
235        checkForNull(chainInstancePK);
236        
237        boolean update = true;
238        
239        if(this.chainInstancePK != null) {
240            if(this.chainInstancePK.equals(chainInstancePK)) {
241                update = false;
242            }
243        } else if(chainInstancePK == null) {
244            update = false;
245        }
246        
247        if(update) {
248            this.chainInstancePK = chainInstancePK;
249            chainInstancePKHasBeenModified = true;
250            clearHashAndString();
251        }
252    }
253    
254    public boolean getChainInstancePKHasBeenModified() {
255        return chainInstancePKHasBeenModified;
256    }
257    
258    @Nonnull
259    public Integer getQueuedLetterSequence() {
260        return queuedLetterSequence;
261    }
262    
263    public void setQueuedLetterSequence(@Nonnull Integer queuedLetterSequence)
264            throws PersistenceNotNullException {
265        checkForNull(queuedLetterSequence);
266        
267        boolean update = true;
268        
269        if(this.queuedLetterSequence != null) {
270            if(this.queuedLetterSequence.equals(queuedLetterSequence)) {
271                update = false;
272            }
273        } else if(queuedLetterSequence == null) {
274            update = false;
275        }
276        
277        if(update) {
278            this.queuedLetterSequence = queuedLetterSequence;
279            queuedLetterSequenceHasBeenModified = true;
280            clearHashAndString();
281        }
282    }
283    
284    public boolean getQueuedLetterSequenceHasBeenModified() {
285        return queuedLetterSequenceHasBeenModified;
286    }
287    
288    @Nonnull
289    public LetterPK getLetterPK() {
290        return letterPK;
291    }
292    
293    public void setLetterPK(@Nonnull LetterPK letterPK)
294            throws PersistenceNotNullException {
295        checkForNull(letterPK);
296        
297        boolean update = true;
298        
299        if(this.letterPK != null) {
300            if(this.letterPK.equals(letterPK)) {
301                update = false;
302            }
303        } else if(letterPK == null) {
304            update = false;
305        }
306        
307        if(update) {
308            this.letterPK = letterPK;
309            letterPKHasBeenModified = true;
310            clearHashAndString();
311        }
312    }
313    
314    public boolean getLetterPKHasBeenModified() {
315        return letterPKHasBeenModified;
316    }
317    
318}