001    /*
002     * Zmanim Java API
003     * Copyright (C) 2007-2008 Eliyahu Hershfeld
004     * 
005     * This program is free software; you can redistribute it and/or modify it under the terms of the
006     * GNU General Public License as published by the Free Software Foundation; either version 2 of the
007     * License, or (at your option) any later version.
008     * 
009     * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
010     * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011     * General Public License for more details.
012     * 
013     * You should have received a copy of the GNU General Public License along with this program; if
014     * not, write to the Free Software Foundation, Inc. 59 Temple Place - Suite 330, Boston, MA
015     * 02111-1307, USA or connect to: http://www.fsf.org/copyleft/gpl.html
016     */
017    package net.sourceforge.zmanim.util;
018    
019    import java.util.Comparator;
020    import java.util.Date;
021    
022    /**
023     * Wrapper class for an astronomical time, mostly used to sort collections of
024     * astronomical times.
025     * 
026     * @author © Eliyahu Hershfeld 2007-2008
027     * @version 1.0
028     */
029    public class Zman {
030            private String zmanLabel;
031            private Date zman;
032            private long duration;
033            private Date zmanDescription;
034    
035            public Zman(Date date, String label) {
036                    zmanLabel = label;
037                    zman = date;
038            }
039    
040            public Zman(long duration, String label) {
041                    zmanLabel = label;
042                    this.duration = duration;
043            }
044    
045            public Date getZman() {
046                    return zman;
047            }
048    
049            public void setZman(Date date) {
050                    zman = date;
051            }
052    
053            public long getDuration() {
054                    return duration;
055            }
056    
057            public void setDuration(long duration) {
058                    this.duration = duration;
059            }
060    
061            public String getZmanLabel() {
062                    return zmanLabel;
063            }
064    
065            public void setZmanLabel(String label) {
066                    zmanLabel = label;
067            }
068    
069            public static final Comparator DATE_ORDER = new Comparator() {
070                    public int compare(Object o1, Object o2) {
071                            Zman z1 = (Zman) o1;
072                            Zman z2 = (Zman) o2;
073                            return z1.getZman().compareTo(z2.getZman());
074                    }
075            };
076    
077            public static final Comparator NAME_ORDER = new Comparator() {
078                    public int compare(Object o1, Object o2) {
079                            Zman z1 = (Zman) o1;
080                            Zman z2 = (Zman) o2;
081                            return z1.getZmanLabel().compareTo(z2.getZmanLabel());
082                    }
083            };
084    
085            public static final Comparator DURATION_ORDER = new Comparator() {
086                    public int compare(Object o1, Object o2) {
087                            Zman z1 = (Zman) o1;
088                            Zman z2 = (Zman) o2;
089                            return z1.getDuration() == z2.getDuration() ? 0
090                                            : z1.getDuration() > z2.getDuration() ? 1 : -1;
091                    }
092            };
093    
094            /**
095             * @return the zmanDescription
096             */
097            public Date getZmanDescription() {
098                    return zmanDescription;
099            }
100    
101            /**
102             * @param zmanDescription
103             *            the zmanDescription to set
104             */
105            public void setZmanDescription(Date zmanDescription) {
106                    this.zmanDescription = zmanDescription;
107            }
108    }