Skip to main content
summaryrefslogtreecommitdiffstats
blob: c9f070d8093ddd5359038f178815229b47195c93 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/

package org.eclipse.osee.framework.skynet.core.change;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.osee.framework.core.data.ArtifactId;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.core.data.GammaId;
import org.eclipse.osee.framework.core.data.HasBranch;
import org.eclipse.osee.framework.core.enums.ModificationType;
import org.eclipse.osee.framework.core.model.TransactionDelta;
import org.eclipse.osee.framework.core.model.change.ChangeItem;
import org.eclipse.osee.framework.core.model.type.ArtifactType;
import org.eclipse.osee.framework.jdk.core.type.Id;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.revision.LoadChangeType;

/**
 * @author Jeff C. Phillips
 */
public abstract class Change implements IAdaptable, Comparable<Change>, HasBranch {
   private final GammaId sourceGamma;
   private final ArtifactId artId;
   private final TransactionDelta txDelta;
   private final ArtifactDelta artifactDelta;
   private final ModificationType modType;
   private final BranchId branch;
   private final boolean isHistorical;
   private final Artifact changeArtifact;
   private ChangeItem changeItem;

   public Change(BranchId branch, GammaId sourceGamma, ArtifactId artId, TransactionDelta txDelta, ModificationType modType, boolean isHistorical, Artifact changeArtifact, ArtifactDelta artifactDelta) {
      this.branch = branch;
      this.sourceGamma = sourceGamma;
      this.artId = artId;
      this.txDelta = txDelta;
      this.modType = modType;
      this.isHistorical = isHistorical;
      this.artifactDelta = artifactDelta;
      this.changeArtifact = changeArtifact;
   }

   public ChangeItem getChangeItem() {
      return changeItem;
   }

   public void setChangeItem(ChangeItem changeItem) {
      this.changeItem = changeItem;
   }

   @Override
   public boolean equals(Object obj) {
      if (getChangeArtifact() != null) {
         if (obj instanceof Change) {
            Change change = (Change) obj;
            boolean areDeltasEqual = false;
            if (change.getDelta() != null && getDelta() != null) {
               areDeltasEqual = change.getDelta().equals(getDelta());
            } else if (change.getDelta() == null && getDelta() == null) {
               areDeltasEqual = true;
            }
            return areDeltasEqual && change.getArtId() == getArtId() &&
            //
               change.getGamma() == getGamma() &&
               //
               change.getChangeArtifact().equals(getChangeArtifact()) &&
               //
               change.getModificationType() == getModificationType() &&
               //
               change.getTxDelta().equals(getTxDelta());
         }
      }
      return false;
   }

   @Override
   public int hashCode() {
      int hashCode = 7;
      hashCode += 13 * getArtId().hashCode();
      hashCode += 13 * getGamma().hashCode();
      hashCode += getChangeArtifact() != null ? 13 * getChangeArtifact().hashCode() : 0;
      hashCode += getDelta() != null ? 13 * getDelta().hashCode() : 0;
      hashCode += getModificationType() != null ? 13 * getModificationType().hashCode() : 0;
      hashCode += getTxDelta() != null ? 13 * getTxDelta().hashCode() : 0;
      return hashCode;
   }

   public GammaId getBaselineGamma() {
      return changeItem.getBaselineVersion().getGammaId();
   }

   public boolean isBaseline() {
      return changeItem.getBaselineVersion().isValid();
   }

   public boolean isHistorical() {
      return isHistorical;
   }

   public ModificationType getModificationType() {
      return modType;
   }

   public ArtifactDelta getDelta() {
      return artifactDelta;
   }

   public Artifact getChangeArtifact() {
      return changeArtifact;
   }

   public String getArtifactName() {
      return getChangeArtifact().toStringWithId();
   }

   public GammaId getGamma() {
      return sourceGamma;
   }

   public ArtifactId getArtId() {
      return artId;
   }

   public TransactionDelta getTxDelta() {
      return txDelta;
   }

   public abstract Id getItemTypeId();

   public ArtifactType getArtifactType() {
      return getChangeArtifact().getArtifactType();
   }

   @Override
   public BranchId getBranch() {
      return branch;
   }

   /**
    * @return value after change or value before if modtype == DELETED
    */
   public abstract String getIsValue();

   /**
    * @return value before change or empty if modtype == DELETED. Use getIsValue() for modtype == DELETED.
    */
   public abstract String getWasValue();

   public abstract String getItemTypeName() throws OseeCoreException;

   public abstract String getName();

   public abstract String getItemKind();

   public abstract Id getItemId();

   public abstract LoadChangeType getChangeType();

   @SuppressWarnings("unchecked")
   @Override
   public <T> T getAdapter(Class<T> type) {
      T toReturn = null;
      if (type != null) {
         if (type.isAssignableFrom(Artifact.class)) {
            toReturn = (T) getChangeArtifact();
         } else if (isHistorical() && type.isInstance(getTxDelta().getEndTx())) {
            toReturn = (T) getTxDelta().getEndTx();
         } else if (type.isAssignableFrom(getClass())) {
            toReturn = (T) this;
         }
      }

      return toReturn;
   }

   @Override
   public String toString() {
      return getName();
   }

   @Override
   public int compareTo(Change o) {
      return getName().compareTo(o.getName());
   }
}

Back to the top