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       * @param checker Name of checker
27       */
28      CheckerExcludes(final String checker) {
29          this.checker = checker;
30      }
31  
32      @Nullable
33      @Override
34      public String apply(@Nullable final String input) {
35          String result = null;
36          if (input != null) {
37              final String[] exclude = input.split(":", 2);
38              final String check = exclude[0];
39              final boolean appropriate = "*".equals(check)
40                  || this.checker.equals(check);
41              if (appropriate && exclude.length > 1) {
42                  result = exclude[1];
43              }
44          }
45          return result;
46      }
47  }