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 /** 22 * The definition of the license family. 23 */ 24 public interface ILicenseFamily extends Comparable<ILicenseFamily> { 25 26 /** The category for generated files */ 27 static final String GENTERATED_CATEGORY = "GEN "; 28 29 /** The category for unknown licenses */ 30 static final String UNKNOWN_CATEGORY = "?????"; 31 32 /** 33 * Gets the family name. 34 * @return the license family name. 35 */ 36 String getFamilyName(); 37 38 /** 39 * Gets the family category. 40 * @return the license family category. 41 */ 42 String getFamilyCategory(); 43 44 /** 45 * Gets the Builder for license families. 46 * @return A builder for an ILicenseFamily. 47 */ 48 static ILicenseFamily.Builder builder() { 49 return new ILicenseFamilyBuilder(); 50 } 51 52 /** 53 * Convert a potential category string into a category string of exactly 5 54 * characters either by truncating the string or appending spaces as necessary. 55 * 56 * @param cat the string to convert. 57 * @return a string of exactly 5 characters. 58 */ 59 static String makeCategory(String cat) { 60 return cat == null ? " " : cat.concat(" ").substring(0, 5); 61 } 62 63 @Override 64 default int compareTo(ILicenseFamily other) { 65 return getFamilyCategory().compareTo(other.getFamilyCategory()); 66 } 67 68 /** 69 * The definition of an ILicenseFamily builder. 70 */ 71 interface Builder { 72 /** 73 * Sets the license family category. Will trim or extends the string with spaces 74 * to ensure that it is exactly 5 characters. 75 * 76 * @param licenseFamilyCategory the category string 77 * @return this builder for chaining. 78 */ 79 Builder setLicenseFamilyCategory(String licenseFamilyCategory); 80 81 /** 82 * Sets the license family name. 83 * 84 * @param licenseFamilyName the name string 85 * @return this builder for chaining. 86 */ 87 Builder setLicenseFamilyName(String licenseFamilyName); 88 89 /** 90 * Gets the category that this builder is building. 91 * 92 * @return the category that this builder is building. 93 */ 94 String getCategory(); 95 96 /** 97 * Builds the defined license family. 98 * @return a new ILicenseFamily instance. 99 */ 100 ILicenseFamily build(); 101 } 102 }