001// --------------------------------------------------------------------------------
002// Copyright 2002-2025 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 * AppearanceValue.java
021 */
022
023package com.echothree.model.data.core.server.value;
024
025import com.echothree.model.data.core.common.pk.AppearancePK;
026
027import com.echothree.model.data.core.server.factory.AppearanceFactory;
028
029import com.echothree.model.data.core.common.pk.AppearanceDetailPK;
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 AppearanceValue
039        extends BaseValue<AppearancePK>
040        implements Cloneable, Serializable {
041    
042    private AppearanceDetailPK activeDetailPK;
043    private boolean activeDetailPKHasBeenModified = false;
044    private AppearanceDetailPK lastDetailPK;
045    private boolean lastDetailPKHasBeenModified = false;
046    
047    private transient Integer _hashCode = null;
048    private transient String _stringValue = null;
049    
050    private void constructFields(AppearanceDetailPK activeDetailPK, AppearanceDetailPK lastDetailPK)
051            throws PersistenceNotNullException {
052        this.activeDetailPK = activeDetailPK;
053        this.lastDetailPK = lastDetailPK;
054    }
055    
056    /** Creates a new instance of AppearanceValue */
057    public AppearanceValue(AppearancePK appearancePK, AppearanceDetailPK activeDetailPK, AppearanceDetailPK lastDetailPK)
058            throws PersistenceNotNullException {
059        super(appearancePK);
060        constructFields(activeDetailPK, lastDetailPK);
061    }
062    
063    /** Creates a new instance of AppearanceValue */
064    public AppearanceValue(AppearanceDetailPK activeDetailPK, AppearanceDetailPK lastDetailPK)
065            throws PersistenceNotNullException {
066        super();
067        constructFields(activeDetailPK, lastDetailPK);
068    }
069    
070   @Override
071   public AppearanceFactory getBaseFactoryInstance() {
072        return AppearanceFactory.getInstance();
073    }
074    
075    @Override
076    public AppearanceValue clone() {
077        Object result;
078        
079        try {
080            result = super.clone();
081        } catch (CloneNotSupportedException cnse) {
082            // This shouldn't happen, fail when it does.
083            throw new PersistenceCloneException(cnse);
084        }
085        
086        return (AppearanceValue)result;
087    }
088    
089   @Override
090    public AppearancePK getPrimaryKey() {
091        if(_primaryKey == null) {
092            _primaryKey = new AppearancePK(entityId);
093        }
094        
095        return _primaryKey;
096    }
097    
098    private void clearHashAndString() {
099        _hashCode = null;
100        _stringValue = null;
101    }
102    
103    @Override
104    public int hashCode() {
105        if(_hashCode == null) {
106            int hashCode = 17;
107            
108            hashCode = 37 * hashCode + ((entityId != null) ? entityId.hashCode() : 0);
109            
110            hashCode = 37 * hashCode + ((activeDetailPK != null) ? activeDetailPK.hashCode() : 0);
111            hashCode = 37 * hashCode + ((lastDetailPK != null) ? lastDetailPK.hashCode() : 0);
112            
113            _hashCode = hashCode;
114        }
115        
116        return _hashCode;
117    }
118    
119    @Override
120    public String toString() {
121        if(_stringValue == null) {
122            _stringValue = "{" + 
123                    "entityId=" + getEntityId() +
124                    ", activeDetailPK=" + getActiveDetailPK() +
125                    ", lastDetailPK=" + getLastDetailPK() +
126                    "}";
127        }
128        return _stringValue;
129    }
130    
131    @Override
132    public boolean equals(Object other) {
133        if(this == other)
134            return true;
135        
136        if(!hasIdentity())
137            return false;
138        
139        if(other instanceof  AppearanceValue that) {
140            if(!that.hasIdentity())
141                return false;
142            
143            Long thisEntityId = getEntityId();
144            Long thatEntityId = that.getEntityId();
145            
146            boolean objectsEqual = thisEntityId.equals(thatEntityId);
147            if(objectsEqual)
148                objectsEqual = isIdentical(that);
149            
150            return objectsEqual;
151        } else {
152            return false;
153        }
154    }
155    
156    public boolean isIdentical(Object other) {
157        if(other instanceof AppearanceValue that) {
158            boolean objectsEqual = true;
159            
160            
161            if(objectsEqual) {
162                AppearanceDetailPK thisActiveDetailPK = getActiveDetailPK();
163                AppearanceDetailPK thatActiveDetailPK = that.getActiveDetailPK();
164                
165                if(thisActiveDetailPK == null) {
166                    objectsEqual = objectsEqual && (thatActiveDetailPK == null);
167                } else {
168                    objectsEqual = objectsEqual && thisActiveDetailPK.equals(thatActiveDetailPK);
169                }
170            }
171            
172            if(objectsEqual) {
173                AppearanceDetailPK thisLastDetailPK = getLastDetailPK();
174                AppearanceDetailPK thatLastDetailPK = that.getLastDetailPK();
175                
176                if(thisLastDetailPK == null) {
177                    objectsEqual = objectsEqual && (thatLastDetailPK == null);
178                } else {
179                    objectsEqual = objectsEqual && thisLastDetailPK.equals(thatLastDetailPK);
180                }
181            }
182            
183            return objectsEqual;
184        } else {
185            return false;
186        }
187    }
188    
189    @Override
190    public boolean hasBeenModified() {
191        return activeDetailPKHasBeenModified || lastDetailPKHasBeenModified;
192    }
193    
194    @Override
195    public void clearHasBeenModified() {
196        activeDetailPKHasBeenModified = false;
197        lastDetailPKHasBeenModified = false;
198    }
199    
200    public AppearanceDetailPK getActiveDetailPK() {
201        return activeDetailPK;
202    }
203    
204    public void setActiveDetailPK(AppearanceDetailPK activeDetailPK) {
205        boolean update = true;
206        
207        if(this.activeDetailPK != null) {
208            if(this.activeDetailPK.equals(activeDetailPK)) {
209                update = false;
210            }
211        } else if(activeDetailPK == null) {
212            update = false;
213        }
214        
215        if(update) {
216            this.activeDetailPK = activeDetailPK;
217            activeDetailPKHasBeenModified = true;
218            clearHashAndString();
219        }
220    }
221    
222    public boolean getActiveDetailPKHasBeenModified() {
223        return activeDetailPKHasBeenModified;
224    }
225    
226    public AppearanceDetailPK getLastDetailPK() {
227        return lastDetailPK;
228    }
229    
230    public void setLastDetailPK(AppearanceDetailPK lastDetailPK) {
231        boolean update = true;
232        
233        if(this.lastDetailPK != null) {
234            if(this.lastDetailPK.equals(lastDetailPK)) {
235                update = false;
236            }
237        } else if(lastDetailPK == null) {
238            update = false;
239        }
240        
241        if(update) {
242            this.lastDetailPK = lastDetailPK;
243            lastDetailPKHasBeenModified = true;
244            clearHashAndString();
245        }
246    }
247    
248    public boolean getLastDetailPKHasBeenModified() {
249        return lastDetailPKHasBeenModified;
250    }
251    
252}