View Javadoc
1   /*******************************************************************************
2    * Portions created by Sebastian Thomschke are copyright (c) 2005-2013 Sebastian
3    * Thomschke.
4    *
5    * All Rights Reserved. This program and the accompanying materials
6    * are made available under the terms of the Eclipse Public License v1.0
7    * which accompanies this distribution, and is available at
8    * http://www.eclipse.org/legal/epl-v10.html
9    *
10   * Contributors:
11   *     Sebastian Thomschke - initial implementation.
12   *******************************************************************************/
13  package net.sf.oval.internal;
14  
15  import java.lang.reflect.Constructor;
16  import java.lang.reflect.Method;
17  import java.util.LinkedHashSet;
18  import java.util.Set;
19  
20  import net.sf.oval.Check;
21  import net.sf.oval.CheckExclusion;
22  import net.sf.oval.context.ConstructorParameterContext;
23  import net.sf.oval.context.MethodParameterContext;
24  import net.sf.oval.context.OValContext;
25  
26  /**
27   * @author Sebastian Thomschke
28   */
29  public final class ParameterChecks
30  {
31  	public final Set<Check> checks = new LinkedHashSet<Check>(2);
32  	public final Set<CheckExclusion> checkExclusions = new LinkedHashSet<CheckExclusion>(2);
33  
34  	public final int parameterIndex;
35  
36  	public final OValContext context;
37  
38  	public ParameterChecks(final Constructor< ? > ctor, final int paramIndex, final String paramName)
39  	{
40  		context = new ConstructorParameterContext(ctor, paramIndex, paramName);
41  		parameterIndex = paramIndex;
42  	}
43  
44  	public ParameterChecks(final Method method, final int paramIndex, final String paramName)
45  	{
46  		context = new MethodParameterContext(method, paramIndex, paramName);
47  		parameterIndex = paramIndex;
48  	}
49  
50  	public boolean hasChecks()
51  	{
52  		return checks.size() > 0;
53  	}
54  
55  	public boolean hasExclusions()
56  	{
57  		return checkExclusions.size() > 0;
58  	}
59  
60  	public boolean isEmpty()
61  	{
62  		return checks.size() == 0 && checkExclusions.size() == 0;
63  	}
64  }