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.configuration.builders;
20  
21  import org.apache.commons.lang3.StringUtils;
22  import org.apache.rat.analysis.IHeaderMatcher;
23  
24  /**
25   * An abstract IHeaderMatcher.Builder.
26   */
27  public abstract class AbstractBuilder implements IHeaderMatcher.Builder {
28  
29      private String id;
30  
31      /**
32       * Protected empty constructor.
33       */
34      protected AbstractBuilder() {
35      }
36  
37      /**
38       * Set the id for the matcher.
39       * @param id the id to use.
40       * @return this builder for chaining.
41       */
42      public final AbstractBuilder setId(String id) {
43          this.id = id;
44          return this;
45      }
46  
47      /**
48       * @return {@code true} if the id is not null and not blank.
49       */
50      public final boolean hasId() {
51          return !StringUtils.isBlank(id);
52      }
53      
54      /**
55       * @return the id as specified in the builder.
56       */
57      protected String getId() {
58          return id;
59      }
60      
61      @Override
62      public String toString() {
63          return String.format( "%s with id %s", this.getClass(), id);
64      }
65  
66  }