1   package com.atlassian.plugins.codegen;
2   
3   import com.atlassian.fugue.Option;
4   
5   import static com.atlassian.fugue.Option.none;
6   import static com.atlassian.fugue.Option.some;
7   import static com.google.common.base.Preconditions.checkNotNull;
8   
9   /**
10   * Simple wrapper for a Maven artifact ID with optional group ID.
11   */
12  public final class ArtifactId
13  {
14      private final Option<String> groupId;
15      private final String artifactId;
16      
17      public static ArtifactId artifactId(String artifactId)
18      {
19          return new ArtifactId(none(String.class), artifactId);
20      }
21      
22      public static ArtifactId artifactId(String groupId, String artifactId)
23      {
24          return new ArtifactId(some(groupId), artifactId); 
25      }
26      
27      public static ArtifactId artifactId(Option<String> groupId, String artifactId)
28      {
29          return new ArtifactId(groupId, artifactId); 
30      }
31      
32      private ArtifactId(Option<String> groupId, String artifactId)
33      {
34          this.groupId = checkNotNull(groupId, "groupId");
35          this.artifactId = checkNotNull(artifactId, "artifactId");
36      }
37      
38      public Option<String> getGroupId()
39      {
40          return groupId;
41      }
42      
43      public String getArtifactId()
44      {
45          return artifactId;
46      }
47  
48      public String getCombinedId()
49      {
50          for (String g : groupId)
51          {
52              return g + ":" + artifactId;
53          }
54          return artifactId;
55      }
56      
57      @Override
58      public String toString()
59      {
60          return getCombinedId();
61      }
62      
63      @Override
64      public boolean equals(Object other)
65      {
66          if (other instanceof ArtifactId)
67          {
68              ArtifactId c = (ArtifactId) other;
69              return groupId.equals(c.groupId) && artifactId.equals(c.artifactId);
70          }
71          return false;
72      }
73      
74      @Override
75      public int hashCode()
76      {
77          return getCombinedId().hashCode();
78      }
79  }