001    package org.hackystat.utilities.time.interval;
002    
003    import java.util.Iterator;
004    
005    /**
006     * Provides a general interval type.
007     * 
008     * @author Hongbing Kou
009     */
010    public abstract class Interval {
011      /** Interval type. */
012      private final String intervalType;
013    
014      /**
015       * Instantiates an interval object.
016       * 
017       * @param intervalType Interval name.
018       */
019      public Interval(String intervalType) {
020        this.intervalType = intervalType;
021      }
022      
023      /**
024       * Gets interval type.
025       * 
026       * @return Interval type.
027       */
028      public String getIntervalType() {
029        return this.intervalType;
030      }
031      
032      /**
033       * Gets iterator over the interval.
034       * 
035       * @return Iterator over the interval.
036       */
037      public abstract Iterator<?> iterator();
038      
039      /**
040       * Whether this interval is a daily interval type.
041       * 
042       * @return True if so and false otherwise.
043       */
044      public boolean isDailyInterval() {
045        return this instanceof DayInterval;
046      }
047    
048      /**
049       * Whether this interval is a week interval type.
050       * 
051       * @return True if so and false otherwise.
052       */
053      public boolean isWeeklyInterval() {
054        return this instanceof WeekInterval;
055      }
056    
057      /**
058       * Whether this interval is a month interval type.
059       * 
060       * @return True if so and false otherwise.
061       */
062      public boolean isMonthlyInterval() {
063        return this instanceof MonthInterval;
064      }
065    }