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 * BaseEncryptionKeyValue.java
021 */
022
023package com.echothree.model.data.core.server.value;
024
025import com.echothree.model.data.core.common.pk.BaseEncryptionKeyPK;
026
027import com.echothree.model.data.core.server.factory.BaseEncryptionKeyFactory;
028
029import com.echothree.util.common.exception.PersistenceCloneException;
030import com.echothree.util.common.exception.PersistenceNotNullException;
031
032import com.echothree.util.server.persistence.BaseValue;
033
034import java.io.Serializable;
035
036public class BaseEncryptionKeyValue
037        extends BaseValue<BaseEncryptionKeyPK>
038        implements Cloneable, Serializable {
039    
040    private String baseEncryptionKeyName;
041    private boolean baseEncryptionKeyNameHasBeenModified = false;
042    private String sha1Hash;
043    private boolean sha1HashHasBeenModified = false;
044    
045    private transient Integer _hashCode = null;
046    private transient String _stringValue = null;
047    
048    private void constructFields(String baseEncryptionKeyName, String sha1Hash)
049            throws PersistenceNotNullException {
050        checkForNull(baseEncryptionKeyName);
051        this.baseEncryptionKeyName = baseEncryptionKeyName;
052        checkForNull(sha1Hash);
053        this.sha1Hash = sha1Hash;
054    }
055    
056    /** Creates a new instance of BaseEncryptionKeyValue */
057    public BaseEncryptionKeyValue(BaseEncryptionKeyPK baseEncryptionKeyPK, String baseEncryptionKeyName, String sha1Hash)
058            throws PersistenceNotNullException {
059        super(baseEncryptionKeyPK);
060        constructFields(baseEncryptionKeyName, sha1Hash);
061    }
062    
063    /** Creates a new instance of BaseEncryptionKeyValue */
064    public BaseEncryptionKeyValue(String baseEncryptionKeyName, String sha1Hash)
065            throws PersistenceNotNullException {
066        super();
067        constructFields(baseEncryptionKeyName, sha1Hash);
068    }
069    
070   @Override
071   public BaseEncryptionKeyFactory getBaseFactoryInstance() {
072        return BaseEncryptionKeyFactory.getInstance();
073    }
074    
075    @Override
076    public BaseEncryptionKeyValue 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 (BaseEncryptionKeyValue)result;
087    }
088    
089   @Override
090    public BaseEncryptionKeyPK getPrimaryKey() {
091        if(_primaryKey == null) {
092            _primaryKey = new BaseEncryptionKeyPK(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 + ((baseEncryptionKeyName != null) ? baseEncryptionKeyName.hashCode() : 0);
111            hashCode = 37 * hashCode + ((sha1Hash != null) ? sha1Hash.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                    ", baseEncryptionKeyName=" + getBaseEncryptionKeyName() +
125                    ", sha1Hash=" + getSha1Hash() +
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  BaseEncryptionKeyValue 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 BaseEncryptionKeyValue that) {
158            boolean objectsEqual = true;
159            
160            
161            if(objectsEqual) {
162                String thisBaseEncryptionKeyName = getBaseEncryptionKeyName();
163                String thatBaseEncryptionKeyName = that.getBaseEncryptionKeyName();
164                
165                if(thisBaseEncryptionKeyName == null) {
166                    objectsEqual = objectsEqual && (thatBaseEncryptionKeyName == null);
167                } else {
168                    objectsEqual = objectsEqual && thisBaseEncryptionKeyName.equals(thatBaseEncryptionKeyName);
169                }
170            }
171            
172            if(objectsEqual) {
173                String thisSha1Hash = getSha1Hash();
174                String thatSha1Hash = that.getSha1Hash();
175                
176                if(thisSha1Hash == null) {
177                    objectsEqual = objectsEqual && (thatSha1Hash == null);
178                } else {
179                    objectsEqual = objectsEqual && thisSha1Hash.equals(thatSha1Hash);
180                }
181            }
182            
183            return objectsEqual;
184        } else {
185            return false;
186        }
187    }
188    
189    @Override
190    public boolean hasBeenModified() {
191        return baseEncryptionKeyNameHasBeenModified || sha1HashHasBeenModified;
192    }
193    
194    @Override
195    public void clearHasBeenModified() {
196        baseEncryptionKeyNameHasBeenModified = false;
197        sha1HashHasBeenModified = false;
198    }
199    
200    public String getBaseEncryptionKeyName() {
201        return baseEncryptionKeyName;
202    }
203    
204    public void setBaseEncryptionKeyName(String baseEncryptionKeyName)
205            throws PersistenceNotNullException {
206        checkForNull(baseEncryptionKeyName);
207        
208        boolean update = true;
209        
210        if(this.baseEncryptionKeyName != null) {
211            if(this.baseEncryptionKeyName.equals(baseEncryptionKeyName)) {
212                update = false;
213            }
214        } else if(baseEncryptionKeyName == null) {
215            update = false;
216        }
217        
218        if(update) {
219            this.baseEncryptionKeyName = baseEncryptionKeyName;
220            baseEncryptionKeyNameHasBeenModified = true;
221            clearHashAndString();
222        }
223    }
224    
225    public boolean getBaseEncryptionKeyNameHasBeenModified() {
226        return baseEncryptionKeyNameHasBeenModified;
227    }
228    
229    public String getSha1Hash() {
230        return sha1Hash;
231    }
232    
233    public void setSha1Hash(String sha1Hash)
234            throws PersistenceNotNullException {
235        checkForNull(sha1Hash);
236        
237        boolean update = true;
238        
239        if(this.sha1Hash != null) {
240            if(this.sha1Hash.equals(sha1Hash)) {
241                update = false;
242            }
243        } else if(sha1Hash == null) {
244            update = false;
245        }
246        
247        if(update) {
248            this.sha1Hash = sha1Hash;
249            sha1HashHasBeenModified = true;
250            clearHashAndString();
251        }
252    }
253    
254    public boolean getSha1HashHasBeenModified() {
255        return sha1HashHasBeenModified;
256    }
257    
258}