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 * PartyContactListValue.java
021 */
022
023package com.echothree.model.data.contactlist.server.value;
024
025import com.echothree.model.data.contactlist.common.pk.PartyContactListPK;
026
027import com.echothree.model.data.contactlist.server.factory.PartyContactListFactory;
028
029import com.echothree.model.data.contactlist.common.pk.PartyContactListDetailPK;
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 PartyContactListValue
039        extends BaseValue<PartyContactListPK>
040        implements Cloneable, Serializable {
041    
042    private PartyContactListDetailPK activeDetailPK;
043    private boolean activeDetailPKHasBeenModified = false;
044    private PartyContactListDetailPK lastDetailPK;
045    private boolean lastDetailPKHasBeenModified = false;
046    
047    private transient Integer _hashCode = null;
048    private transient String _stringValue = null;
049    
050    private void constructFields(PartyContactListDetailPK activeDetailPK, PartyContactListDetailPK lastDetailPK)
051            throws PersistenceNotNullException {
052        this.activeDetailPK = activeDetailPK;
053        this.lastDetailPK = lastDetailPK;
054    }
055    
056    /** Creates a new instance of PartyContactListValue */
057    public PartyContactListValue(PartyContactListPK partyContactListPK, PartyContactListDetailPK activeDetailPK, PartyContactListDetailPK lastDetailPK)
058            throws PersistenceNotNullException {
059        super(partyContactListPK);
060        constructFields(activeDetailPK, lastDetailPK);
061    }
062    
063    /** Creates a new instance of PartyContactListValue */
064    public PartyContactListValue(PartyContactListDetailPK activeDetailPK, PartyContactListDetailPK lastDetailPK)
065            throws PersistenceNotNullException {
066        super();
067        constructFields(activeDetailPK, lastDetailPK);
068    }
069    
070   @Override
071   public PartyContactListFactory getBaseFactoryInstance() {
072        return PartyContactListFactory.getInstance();
073    }
074    
075    @Override
076    public PartyContactListValue 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 (PartyContactListValue)result;
087    }
088    
089   @Override
090    public PartyContactListPK getPrimaryKey() {
091        if(_primaryKey == null) {
092            _primaryKey = new PartyContactListPK(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            StringBuilder stringValue = new StringBuilder("{");
123            
124            stringValue.append("entityId=").append(getEntityId());
125            
126            stringValue.append(", activeDetailPK=").append(getActiveDetailPK());
127            stringValue.append(", lastDetailPK=").append(getLastDetailPK());
128            
129            stringValue.append('}');
130            
131            _stringValue = stringValue.toString();
132        }
133        return _stringValue;
134    }
135    
136    @Override
137    public boolean equals(Object other) {
138        if(this == other)
139            return true;
140        
141        if(!hasIdentity())
142            return false;
143        
144        if(other instanceof  PartyContactListValue) {
145            PartyContactListValue that = (PartyContactListValue)other;
146            
147            if(!that.hasIdentity())
148                return false;
149            
150            Long thisEntityId = getEntityId();
151            Long thatEntityId = that.getEntityId();
152            
153            boolean objectsEqual = thisEntityId.equals(thatEntityId);
154            if(objectsEqual)
155                objectsEqual = objectsEqual && isIdentical(that);
156            
157            return objectsEqual;
158        } else {
159            return false;
160        }
161    }
162    
163    public boolean isIdentical(Object other) {
164        if(other instanceof PartyContactListValue) {
165            PartyContactListValue that = (PartyContactListValue)other;
166            boolean objectsEqual = true;
167            
168            
169            if(objectsEqual) {
170                PartyContactListDetailPK thisActiveDetailPK = getActiveDetailPK();
171                PartyContactListDetailPK thatActiveDetailPK = that.getActiveDetailPK();
172                
173                if(thisActiveDetailPK == null) {
174                    objectsEqual = objectsEqual && (thatActiveDetailPK == null);
175                } else {
176                    objectsEqual = objectsEqual && thisActiveDetailPK.equals(thatActiveDetailPK);
177                }
178            }
179            
180            if(objectsEqual) {
181                PartyContactListDetailPK thisLastDetailPK = getLastDetailPK();
182                PartyContactListDetailPK thatLastDetailPK = that.getLastDetailPK();
183                
184                if(thisLastDetailPK == null) {
185                    objectsEqual = objectsEqual && (thatLastDetailPK == null);
186                } else {
187                    objectsEqual = objectsEqual && thisLastDetailPK.equals(thatLastDetailPK);
188                }
189            }
190            
191            return objectsEqual;
192        } else {
193            return false;
194        }
195    }
196    
197    @Override
198    public boolean hasBeenModified() {
199        return activeDetailPKHasBeenModified || lastDetailPKHasBeenModified;
200    }
201    
202    @Override
203    public void clearHasBeenModified() {
204        activeDetailPKHasBeenModified = false;
205        lastDetailPKHasBeenModified = false;
206    }
207    
208    public PartyContactListDetailPK getActiveDetailPK() {
209        return activeDetailPK;
210    }
211    
212    public void setActiveDetailPK(PartyContactListDetailPK activeDetailPK) {
213        boolean update = true;
214        
215        if(this.activeDetailPK != null) {
216            if(this.activeDetailPK.equals(activeDetailPK)) {
217                update = false;
218            }
219        } else if(activeDetailPK == null) {
220            update = false;
221        }
222        
223        if(update) {
224            this.activeDetailPK = activeDetailPK;
225            activeDetailPKHasBeenModified = true;
226            clearHashAndString();
227        }
228    }
229    
230    public boolean getActiveDetailPKHasBeenModified() {
231        return activeDetailPKHasBeenModified;
232    }
233    
234    public PartyContactListDetailPK getLastDetailPK() {
235        return lastDetailPK;
236    }
237    
238    public void setLastDetailPK(PartyContactListDetailPK lastDetailPK) {
239        boolean update = true;
240        
241        if(this.lastDetailPK != null) {
242            if(this.lastDetailPK.equals(lastDetailPK)) {
243                update = false;
244            }
245        } else if(lastDetailPK == null) {
246            update = false;
247        }
248        
249        if(update) {
250            this.lastDetailPK = lastDetailPK;
251            lastDetailPKHasBeenModified = true;
252            clearHashAndString();
253        }
254    }
255    
256    public boolean getLastDetailPKHasBeenModified() {
257        return lastDetailPKHasBeenModified;
258    }
259    
260}