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