View Javadoc

1   /*******************************************************************************
2    * Copyright 2013 André Rouél and Dominik Seichter
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   ******************************************************************************/
16  package net.sf.qualitytest.blueprint;
17  
18  import java.lang.reflect.Field;
19  import java.lang.reflect.Method;
20  
21  import javax.annotation.Nonnull;
22  
23  /**
24   * Strategy to determine if an attribute matches and should be replaced with a certain value.
25   * 
26   * An attribute can be matched by name or type.
27   * 
28   * A {@link MatchingStrategy} should implement hashCode so that matching strategies for the same object/type can be
29   * detected and the last one added can be used.
30   * 
31   * @see net.sf.qualitytest.blueprint.strategy.creation.ValueCreationStrategy
32   * 
33   * @author Dominik Seichter
34   */
35  public interface MatchingStrategy {
36  
37  	/**
38  	 * Test if a field matches this strategy.
39  	 * 
40  	 * @param field
41  	 *            A field
42  	 * 
43  	 * @return true if the strategy matches and the {@code ValueCreationStrategy} should be applied
44  	 */
45  	boolean matchesByField(@Nonnull final Field field);
46  
47  	/**
48  	 * Test if a method matches this strategy.
49  	 * 
50  	 * @param method
51  	 *            A method
52  	 * 
53  	 * @return true if the strategy matches and the {@code ValueCreationStrategy} should be applied
54  	 */
55  	boolean matchesByMethod(@Nonnull final Method method);
56  
57  	/**
58  	 * Test if a type matches this strategy.
59  	 * 
60  	 * @param clazz
61  	 *            a clazz type
62  	 * 
63  	 * @return true if the strategy matches and the {@code ValueCreationStrategy} should be applied
64  	 */
65  	boolean matchesByType(@Nonnull final Class<?> clazz);
66  }