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 AbstractBuilder setId(String id) {
43          this.id = id;
44          return this;
45      }
46  
47      /**
48       * Returns true if this builder has an ID specified.
49       * @return {@code true} if the id is not null and not blank.
50       */
51      public final boolean hasId() {
52          return !StringUtils.isBlank(id);
53      }
54  
55      /**
56       * Gets the ID as specified in the builder.
57       * @return the id as specified in the builder.
58       */
59      public final String getId() {
60          return id;
61      }
62  
63      @Override
64      public String toString() {
65          return String.format("%s with id %s", this.getClass(), id);
66      }
67  }