// Path: apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java
// public class SimplePatternBasedLicense extends BaseLicense implements IHeaderMatcher {
//     private String[] patterns;
// 
//     public SimplePatternBasedLicense() {
//     }
// 
//     protected SimplePatternBasedLicense(Datum pLicenseFamilyCategory, Datum pLicenseFamilyName,
//             String pNotes, String[] pPatterns) {
//         super(pLicenseFamilyCategory, pLicenseFamilyName, pNotes);
//         setPatterns(pPatterns);
//     }
//     
//     public String[] getPatterns() {
//         return patterns;
//     }
// 
//     public void setPatterns(String[] pPatterns) {
//         patterns = pPatterns;
//     }
// 
//     protected boolean matches(String pLine) {
//         if (pLine != null) {
//             final String[] pttrns = getPatterns();
//             if (pttrns != null) {
//                 for (String pttrn : pttrns) {
//                     if (pLine.contains(pttrn)) {
//                         return true;
//                     }
//                 }
//             }
//         }
//         return false;
//     }
//     
//     public void reset() {
//         // Nothing to do
//     }
// 
//     public boolean match(Document pSubject, String pLine) throws RatHeaderAnalysisException {
//         final boolean result = matches(pLine);
//         if (result) {
//             reportOnLicense(pSubject);
//         }
//         return result;
//     }
// }


import java.util.ArrayList;
import java.util.List;
import org.apache.rat.analysis.license.SimplePatternBasedLicense;
import org.apache.tools.ant.BuildException;
 /*
 * Licensed to the Apache Software Foundation (ASF) under one   *
 * or more contributor license agreements.  See the NOTICE file *
 * distributed with this work for additional information        *
 * regarding copyright ownership.  The ASF licenses this file   *
 * to you under the Apache License, Version 2.0 (the            *
 * "License"); you may not use this file except in compliance   *
 * with the License.  You may obtain a copy of the License at   *
 *                                                              *
 *   http://www.apache.org/licenses/LICENSE-2.0                 *
 *                                                              *
 * Unless required by applicable law or agreed to in writing,   *
 * software distributed under the License is distributed on an  *
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
 * KIND, either express or implied.  See the License for the    *
 * specific language governing permissions and limitations      *
 * under the License.                                           *
 */ 
package org.apache.rat.anttasks;


/**
 * Adapts {@link SimplePatternBasedLicense SimplePatternBasedLicense}
 * to Ant's method naming conventions so it becomes easy to write
 * substring based license matchers inside an Ant build file.
 * @since Rat Antlib 0.8
 */
public class SubstringLicenseMatcher extends SimplePatternBasedLicense {
    private final List<String> patterns = new ArrayList<>();
    private boolean validated = false;

    public void addConfiguredPattern(Pattern p) {
        patterns.add(p.getSubstring());
    }

    @Override
    public String[] getPatterns() {
        validate();
        return patterns.toArray(new String[0]);
    }

    private void validate() {
        if (!validated) {
// Path: apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java
// public class SimplePatternBasedLicense extends BaseLicense implements IHeaderMatcher {
//     private String[] patterns;
// 
//     public SimplePatternBasedLicense() {
//     }
// 
//     protected SimplePatternBasedLicense(Datum pLicenseFamilyCategory, Datum pLicenseFamilyName,
//             String pNotes, String[] pPatterns) {
//         super(pLicenseFamilyCategory, pLicenseFamilyName, pNotes);
//         setPatterns(pPatterns);
//     }
//     
//     public String[] getPatterns() {
//         return patterns;
//     }
// 
//     public void setPatterns(String[] pPatterns) {
//         patterns = pPatterns;
//     }
// 
//     protected boolean matches(String pLine) {
//         if (pLine != null) {
//             final String[] pttrns = getPatterns();
//             if (pttrns != null) {
//                 for (String pttrn : pttrns) {
//                     if (pLine.contains(pttrn)) {
//                         return true;
//                     }
//                 }
//             }
//         }
//         return false;
//     }
//     
//     public void reset() {
//         // Nothing to do
//     }
// 
//     public boolean match(Document pSubject, String pLine) throws RatHeaderAnalysisException {
//         final boolean result = matches(pLine);
//         if (result) {
//             reportOnLicense(pSubject);
//         }
//         return result;
//     }
// }


// Path: apache-rat-tasks/src/main/java/org/apache/rat/anttasks/SubstringLicenseMatcher.java
import java.util.ArrayList;
import java.util.List;
import org.apache.rat.analysis.license.SimplePatternBasedLicense;
import org.apache.tools.ant.BuildException;

 /*
 * Licensed to the Apache Software Foundation (ASF) under one   *
 * or more contributor license agreements.  See the NOTICE file *
 * distributed with this work for additional information        *
 * regarding copyright ownership.  The ASF licenses this file   *
 * to you under the Apache License, Version 2.0 (the            *
 * "License"); you may not use this file except in compliance   *
 * with the License.  You may obtain a copy of the License at   *
 *                                                              *
 *   http://www.apache.org/licenses/LICENSE-2.0                 *
 *                                                              *
 * Unless required by applicable law or agreed to in writing,   *
 * software distributed under the License is distributed on an  *
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
 * KIND, either express or implied.  See the License for the    *
 * specific language governing permissions and limitations      *
 * under the License.                                           *
 */ 
package org.apache.rat.anttasks;


/**
 * Adapts {@link SimplePatternBasedLicense SimplePatternBasedLicense}
 * to Ant's method naming conventions so it becomes easy to write
 * substring based license matchers inside an Ant build file.
 * @since Rat Antlib 0.8
 */
public class SubstringLicenseMatcher extends SimplePatternBasedLicense {
    private final List<String> patterns = new ArrayList<>();
    private boolean validated = false;

    public void addConfiguredPattern(Pattern p) {
        patterns.add(p.getSubstring());
    }

    @Override
    public String[] getPatterns() {
        validate();
        return patterns.toArray(new String[0]);
    }

    private void validate() {
        if (!validated) {
            validated  = true;