View Javadoc
1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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  }