Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4aead0ebb9a1edf486089d91072ca4c7d83bbde2 (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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*********************************************************************
 * Copyright (c) 2004, 2007 Boeing
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Boeing - initial API and implementation
 **********************************************************************/

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.eclipse.osee.framework.core.data.ArtifactId;
import org.eclipse.osee.framework.core.enums.ModificationType;
import org.eclipse.osee.framework.jdk.core.type.Id;
import org.eclipse.osee.framework.jdk.core.util.Conditions;

/**
 * @author Roberto E. Escobar
 */
public class ChangeItem implements Comparable<ChangeItem> {

   private ChangeIgnoreType ignoreType = ChangeIgnoreType.SENTINEL;
   private ChangeType changeType = ChangeType.UNKNOWN_CHANGE;
   private ArtifactId artId = ArtifactId.SENTINEL;
   private Id itemId = Id.valueOf(Id.SENTINEL);
   private Id itemTypeId = Id.valueOf(Id.SENTINEL);

   private ChangeVersion baselineVersion = new ChangeVersion();
   private ChangeVersion firstNonCurrentChange = new ChangeVersion();
   private ChangeVersion currentVersion = new ChangeVersion();
   private ChangeVersion destinationVersion = new ChangeVersion();
   private ChangeVersion netChange = new ChangeVersion();

   private boolean synthetic = false;
   private boolean isApplicabilityCopy = false;

   private ArtifactId artIdB = ArtifactId.SENTINEL;

   public ChangeItem() {
      super();
   }

   public void copy(ChangeItem source) {
      Conditions.checkNotNull(source, "ChangeItem");
      setIgnoreType(source.getIgnoreType());
      setChangeType(source.getChangeType());
      setArtId(source.getArtId());
      setItemId(source.getItemId());
      setItemTypeId(source.getItemTypeId());
      setBaselineVersion(source.getBaselineVersion());
      setFirstNonCurrentChange(source.getFirstNonCurrentChange());
      setCurrentVersion(source.getCurrentVersion());
      setDestinationVersion(source.getDestinationVersion());
      setNetChange(source.getNetChange());
      setSynthetic(source.isSynthetic());
      setApplicabilityCopy(source.isApplicabilityCopy());
      setArtIdB(source.getArtIdB());
   }

   public ChangeIgnoreType getIgnoreType() {
      return ignoreType;
   }

   public void setIgnoreType(ChangeIgnoreType type) {
      this.ignoreType = type;
   }

   public void setSynthetic(boolean synthetic) {
      this.synthetic = synthetic;
   }

   public boolean isApplicabilityCopy() {
      return isApplicabilityCopy;
   }

   public void setApplicabilityCopy(boolean isApplicabilityCopy) {
      this.isApplicabilityCopy = isApplicabilityCopy;
   }

   public ChangeType getChangeType() {
      return changeType;
   }

   public void setChangeType(ChangeType changeType) {
      this.changeType = changeType;
   }

   public void setArtId(ArtifactId artId) {
      this.artId = artId;
   }

   public void setItemId(Id itemId) {
      this.itemId = itemId;
   }

   public void setItemTypeId(Id itemTypeId) {
      this.itemTypeId = itemTypeId;
   }

   public boolean isSynthetic() {
      return synthetic;
   }

   public ArtifactId getArtId() {
      return artId;
   }

   public Id getItemId() {
      return itemId;
   }

   public Id getItemTypeId() {
      return itemTypeId;
   }

   public ChangeVersion getBaselineVersion() {
      return baselineVersion;
   }

   public ChangeVersion getFirstNonCurrentChange() {
      return firstNonCurrentChange;
   }

   public ChangeVersion getCurrentVersion() {
      return currentVersion;
   }

   public ChangeVersion getDestinationVersion() {
      return destinationVersion;
   }

   public ChangeVersion getNetChange() {
      return netChange;
   }

   public void setBaselineVersion(ChangeVersion baselineVersion) {
      this.baselineVersion = baselineVersion;
   }

   public void setFirstNonCurrentChange(ChangeVersion firstNonCurrentChange) {
      this.firstNonCurrentChange = firstNonCurrentChange;
   }

   public void setCurrentVersion(ChangeVersion currentVersion) {
      this.currentVersion = currentVersion;
   }

   public void setDestinationVersion(ChangeVersion destinationVersion) {
      this.destinationVersion = destinationVersion;
   }

   public void setNetChange(ChangeVersion netChange) {
      this.netChange = netChange;
   }

   public ArtifactId getArtIdB() {
      return artIdB;
   }

   public void setArtIdB(ArtifactId artIdB) {
      this.artIdB = artIdB;
   }

   @Override
   public String toString() {
      String artIdBStr = "";
      if (getChangeType() == ChangeType.RELATION_CHANGE) {
         artIdBStr = " artBId: " + getArtIdB();
      }
      return String.format(
         "ChangeItem %s - itemId:[%s] artId:%s%s typeId:%s base:%s first:%s current:%s destination:%s net:%s synthetic:%s ignoreType:%s",
         getChangeType().name(), itemId, getArtId(), artIdBStr, getItemTypeId(), getBaselineVersion(),
         getFirstNonCurrentChange(), getCurrentVersion(), getDestinationVersion(), getNetChange(), isSynthetic(),
         getIgnoreType().toString());
   }

   @Override
   public boolean equals(Object obj) {
      if (this == obj) {
         return true;
      }
      if (!(obj instanceof ChangeItem)) {
         return false;
      }

      ChangeItem other = (ChangeItem) obj;

      if (itemId.notEqual(other.itemId)) {
         return false;
      }
      if (artId.notEqual(other.artId)) {
         return false;
      }
      if (currentVersion == null) {
         if (other.currentVersion != null) {
            return false;
         }
      } else {
         if (!currentVersion.equals(other.currentVersion)) {
            return false;
         }
      }
      if (itemTypeId.notEqual(other.itemTypeId)) {
         return false;
      }
      return true;
   }

   public boolean totalEquals(ChangeItem other) {
      if (!this.equals(other)) {
         return false;
      }
      if (!this.ignoreType.equals(other.ignoreType)) {
         return false;
      }
      if (!this.changeType.equals(other.changeType)) {
         return false;
      }
      if (!(this.synthetic == other.synthetic)) {
         return false;
      }
      if (!(this.isApplicabilityCopy == other.isApplicabilityCopy)) {
         return false;
      }
      if (this.getArtIdB() != other.getArtIdB()) {
         return false;
      }
      if (baselineVersion == null) {
         if (other.baselineVersion != null) {
            return false;
         }
      } else {
         if (!baselineVersion.equals(other.baselineVersion)) {
            return false;
         }
      }
      if (destinationVersion == null) {
         if (other.destinationVersion != null) {
            return false;
         }
      } else {
         if (!destinationVersion.equals(other.destinationVersion)) {
            return false;
         }
      }
      if (netChange == null) {
         if (other.netChange != null) {
            return false;
         }
      } else {
         if (!netChange.equals(other.netChange)) {
            return false;
         }
      }
      if (firstNonCurrentChange == null) {
         if (other.firstNonCurrentChange != null) {
            return false;
         }
      } else {
         if (!firstNonCurrentChange.equals(other.firstNonCurrentChange)) {
            return false;
         }
      }
      return true;
   }

   @Override
   public int compareTo(ChangeItem obj) {
      return itemId.getId().compareTo(obj.itemId.getId());
   }

   @Override
   public int hashCode() {
      return itemId.getId().hashCode();
   }

   public boolean isDeleted() {
      return getNetChange().getModType().equals(ModificationType.DELETED) || getNetChange().getModType().equals(
         ModificationType.ARTIFACT_DELETED) || getCurrentVersion().getModType().equals(
            ModificationType.DELETED) || getCurrentVersion().getModType().equals(ModificationType.ARTIFACT_DELETED);
   }

   public static StringBuilder toString(Collection<ChangeItem> items) {
      List<ChangeItem> sItems = new ArrayList<>(items);
      Collections.sort(sItems, new Comparator<ChangeItem>() {

         @Override
         public int compare(ChangeItem o1, ChangeItem o2) {
            if (o1.getArtId().equals(o2.getArtId())) {
               return o1.getItemId().getId().compareTo(o2.getItemId().getId());
            } else {
               return o1.getArtId().getId().compareTo(o2.getArtId().getId());
            }
         }
      });
      StringBuilder sb = new StringBuilder();
      for (ChangeItem item : sItems) {
         sb.append(item.toString());
         sb.append("\n");
      }
      return sb;
   }
}

Back to the top