Skip to main content
summaryrefslogtreecommitdiffstats
blob: ac1665ba6eedf692551cbe9b8afa47928db01607 (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
/*******************************************************************************
 * Copyright (c) 2009 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.model.event;

import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.jdk.core.type.BaseIdentity;

/**
 * @author Donald G. Dunne
 */
public class DefaultBasicGuidArtifact extends BaseIdentity<String> implements IBasicGuidArtifact {
   private static final long serialVersionUID = -4997763989583925345L;
   private final String branchGuid;
   private Long artTypeGuid;

   public DefaultBasicGuidArtifact(String branchGuid, Long artTypeGuid, String artGuid) {
      super(artGuid);
      this.branchGuid = branchGuid;
      this.artTypeGuid = artTypeGuid;
   }

   @Override
   public String getBranchGuid() {
      return branchGuid;
   }

   @Override
   public Long getArtTypeGuid() {
      return artTypeGuid;
   }

   @Override
   public String toString() {
      return String.format("[%s]", getGuid());
   }

   @Override
   public int hashCode() {
      // NOTE This hashcode MUST match that of Artifact class
      return super.hashCode();
   }

   /**
    * Note: DefaultBasicGuidArtifact class does not implement the hashCode, but instead uses the one implemented by
    * Identity. It can not use the branch guid due to the need for IArtifactTokens to match Artifact instances. In
    * addition, the event system requires that the DefaultBasicGuidArtifact and Artifact hashcode matches.
    */
   @Override
   public boolean equals(Object obj) {
      boolean equals = super.equals(obj);
      if (!equals && obj instanceof IBasicGuidArtifact) {
         IBasicGuidArtifact other = (IBasicGuidArtifact) obj;

         if (artTypeGuid == null || other.getArtTypeGuid() == null) {
            equals = false;
         }
         equals = artTypeGuid.equals(other.getArtTypeGuid());

         if (equals && branchGuid == null || other.getBranchGuid() == null) {
            equals = false;
         } else if (equals) {
            equals = branchGuid.equals(other.getBranchGuid());
         }

         if (equals && getGuid() == null || other.getGuid() == null) {
            equals = false;
         } else if (equals) {
            equals = getGuid().equals(other.getGuid());
         }
      }
      return equals;
   }

   public void setArtTypeGuid(Long artTypeGuid) {
      this.artTypeGuid = artTypeGuid;
   }

   public boolean is(IArtifactType... artifactTypes) {
      for (IArtifactType artifactType : artifactTypes) {
         if (artifactType.getGuid().equals(getArtTypeGuid())) {
            return true;
         }
      }
      return false;
   }
}

Back to the top