001    /*******************************************************************************
002     * Portions created by Sebastian Thomschke are copyright (c) 2005-2011 Sebastian
003     * Thomschke.
004     * 
005     * All Rights Reserved. This program and the accompanying materials
006     * are made available under the terms of the Eclipse Public License v1.0
007     * which accompanies this distribution, and is available at
008     * http://www.eclipse.org/legal/epl-v10.html
009     * 
010     * Contributors:
011     *     Sebastian Thomschke - initial implementation.
012     *******************************************************************************/
013    package net.sf.oval.internal;
014    
015    import java.lang.reflect.Constructor;
016    import java.lang.reflect.Method;
017    import java.util.Set;
018    
019    import net.sf.oval.Check;
020    import net.sf.oval.CheckExclusion;
021    import net.sf.oval.context.ConstructorParameterContext;
022    import net.sf.oval.context.MethodParameterContext;
023    import net.sf.oval.context.OValContext;
024    import net.sf.oval.internal.util.LinkedSet;
025    
026    /**
027     * @author Sebastian Thomschke
028     */
029    public final class ParameterChecks
030    {
031            public final Set<Check> checks = new LinkedSet<Check>(2);
032            public final Set<CheckExclusion> checkExclusions = new LinkedSet<CheckExclusion>(2);
033    
034            public final int parameterIndex;
035    
036            public final OValContext context;
037    
038            public ParameterChecks(final Constructor< ? > ctor, final int paramIndex, final String paramName)
039            {
040                    context = new ConstructorParameterContext(ctor, paramIndex, paramName);
041                    parameterIndex = paramIndex;
042            }
043    
044            public ParameterChecks(final Method method, final int paramIndex, final String paramName)
045            {
046                    context = new MethodParameterContext(method, paramIndex, paramName);
047                    parameterIndex = paramIndex;
048            }
049    
050            public boolean hasChecks()
051            {
052                    return checks.size() > 0;
053            }
054    
055            public boolean hasExclusions()
056            {
057                    return checkExclusions.size() > 0;
058            }
059    
060            public boolean isEmpty()
061            {
062                    return checks.size() == 0 && checkExclusions.size() == 0;
063            }
064    }