001    package org.apache.commons.contract.descriptor;
002    
003    import org.apache.commons.contract.constraints.Constraints;
004    import org.apache.commons.contract.i18n.ParameterBundle;
005    
006    public class ParameterDescriptor extends Descriptor {
007            public final static ParameterDescriptor[] NO_PARAMETERS = new ParameterDescriptor[0];
008            
009        protected Constraints constraints;
010        protected Object defaultValue;
011        protected boolean required;
012    
013        public ParameterDescriptor(String name, ParameterBundle description, Constraints valueDescriptor) {
014            super(name, description);
015            this.constraints = valueDescriptor;
016            this.required = true;
017        }
018    
019        public ParameterDescriptor(String name, ParameterBundle description, Constraints valueDescriptor, Object defaultValue) {
020            super(name, description);
021            this.constraints = valueDescriptor;
022            this.defaultValue  = defaultValue;
023            this.required = false;
024        }
025    
026        public boolean isRequired() {
027            return required;
028        }
029    
030        public void setConstraints(Constraints valueDescriptor) {
031            this.constraints = valueDescriptor;
032        }
033    
034        public Constraints getConstraints() {
035            return constraints;
036        }
037    
038        public void setDefaultValue(Object defaultValue) {
039            this.defaultValue = defaultValue;
040            this.required = true;
041        }
042    
043        public Object getDefaultValue() {
044            return defaultValue;
045        }
046        
047        public boolean equals(Object o) {
048            if ( o instanceof ParameterDescriptor && ((ParameterDescriptor)o).getName().equals(getName())) return true;
049            return false;
050        }
051    }