View Javadoc

1   package net.sf.twip.parameterhandler;
2   
3   import net.sf.twip.internal.TwipConfigurationErrorInvalidEnumAssume;
4   import net.sf.twip.util.Parameter;
5   
6   /**
7    * Enums can be compared by their ordinal.
8    */
9   public class EnumParameterHandler extends AbstractNumberParameterHandler {
10  	public EnumParameterHandler(Parameter parameter) {
11  		super(parameter);
12  	}
13  
14  	@Override
15  	protected Comparable<? extends Number> getComparable(String value) {
16  		final Object[] values = getDefaultParameterValues();
17  		for (int i = 0; i < values.length; i++) {
18  			if (value.equals(values[i].toString())) {
19  				return i;
20  			}
21  		}
22  		throw new TwipConfigurationErrorInvalidEnumAssume("invalid enum value " + value
23  				+ " in Assume expression");
24  	}
25  
26  	@Override
27  	protected Object[] getDefaultParameterValues() {
28  		return parameter.getType().getEnumConstants();
29  	}
30  
31  	@Override
32  	public boolean test(Object value) {
33  		final Object[] values = getDefaultParameterValues();
34  		for (int i = 0; i < values.length; i++) {
35  			if (value.equals(values[i])) {
36  				return super.test(i);
37  			}
38  		}
39  		throw new TwipConfigurationErrorInvalidEnumAssume("invalid enum value " + value
40  				+ " in Assume expression!!!");
41  	}
42  }