1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.creadur.tentacles;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.net.URI;
24 import java.util.ArrayList;
25 import java.util.HashSet;
26 import java.util.List;
27 import java.util.Set;
28
29 public class License {
30 private final String text;
31 private final String key;
32 private final Set<Archive> archives = new HashSet<>();
33 private final List<File> locations = new ArrayList<>();
34
35 public License(final String key, final String text) {
36 this.text = text;
37 this.key = key;
38 }
39
40 public String getText() {
41 return this.text;
42 }
43
44 public String getKey() {
45 return this.key;
46 }
47
48 public Set<Archive> getArchives() {
49 return this.archives;
50 }
51
52 public List<File> getLocations() {
53 return this.locations;
54 }
55
56 public Set<URI> locations(final Archive archive) throws IOException {
57 final URI contents = archive.contentsURI();
58 final Set<URI> locations = new HashSet<>();
59 for (final File file : this.locations) {
60 final URI uri = file.toURI();
61 final URI relativize = contents.relativize(uri);
62 if (!relativize.equals(uri)) {
63 locations.add(relativize);
64 }
65 }
66
67 return locations;
68 }
69
70 @Override
71 public boolean equals(final Object o) {
72 if (this == o) {
73 return true;
74 }
75 if (o == null || getClass() != o.getClass()) {
76 return false;
77 }
78
79 final License license = (License) o;
80
81 return this.key.equals(license.key);
82 }
83
84 @Override
85 public int hashCode() {
86 return this.key.hashCode();
87 }
88
89 public boolean implies(final License fullLicense) {
90 return fullLicense.key.contains(this.key);
91 }
92 }