001    package edu.nrao.sss.model.project.scheduling.constraint;
002    
003    import java.util.List;
004    
005    
006    
007    /**
008     * Represents an operating condition such as wind, API, and the position
009     * of the target and evaluates the probability of a scheduling block meeting 
010     * its scientific goals under the operating condition.
011     * @author slovelan
012     */
013    
014    
015    public abstract class  Constraint {
016            
017            protected ConstraintType constraintType = ConstraintType.getDefault();
018            
019            public Constraint( ){
020                    
021            }
022            
023            public Constraint( Constraint c ){
024                    if ( c == null ){
025                            throw new IllegalArgumentException( "Please provide a constraint to copy!" );
026                    }
027                    constraintType = c.getConstraintType();
028            }
029            
030              
031            /**
032             * Returns a <code>ConstraintProbability</code> indicating the probability of success
033             * of the scheduling block with respect to this requirement.
034             * @param currentConditions the current external operating condition the could be the current
035             *        wind speed if the constraint represents wind speed or a date if the constraint
036             *        represents a position elevation.
037             * @return a <code>ConstraintProbability</code> indicating the probability of successful
038             *         completion of this scheduling block under the current operating conditions.
039             */
040              
041             public abstract ConstraintProbability getProbabilitySuccess( List<Constraint> currentConditions );
042             
043             
044             /**
045              * Resets this constraint back to its original default (unspecified value).
046              */
047             
048             public abstract void reset();
049             
050             /**
051              * Returns true if this constraint represents a restriction in terms of scheduling
052              * on the block; false otherwise.
053              * @return true if this constraint is inot in its default state; false otherwise.
054              */
055             public abstract boolean isSpecified();
056            
057             /**
058              * Returns the constraint matching this one in the list.
059              * @param constraints a list of constraints.
060              * @return the constraint matching this one.
061              */
062             
063             protected Constraint getConstraint( List<Constraint> constraints ){
064                     Constraint target = null;
065                     for ( Constraint constraint : constraints ){
066                             ConstraintType ct = constraint.getConstraintType();
067                             if ( constraintType.equals( ct )){
068                                    target = constraint;
069                                    break;
070                             }
071                    } 
072                    return target;
073             }
074             
075             
076             /**
077              * Returns the type of operation condition for this constraint.
078              * @return the <code>ConstraintType</code> for this operating condition.
079              */
080             
081             public ConstraintType getConstraintType(){
082                     return constraintType;
083             }
084             
085             
086             public abstract Object getValue();
087             
088             //----------------------------------------------------------------------------
089             //                      Object methods
090             //----------------------------------------------------------------------------
091             
092             
093             public boolean equals ( Object other ){
094                    boolean result = false;
095                    if ( other instanceof Constraint ){
096                            Constraint otherConstraint = (Constraint) other;
097                            if ( constraintType.equals( otherConstraint.getConstraintType())){
098                                    result = true;
099                            }
100                    }
101                    return result;
102             }
103            
104                    public int hashCode(){
105                              int result = 7;
106                              result = 11 * result  + constraintType.hashCode();
107                              return result;
108                    }
109    }