View Javadoc

1   /*
2    *  File: YearIterator.java 
3    *  Copyright (c) 2004-2007  Peter Kliem (Peter.Kliem@jaret.de)
4    *  A commercial license is available, see http://www.jaret.de.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of the Common Public License v1.0
8    * which accompanies this distribution, and is available at
9    * http://www.eclipse.org/legal/cpl-v10.html
10   */
11  package de.jaret.util.date.iterator;
12  
13  import de.jaret.util.date.JaretDate;
14  
15  /**
16   * DateIterator iterating over years.
17   * 
18   * @author kliem
19   * @version $Id: YearIterator.java 828 2009-02-08 13:58:21Z kliem $
20   */
21  public class YearIterator extends AbstractDateIterator implements DateIterator {
22      /** default formatter. */
23      protected IIteratorFormatter _defaultFormatter = new IIteratorFormatter() {
24  
25          /**
26           * {@inheritDoc}
27           */
28          public String getLabel(JaretDate date, Format format) {
29              return Integer.toString(date.getYear());
30          }
31      };
32  
33      /**
34       * {@inheritDoc}
35       */
36      protected void advanceDate(JaretDate date) {
37          date.advanceYears(1);
38      }
39  
40      /**
41       * {@inheritDoc}
42       */
43      public long getApproxStepMilliSeconds() {
44          return 365L * 24L * 60L * 60L * 1000L;
45      }
46  
47      /**
48       * {@inheritDoc}
49       */
50      protected JaretDate correctStartDate(JaretDate date) {
51          date.setTime(0, 0, 0);
52          date.setDay(1);
53          date.setMonth(1);
54          return date;
55      }
56  
57      /**
58       * {@inheritDoc}
59       */
60      protected IIteratorFormatter getDefaultFormatter() {
61          return _defaultFormatter;
62      }
63  
64  }