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 * QueuedEventValue.java
021 */
022
023package com.echothree.model.data.core.server.value;
024
025import com.echothree.model.data.core.common.pk.QueuedEventPK;
026
027import com.echothree.model.data.core.server.factory.QueuedEventFactory;
028
029import com.echothree.model.data.core.common.pk.EventPK;
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 QueuedEventValue
039        extends BaseValue<QueuedEventPK>
040        implements Cloneable, Serializable {
041    
042    private EventPK eventPK;
043    private boolean eventPKHasBeenModified = false;
044    
045    private transient Integer _hashCode = null;
046    private transient String _stringValue = null;
047    
048    private void constructFields(EventPK eventPK)
049            throws PersistenceNotNullException {
050        checkForNull(eventPK);
051        this.eventPK = eventPK;
052    }
053    
054    /** Creates a new instance of QueuedEventValue */
055    public QueuedEventValue(QueuedEventPK queuedEventPK, EventPK eventPK)
056            throws PersistenceNotNullException {
057        super(queuedEventPK);
058        constructFields(eventPK);
059    }
060    
061    /** Creates a new instance of QueuedEventValue */
062    public QueuedEventValue(EventPK eventPK)
063            throws PersistenceNotNullException {
064        super();
065        constructFields(eventPK);
066    }
067    
068   @Override
069   public QueuedEventFactory getBaseFactoryInstance() {
070        return QueuedEventFactory.getInstance();
071    }
072    
073    @Override
074    public QueuedEventValue clone() {
075        Object result;
076        
077        try {
078            result = super.clone();
079        } catch (CloneNotSupportedException cnse) {
080            // This shouldn't happen, fail when it does.
081            throw new PersistenceCloneException(cnse);
082        }
083        
084        return (QueuedEventValue)result;
085    }
086    
087   @Override
088    public QueuedEventPK getPrimaryKey() {
089        if(_primaryKey == null) {
090            _primaryKey = new QueuedEventPK(entityId);
091        }
092        
093        return _primaryKey;
094    }
095    
096    private void clearHashAndString() {
097        _hashCode = null;
098        _stringValue = null;
099    }
100    
101    @Override
102    public int hashCode() {
103        if(_hashCode == null) {
104            int hashCode = 17;
105            
106            hashCode = 37 * hashCode + ((entityId != null) ? entityId.hashCode() : 0);
107            
108            hashCode = 37 * hashCode + ((eventPK != null) ? eventPK.hashCode() : 0);
109            
110            _hashCode = hashCode;
111        }
112        
113        return _hashCode;
114    }
115    
116    @Override
117    public String toString() {
118        if(_stringValue == null) {
119            _stringValue = "{" + 
120                    "entityId=" + getEntityId() +
121                    ", eventPK=" + getEventPK() +
122                    "}";
123        }
124        return _stringValue;
125    }
126    
127    @Override
128    public boolean equals(Object other) {
129        if(this == other)
130            return true;
131        
132        if(!hasIdentity())
133            return false;
134        
135        if(other instanceof  QueuedEventValue that) {
136            if(!that.hasIdentity())
137                return false;
138            
139            Long thisEntityId = getEntityId();
140            Long thatEntityId = that.getEntityId();
141            
142            boolean objectsEqual = thisEntityId.equals(thatEntityId);
143            if(objectsEqual)
144                objectsEqual = isIdentical(that);
145            
146            return objectsEqual;
147        } else {
148            return false;
149        }
150    }
151    
152    public boolean isIdentical(Object other) {
153        if(other instanceof QueuedEventValue that) {
154            boolean objectsEqual = true;
155            
156            
157            if(objectsEqual) {
158                EventPK thisEventPK = getEventPK();
159                EventPK thatEventPK = that.getEventPK();
160                
161                if(thisEventPK == null) {
162                    objectsEqual = objectsEqual && (thatEventPK == null);
163                } else {
164                    objectsEqual = objectsEqual && thisEventPK.equals(thatEventPK);
165                }
166            }
167            
168            return objectsEqual;
169        } else {
170            return false;
171        }
172    }
173    
174    @Override
175    public boolean hasBeenModified() {
176        return eventPKHasBeenModified;
177    }
178    
179    @Override
180    public void clearHasBeenModified() {
181        eventPKHasBeenModified = false;
182    }
183    
184    public EventPK getEventPK() {
185        return eventPK;
186    }
187    
188    public void setEventPK(EventPK eventPK)
189            throws PersistenceNotNullException {
190        checkForNull(eventPK);
191        
192        boolean update = true;
193        
194        if(this.eventPK != null) {
195            if(this.eventPK.equals(eventPK)) {
196                update = false;
197            }
198        } else if(eventPK == null) {
199            update = false;
200        }
201        
202        if(update) {
203            this.eventPK = eventPK;
204            eventPKHasBeenModified = true;
205            clearHashAndString();
206        }
207    }
208    
209    public boolean getEventPKHasBeenModified() {
210        return eventPKHasBeenModified;
211    }
212    
213}