View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2011-2026 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.qulice.maven;
6   
7   import com.google.common.base.Function;
8   import javax.annotation.Nullable;
9   
10  /**
11   * Converts a checker exclude into exclude param.
12   *
13   * <p>E.g. "checkstyle:.*" will become ".*".</p>
14   *
15   * @since 0.1
16   */
17  final class CheckerExcludes implements Function<String, String> {
18  
19      /**
20       * Name of checker.
21       */
22      private final String checker;
23  
24      /**
25       * Constructor.
26       *
27       * @param checker Name of checker
28       */
29      CheckerExcludes(final String checker) {
30          this.checker = checker;
31      }
32  
33      @Nullable
34      @Override
35      public String apply(@Nullable final String input) {
36          String result = null;
37          if (input != null) {
38              final String[] exclude = input.split(":", 2);
39              final String check = exclude[0];
40              final boolean appropriate = "*".equals(check)
41                  || this.checker.equals(check);
42              if (appropriate && exclude.length > 1) {
43                  result = exclude[1];
44              }
45          }
46          return result;
47      }
48  }