1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.api;
20
21 import java.util.Arrays;
22 import java.util.Collections;
23 import java.util.HashSet;
24 import java.util.Objects;
25 import java.util.Set;
26
27 abstract class ExtensibleEnums {
28
29 static Language language(String id) {
30 return new DefaultLanguage(id);
31 }
32
33 static PathScope pathScope(String id, ProjectScope projectScope, DependencyScope... dependencyScopes) {
34 return new DefaultPathScope(id, projectScope, dependencyScopes);
35 }
36
37 static ProjectScope projectScope(String id) {
38 return new DefaultProjectScope(id);
39 }
40
41 private static class DefaultExtensibleEnum implements ExtensibleEnum {
42
43 private final String id;
44
45 DefaultExtensibleEnum(String id) {
46 this.id = Objects.requireNonNull(id);
47 }
48
49 public String id() {
50 return id;
51 }
52
53 @Override
54 public int hashCode() {
55 return id().hashCode();
56 }
57
58 @Override
59 public boolean equals(Object obj) {
60 return obj != null && getClass() == obj.getClass() && id().equals(((DefaultExtensibleEnum) obj).id());
61 }
62
63 @Override
64 public String toString() {
65 return getClass().getSimpleName() + "[" + id() + "]";
66 }
67 }
68
69 private static class DefaultPathScope extends DefaultExtensibleEnum implements PathScope {
70 private final ProjectScope projectScope;
71 private final Set<DependencyScope> dependencyScopes;
72
73 DefaultPathScope(String id, ProjectScope projectScope, DependencyScope... dependencyScopes) {
74 super(id);
75 this.projectScope = Objects.requireNonNull(projectScope);
76 this.dependencyScopes =
77 Collections.unmodifiableSet(new HashSet<>(Arrays.asList(Objects.requireNonNull(dependencyScopes))));
78 }
79
80 @Override
81 public ProjectScope projectScope() {
82 return projectScope;
83 }
84
85 @Override
86 public Set<DependencyScope> dependencyScopes() {
87 return dependencyScopes;
88 }
89 }
90
91 private static class DefaultProjectScope extends DefaultExtensibleEnum implements ProjectScope {
92
93 DefaultProjectScope(String id) {
94 super(id);
95 }
96 }
97
98 private static class DefaultLanguage extends DefaultExtensibleEnum implements Language {
99
100 DefaultLanguage(String id) {
101 super(id);
102 }
103 }
104 }