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.rat.license;
20  
21  import org.apache.commons.lang3.StringUtils;
22  import org.apache.rat.ConfigurationException;
23  import org.apache.rat.license.ILicenseFamily.Builder;
24  
25  /**
26   * An instance of the ILicenseFamily Builder.
27   */
28  public class ILicenseFamilyBuilder implements Builder {
29  
30      private String licenseFamilyCategory;
31      private String licenseFamilyName;
32  
33      @Override
34      public Builder setLicenseFamilyCategory(String licenseFamilyCategory) {
35          this.licenseFamilyCategory = licenseFamilyCategory;
36          return this;
37      }
38      
39  
40      @Override
41      public String getCategory() {
42          return licenseFamilyCategory;
43      }
44  
45      @Override
46      public Builder setLicenseFamilyName(String licenseFamilyName) {
47          this.licenseFamilyName = licenseFamilyName;
48          return this;
49      }
50  
51      @Override
52      public ILicenseFamily build() {
53          if (StringUtils.isBlank(licenseFamilyCategory)) {
54              throw new ConfigurationException("LicenseFamily Category must be specified");
55          }
56          if (StringUtils.isBlank(licenseFamilyName)) {
57              throw new ConfigurationException("LicenseFamily Name must be specified");
58          }
59          return new ILicenseFamily() { 
60              private final String cat = ILicenseFamily.makeCategory(licenseFamilyCategory);
61              private final String name = licenseFamilyName;
62              @Override
63              public String toString() {
64                  return String.format("%s %s", getFamilyCategory(), getFamilyName());
65              }
66  
67              @Override
68              public final String getFamilyName() {
69                  return name;
70              }
71  
72              @Override
73              public String getFamilyCategory() {
74                  return cat;
75              }
76          };
77      }
78  }