001    package edu.nrao.sss.model.project.scheduling.priority;
002    
003    import javax.xml.bind.annotation.XmlRootElement;
004    
005    /**
006     * A measure of importance of a particular type that can be
007     * assigned a weight.
008     * @author slovelan
009     */
010    @XmlRootElement
011    public class Priority {
012            
013            private static final double DEFAULT_VALUE = 0;
014            
015            private PriorityType theType = PriorityType.MEAN_REFEREE_PRIORITY;
016            private double value = DEFAULT_VALUE;
017            
018            //The scheduling tool shall have a facility enabling the operator or NRAO staff to modify the
019            //priorities of SBs in the queue such priority modifications shall always have an associated 
020            //length of time, which shall be specified at the time of the change( e.g., for the next
021            //hour, for the next day, forever.
022            
023            
024            //----------------------------------------------------------------------------------
025            //                           Construction
026            //----------------------------------------------------------------------------------
027            
028            public Priority(){
029    
030            }
031            
032            public Priority( PriorityType theType, double value ){
033                    if ( theType == null ){
034                            throw new IllegalArgumentException( "A priority must have a PriorityType!");
035                    }
036                    this.theType = theType;
037                    this.value   = value;
038            }
039            
040            //Avoid the clone method at all costs
041            public Priority( Priority otherPriority ){
042                    if ( otherPriority == null ){
043                            throw new AssertionError( "Use a no argument constructor if you have nothing to contribute!");
044                    }
045                    this.theType = otherPriority.getPriorityType();
046                    this.value = otherPriority.getPriorityValue();
047            }
048            
049            public double getPriorityValue(){
050                    return value;
051            }
052            
053            public void setPriorityValue( double b ){
054                    value = b;
055            }
056            
057            /**
058             * Returns the <code>PriorityType</code> for this priority.
059             * @return the general category for this <code>Priority</code>; examples
060             * include a referee priority, a scheduling commitee priority, etc.
061             */
062            
063            public PriorityType getPriorityType(){
064                    return theType;
065            }
066            
067            public void setPriorityType( PriorityType aType ){
068                    if ( aType != null ){
069                            theType = aType;
070                    }
071                    else {
072                            throw new AssertionError( "It doesn't make sense to have a priority without a type!" );
073                    }
074            }
075            
076            //--------------------------------------------------------------------
077            //                Object Methods
078            //--------------------------------------------------------------------
079            
080            public boolean equals( Object other ){
081                    boolean result = false;
082                    if ( other instanceof Priority ){
083                            Priority otherPriority = (Priority) other;
084                            if ( theType.equals( otherPriority.getPriorityType())){
085                                    result = true;
086                            }
087                    }
088                    return result;
089            }
090            
091            public int hashCode(){
092                    int result = 7;
093                    result = 11 * result +theType.hashCode();
094                    return result;
095            }
096            
097            //----------------------------------------------------------------------
098            //          Comparing values
099            //----------------------------------------------------------------------
100            
101            public int comparePriorities( Object other ){
102                    Priority otherPriority = (Priority) other;
103                    Double thisValue = new Double( value );
104                    Double otherValue = otherPriority.getPriorityValue();
105                    int result = thisValue.compareTo( otherValue );
106                    return result;
107            }
108            
109            
110    }