Skip to main content
summaryrefslogtreecommitdiffstats
blob: 82d9c483fd8c6a726b0b69b54763f06114389cf8 (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
/*******************************************************************************
 * 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.core.message;

import org.eclipse.osee.framework.core.enums.ModificationType;
import org.eclipse.osee.framework.core.exception.OseeArgumentException;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeStateException;
import org.eclipse.osee.framework.core.util.Conditions;

/**
 * @author Roberto E. Escobar
 */
public final class ChangeItemUtil {

   private ChangeItemUtil() {
      // Utility Class
   }

   public static ChangeVersion getStartingVersion(ChangeItem item) throws OseeCoreException {
      if (item == null) {
         throw new OseeArgumentException("ChangeItem cannot be null");
      }
      ChangeVersion toReturn = item.getBaselineVersion();
      if (!toReturn.isValid()) {
         toReturn = item.getFirstNonCurrentChange();
         if (!toReturn.isValid()) {
            toReturn = item.getCurrentVersion();
            if (!toReturn.isValid()) {
               throw new OseeStateException("Cannot find a valid starting point for change item: %s", item);
            }
         }
      }
      return toReturn;
   }

   public static void copy(ChangeVersion source, ChangeVersion dest) throws OseeCoreException {
      Conditions.checkNotNull(source, "source");
      Conditions.checkNotNull(dest, "Dest");

      dest.setGammaId(source.getGammaId());
      dest.setModType(source.getModType());
      dest.setValue(source.getValue());
   }

   public static boolean isModType(ChangeVersion changeVersion, ModificationType matchModType) {
      return changeVersion != null && changeVersion.getModType() == matchModType;
   }

   public static boolean isNew(ChangeVersion changeVersion) {
      return isModType(changeVersion, ModificationType.NEW);
   }

   public static boolean isIntroduced(ChangeVersion changeVersion) {
      return isModType(changeVersion, ModificationType.INTRODUCED);
   }

   public static boolean isDeleted(ChangeVersion changeVersion) {
      return changeVersion != null && changeVersion.getModType() != null && changeVersion.getModType().isDeleted();
   }

   public static boolean wasNewOnSource(ChangeItem changeItem) {
      return isNew(changeItem.getFirstNonCurrentChange()) || isNew(changeItem.getCurrentVersion());
   }

   public static boolean wasIntroducedOnSource(ChangeItem changeItem) {
      return isIntroduced(changeItem.getFirstNonCurrentChange()) || isIntroduced(changeItem.getCurrentVersion());
   }

   public static boolean wasNewOrIntroducedOnSource(ChangeItem changeItem) {
      return wasNewOnSource(changeItem) || wasIntroducedOnSource(changeItem);
   }

   public static boolean hasBeenReplacedWithVersion(ChangeItem changeItem) {
      boolean results = areGammasEqual(changeItem.getCurrentVersion(), changeItem.getBaselineVersion()) && //
      isModType(changeItem.getCurrentVersion(), ModificationType.MODIFIED);
      return results;
   }

   public static boolean isAlreadyOnDestination(ChangeItem changeItem) {
      return areGammasEqual(changeItem.getCurrentVersion(), changeItem.getDestinationVersion()) && //
      isDeleted(changeItem.getCurrentVersion()) == isDeleted(changeItem.getDestinationVersion());
   }

   public static boolean areGammasEqual(ChangeVersion object1, ChangeVersion object2) {
      boolean result = false;
      if (object1 == null && object2 == null) {
         result = true;
      } else if (object1 != null && object2 != null) {
         if (object1.getGammaId() == object2.getGammaId()) {
            result = true;
         } else if (object1.getGammaId() != null) {
            result = object1.getGammaId().equals(object2.getGammaId());
         }
      }
      return result;
   }

   public static boolean isIgnoreCase(ChangeItem changeItem) {
      return //
      wasCreatedAndDeleted(changeItem) || //
      isAlreadyOnDestination(changeItem) || //
      isDeletedAndDoesNotExistInDestination(changeItem) || //
      hasBeenDeletedInDestination(changeItem) || //
      isDestinationEqualOrNewerThanCurrent(changeItem) || //
      hasBeenReplacedWithVersion(changeItem);
   }

   public static boolean wasCreatedAndDeleted(ChangeItem changeItem) {
      return wasNewOrIntroducedOnSource(changeItem) && isDeleted(changeItem.getCurrentVersion());
   }

   public static boolean isDeletedAndDoesNotExistInDestination(ChangeItem changeItem) {
      return !changeItem.getDestinationVersion().isValid() && isDeleted(changeItem.getCurrentVersion());
   }

   public static boolean hasBeenDeletedInDestination(ChangeItem changeItem) {
      return changeItem.getDestinationVersion().isValid() && isDeleted(changeItem.getDestinationVersion());
   }

   public static boolean isDestinationEqualOrNewerThanCurrent(ChangeItem changeItem) {
      return (isNew(changeItem.getCurrentVersion()) || isIntroduced(changeItem.getCurrentVersion())) && changeItem.getDestinationVersion().isValid();
   }
}

Back to the top