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