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.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  }