1 package org.apache.commons.contract.descriptor; 2 3 import org.apache.commons.contract.constraints.Constraints; 4 import org.apache.commons.contract.i18n.ParameterBundle; 5 6 public class ParameterDescriptor extends Descriptor { 7 public final static ParameterDescriptor[] NO_PARAMETERS = new ParameterDescriptor[0]; 8 9 protected Constraints constraints; 10 protected Object defaultValue; 11 protected boolean required; 12 13 public ParameterDescriptor(String name, ParameterBundle description, Constraints valueDescriptor) { 14 super(name, description); 15 this.constraints = valueDescriptor; 16 this.required = true; 17 } 18 19 public ParameterDescriptor(String name, ParameterBundle description, Constraints valueDescriptor, Object defaultValue) { 20 super(name, description); 21 this.constraints = valueDescriptor; 22 this.defaultValue = defaultValue; 23 this.required = false; 24 } 25 26 public boolean isRequired() { 27 return required; 28 } 29 30 public void setConstraints(Constraints valueDescriptor) { 31 this.constraints = valueDescriptor; 32 } 33 34 public Constraints getConstraints() { 35 return constraints; 36 } 37 38 public void setDefaultValue(Object defaultValue) { 39 this.defaultValue = defaultValue; 40 this.required = true; 41 } 42 43 public Object getDefaultValue() { 44 return defaultValue; 45 } 46 47 public boolean equals(Object o) { 48 if ( o instanceof ParameterDescriptor && ((ParameterDescriptor)o).getName().equals(getName())) return true; 49 return false; 50 } 51 }