001    package util;
002    
003    import java.text.DecimalFormat;
004    
005    /**
006     * A data container to hold the emission line instances and hold a reference
007     * to the source star.
008     */
009    public class Line implements Comparable {
010    
011        static DecimalFormat formatter = new DecimalFormat("0.00");
012    
013        Star source;
014        double wavelength;
015        //double width;
016        //double strength;
017        //double redshift;
018    
019        public Line(Star aSource, double aWavelength) {
020            source = aSource;
021            wavelength = aWavelength;
022        }
023    
024        public int compareTo(Object aLine) {
025            if (aLine == null)
026                throw(new NullPointerException("Compare to null Line instance"));
027            else if (aLine instanceof Line) {
028                double w = ((Line) aLine).getWavelength();
029                if (getWavelength() > w) return 1;
030                else if (getWavelength() < w) return -1;
031            }
032            return 0;
033        }
034    
035        public Star getSource() {
036            return source;
037        }
038    
039        public double getWavelength() {
040            return wavelength;
041        }
042    
043        //TODO: make this more flexible
044        public String toString() {
045            String wavelengthString = formatter.format(getWavelength());
046            if (wavelengthString.length() == 7) wavelengthString = " " + wavelengthString;
047            return wavelengthString;
048        }
049    }