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.net.URI;
23 import java.util.ArrayList;
24 import java.util.HashSet;
25 import java.util.List;
26 import java.util.Set;
27
28 public class Notice {
29 private final String text;
30 private final String key;
31 private final Set<Archive> archives = new HashSet<Archive>();
32 private final List<File> locations = new ArrayList<File>();
33
34 public Notice(final String text) {
35 this.text = text.intern();
36 this.key = text.replaceAll("[ \\n\\t\\r]+", "").toLowerCase().intern();
37 }
38
39 public String getText() {
40 return this.text;
41 }
42
43 public String getKey() {
44 return this.key;
45 }
46
47 public Set<Archive> getArchives() {
48 return this.archives;
49 }
50
51 public List<File> getLocations() {
52 return this.locations;
53 }
54
55 public Set<URI> locations(final Archive archive) {
56 final URI contents = archive.contentsURI();
57 final Set<URI> locations = new HashSet<URI>();
58 for (final File file : this.locations) {
59 final URI uri = file.toURI();
60 final URI relativize = contents.relativize(uri);
61 if (!relativize.equals(uri)) {
62 locations.add(relativize);
63 }
64 }
65
66 return locations;
67 }
68
69 @Override
70 public boolean equals(final Object o) {
71 if (this == o) {
72 return true;
73 }
74 if (o == null || getClass() != o.getClass()) {
75 return false;
76 }
77
78 final Notice notice = (Notice) o;
79
80 if (!this.key.equals(notice.key)) {
81 return false;
82 }
83
84 return true;
85 }
86
87 @Override
88 public int hashCode() {
89 return this.key.hashCode();
90 }
91
92 public boolean implies(final Notice fullLicense) {
93 return fullLicense.key.contains(this.key);
94 }
95
96 }