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 * EntityVisitValue.java
021 */
022
023package com.echothree.model.data.core.server.value;
024
025import com.echothree.model.data.core.common.pk.EntityVisitPK;
026
027import com.echothree.model.data.core.server.factory.EntityVisitFactory;
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
038import javax.annotation.Nonnull;
039import javax.annotation.Nullable;
040
041public class EntityVisitValue
042        extends BaseValue<EntityVisitPK>
043        implements Cloneable, Serializable {
044    
045    private EntityInstancePK entityInstancePK;
046    private boolean entityInstancePKHasBeenModified = false;
047    private EntityInstancePK visitedEntityInstancePK;
048    private boolean visitedEntityInstancePKHasBeenModified = false;
049    private Long visitedTime;
050    private boolean visitedTimeHasBeenModified = false;
051    
052    private transient Integer _hashCode = null;
053    private transient String _stringValue = null;
054    
055    private void constructFields(EntityInstancePK entityInstancePK, EntityInstancePK visitedEntityInstancePK, Long visitedTime)
056            throws PersistenceNotNullException {
057        checkForNull(entityInstancePK);
058        this.entityInstancePK = entityInstancePK;
059        checkForNull(visitedEntityInstancePK);
060        this.visitedEntityInstancePK = visitedEntityInstancePK;
061        checkForNull(visitedTime);
062        this.visitedTime = visitedTime;
063    }
064    
065    /** Creates a new instance of EntityVisitValue */
066    public EntityVisitValue(EntityVisitPK entityVisitPK, EntityInstancePK entityInstancePK, EntityInstancePK visitedEntityInstancePK, Long visitedTime)
067            throws PersistenceNotNullException {
068        super(entityVisitPK);
069        constructFields(entityInstancePK, visitedEntityInstancePK, visitedTime);
070    }
071    
072    /** Creates a new instance of EntityVisitValue */
073    public EntityVisitValue(EntityInstancePK entityInstancePK, EntityInstancePK visitedEntityInstancePK, Long visitedTime)
074            throws PersistenceNotNullException {
075        super();
076        constructFields(entityInstancePK, visitedEntityInstancePK, visitedTime);
077    }
078    
079    @Override
080    @Nonnull
081    public EntityVisitFactory getBaseFactoryInstance() {
082        return EntityVisitFactory.getInstance();
083    }
084    
085    @Override
086    @Nonnull
087    public EntityVisitValue 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 (EntityVisitValue)result;
098    }
099    
100    @Override
101    @Nonnull
102    public EntityVisitPK getPrimaryKey() {
103        if(_primaryKey == null) {
104            _primaryKey = new EntityVisitPK(entityId);
105        }
106        
107        return _primaryKey;
108    }
109    
110    private void clearHashAndString() {
111        _hashCode = null;
112        _stringValue = null;
113    }
114    
115    @Override
116    public int hashCode() {
117        if(_hashCode == null) {
118            int hashCode = 17;
119            
120            hashCode = 37 * hashCode + ((entityId != null) ? entityId.hashCode() : 0);
121            
122            hashCode = 37 * hashCode + ((entityInstancePK != null) ? entityInstancePK.hashCode() : 0);
123            hashCode = 37 * hashCode + ((visitedEntityInstancePK != null) ? visitedEntityInstancePK.hashCode() : 0);
124            hashCode = 37 * hashCode + ((visitedTime != null) ? visitedTime.hashCode() : 0);
125            
126            _hashCode = hashCode;
127        }
128        
129        return _hashCode;
130    }
131    
132    @Override
133    @Nonnull
134    public String toString() {
135        if(_stringValue == null) {
136            _stringValue = "{" + 
137                    "entityId=" + getEntityId() +
138                    ", entityInstancePK=" + getEntityInstancePK() +
139                    ", visitedEntityInstancePK=" + getVisitedEntityInstancePK() +
140                    ", visitedTime=" + getVisitedTime() +
141                    "}";
142        }
143        return _stringValue;
144    }
145    
146    @Override
147    public boolean equals(Object other) {
148        if(this == other)
149            return true;
150        
151        if(!hasIdentity())
152            return false;
153        
154        if(other instanceof  EntityVisitValue that) {
155            if(!that.hasIdentity())
156                return false;
157            
158            Long thisEntityId = getEntityId();
159            Long thatEntityId = that.getEntityId();
160            
161            boolean objectsEqual = thisEntityId.equals(thatEntityId);
162            if(objectsEqual)
163                objectsEqual = isIdentical(that);
164            
165            return objectsEqual;
166        } else {
167            return false;
168        }
169    }
170    
171    public boolean isIdentical(Object other) {
172        if(other instanceof EntityVisitValue that) {
173            boolean objectsEqual = true;
174            
175            
176            if(objectsEqual) {
177                EntityInstancePK thisEntityInstancePK = getEntityInstancePK();
178                EntityInstancePK thatEntityInstancePK = that.getEntityInstancePK();
179                
180                if(thisEntityInstancePK == null) {
181                    objectsEqual = objectsEqual && (thatEntityInstancePK == null);
182                } else {
183                    objectsEqual = objectsEqual && thisEntityInstancePK.equals(thatEntityInstancePK);
184                }
185            }
186            
187            if(objectsEqual) {
188                EntityInstancePK thisVisitedEntityInstancePK = getVisitedEntityInstancePK();
189                EntityInstancePK thatVisitedEntityInstancePK = that.getVisitedEntityInstancePK();
190                
191                if(thisVisitedEntityInstancePK == null) {
192                    objectsEqual = objectsEqual && (thatVisitedEntityInstancePK == null);
193                } else {
194                    objectsEqual = objectsEqual && thisVisitedEntityInstancePK.equals(thatVisitedEntityInstancePK);
195                }
196            }
197            
198            if(objectsEqual) {
199                Long thisVisitedTime = getVisitedTime();
200                Long thatVisitedTime = that.getVisitedTime();
201                
202                if(thisVisitedTime == null) {
203                    objectsEqual = objectsEqual && (thatVisitedTime == null);
204                } else {
205                    objectsEqual = objectsEqual && thisVisitedTime.equals(thatVisitedTime);
206                }
207            }
208            
209            return objectsEqual;
210        } else {
211            return false;
212        }
213    }
214    
215    @Override
216    public boolean hasBeenModified() {
217        return entityInstancePKHasBeenModified || visitedEntityInstancePKHasBeenModified || visitedTimeHasBeenModified;
218    }
219    
220    @Override
221    public void clearHasBeenModified() {
222        entityInstancePKHasBeenModified = false;
223        visitedEntityInstancePKHasBeenModified = false;
224        visitedTimeHasBeenModified = false;
225    }
226    
227    @Nonnull
228    public EntityInstancePK getEntityInstancePK() {
229        return entityInstancePK;
230    }
231    
232    public void setEntityInstancePK(@Nonnull EntityInstancePK entityInstancePK)
233            throws PersistenceNotNullException {
234        checkForNull(entityInstancePK);
235        
236        boolean update = true;
237        
238        if(this.entityInstancePK != null) {
239            if(this.entityInstancePK.equals(entityInstancePK)) {
240                update = false;
241            }
242        } else if(entityInstancePK == null) {
243            update = false;
244        }
245        
246        if(update) {
247            this.entityInstancePK = entityInstancePK;
248            entityInstancePKHasBeenModified = true;
249            clearHashAndString();
250        }
251    }
252    
253    public boolean getEntityInstancePKHasBeenModified() {
254        return entityInstancePKHasBeenModified;
255    }
256    
257    @Nonnull
258    public EntityInstancePK getVisitedEntityInstancePK() {
259        return visitedEntityInstancePK;
260    }
261    
262    public void setVisitedEntityInstancePK(@Nonnull EntityInstancePK visitedEntityInstancePK)
263            throws PersistenceNotNullException {
264        checkForNull(visitedEntityInstancePK);
265        
266        boolean update = true;
267        
268        if(this.visitedEntityInstancePK != null) {
269            if(this.visitedEntityInstancePK.equals(visitedEntityInstancePK)) {
270                update = false;
271            }
272        } else if(visitedEntityInstancePK == null) {
273            update = false;
274        }
275        
276        if(update) {
277            this.visitedEntityInstancePK = visitedEntityInstancePK;
278            visitedEntityInstancePKHasBeenModified = true;
279            clearHashAndString();
280        }
281    }
282    
283    public boolean getVisitedEntityInstancePKHasBeenModified() {
284        return visitedEntityInstancePKHasBeenModified;
285    }
286    
287    @Nonnull
288    public Long getVisitedTime() {
289        return visitedTime;
290    }
291    
292    public void setVisitedTime(@Nonnull Long visitedTime)
293            throws PersistenceNotNullException {
294        checkForNull(visitedTime);
295        
296        boolean update = true;
297        
298        if(this.visitedTime != null) {
299            if(this.visitedTime.equals(visitedTime)) {
300                update = false;
301            }
302        } else if(visitedTime == null) {
303            update = false;
304        }
305        
306        if(update) {
307            this.visitedTime = visitedTime;
308            visitedTimeHasBeenModified = true;
309            clearHashAndString();
310        }
311    }
312    
313    public boolean getVisitedTimeHasBeenModified() {
314        return visitedTimeHasBeenModified;
315    }
316    
317}