View Javadoc
1   /*
2    * #%L
3    * settings4j
4    * ===============================================================
5    * Copyright (C) 2008 - 2015 Brabenetz Harald, Austria
6    * ===============================================================
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * 
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package org.settings4j;
21  
22  /**
23   * Interface to implement an cumied filter.
24   * <p>
25   * The default implementation is in {@link org.settings4j.settings.DefaultFilter}.
26   * </p>
27   * <p>
28   * A simple "Never-Filter" whould look like:
29   * </p>
30   *
31   * <pre>
32   * /\u200b*\u200b*
33   *  * The simplest default implementation doesn't filter.
34   *  *\u200b/
35   * public static final Filter NO_FILTER = new Filter() {
36   *     public void addExclude(final String pattern) {
37   *         throw new java.lang.IllegalStateException("This instance of Filter cannot be modified.");
38   *     }
39   *     public void addInclude(final String pattern) {
40   *         throw new java.lang.IllegalStateException("This instance of Filter cannot be modified.");
41   *     }
42   *     public boolean isValid(final String key) {
43   *         return true;
44   *     }
45   * };
46   * </pre>
47   *
48   * @author Harald.Brabenetz
49   */
50  public interface Filter {
51  
52      /**
53       * Add an include Pattern (Which pattern-Syntax is determinate by the implementation).
54       *
55       * @param pattern the pattern.
56       */
57      void addInclude(String pattern);
58  
59      /**
60       * Add an exclude Pattern (Which pattern-Syntax is determinate by the implementation).
61       *
62       * @param pattern the pattern.
63       */
64      void addExclude(String pattern);
65  
66      /**
67       * Return true if the key is not filtered out.
68       * @param key The key to check.
69       * @return true if the key is not filtered out.
70       */
71      boolean isValid(String key);
72  }