1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.rat.license;
20
21 import org.apache.commons.lang3.StringUtils;
22 import org.apache.rat.ConfigurationException;
23
24
25
26
27 public interface ILicenseFamily extends Comparable<ILicenseFamily> {
28
29
30 ILicenseFamily UNKNOWN = new Builder().setLicenseFamilyName("Unknown license").setLicenseFamilyCategory("?????").build();
31
32
33
34
35
36 String getFamilyName();
37
38
39
40
41
42 String getFamilyCategory();
43
44
45
46
47
48 static ILicenseFamily.Builder builder() {
49 return new Builder();
50 }
51
52
53
54
55
56
57
58
59 static String makeCategory(String cat) {
60 return cat == null ? " " : cat.concat(" ").substring(0, Builder.CATEGORY_LENGTH);
61 }
62
63 @Override
64 default int compareTo(ILicenseFamily other) {
65 return getFamilyCategory().compareTo(other.getFamilyCategory());
66 }
67
68
69
70
71 class Builder {
72
73 private static final int CATEGORY_LENGTH = 5;
74
75 private String licenseFamilyCategory;
76
77 private String licenseFamilyName;
78
79
80
81
82
83
84
85
86 public Builder setLicenseFamilyCategory(final String licenseFamilyCategory) {
87 this.licenseFamilyCategory = licenseFamilyCategory;
88 return this;
89 }
90
91
92
93
94
95
96
97 public Builder setLicenseFamilyName(final String licenseFamilyName) {
98 this.licenseFamilyName = licenseFamilyName;
99 return this;
100 }
101
102
103
104
105
106
107 public String getCategory() {
108 return licenseFamilyCategory;
109 }
110
111
112
113
114
115 public ILicenseFamily build() {
116 if (StringUtils.isBlank(licenseFamilyCategory)) {
117 throw new ConfigurationException("LicenseFamily Category must be specified");
118 }
119 if (StringUtils.isBlank(licenseFamilyName)) {
120 throw new ConfigurationException("LicenseFamily Name must be specified");
121 }
122 return new ILicenseFamily() {
123 private final String cat = ILicenseFamily.makeCategory(licenseFamilyCategory);
124 private final String name = licenseFamilyName;
125 @Override
126 public String toString() {
127 return String.format("%s %s", getFamilyCategory(), getFamilyName());
128 }
129
130 @Override
131 public String getFamilyName() {
132 return name;
133 }
134
135 @Override
136 public String getFamilyCategory() {
137 return cat;
138 }
139
140 @Override
141 public boolean equals(final Object other) {
142 if (other == this) {
143 return true;
144 }
145 if (other instanceof ILicenseFamily) {
146 return this.getFamilyCategory().equals(((ILicenseFamily) other).getFamilyCategory());
147 }
148 return false;
149 }
150
151 @Override
152 public int hashCode() {
153 return getFamilyCategory().hashCode();
154 }
155 };
156 }
157 }
158 }