View Javadoc

1   /*
2    *  File: Fahrzeug.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    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation; either version 2 of the License, or
9    *  (at your option) any later version.
10   *
11   *  This program is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   *  GNU General Public License for more details.
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   */
20  package de.jaret.examples.timebars.fzd.model;
21  
22  import java.util.ArrayList;
23  import java.util.Iterator;
24  import java.util.List;
25  
26  import de.jaret.util.date.Interval;
27  import de.jaret.util.date.JaretDate;
28  import de.jaret.util.ui.timebars.model.DefaultTimeBarRowModel;
29  
30  /***
31   * @author Peter Kliem
32   * @version $Id: Fahrzeug.java 160 2007-01-02 22:02:40Z olk $
33   */
34  public class Fahrzeug extends DefaultTimeBarRowModel {
35      protected String _fzdNummer;
36      protected List _umlaeufe = new ArrayList();
37      protected FahrzeugInfo _fzgInfo;
38  
39      public Fahrzeug(String fzdNummer) {
40          _fzdNummer = fzdNummer;
41          _fzgInfo = new FahrzeugInfo(fzdNummer);
42          setRowHeader(_fzgInfo);
43  
44      }
45  
46      public FahrzeugInfo getFahrzeugInfo() {
47          return _fzgInfo;
48      }
49  
50      /***
51       * @return Returns the fzdNummer.
52       */
53      public String getFzdNummer() {
54          return _fzdNummer;
55      }
56  
57      /***
58       * @param fzdNummer The fzdNummer to set.
59       */
60      public void setFzdNummer(String fzdNummer) {
61          _fzdNummer = fzdNummer;
62      }
63  
64      /***
65       * @return Returns the umlaeufe.
66       */
67      public List getUmlaeufe() {
68          return _umlaeufe;
69      }
70  
71      public void addUmlauf(Umlauf umlauf) {
72          addInterval(umlauf);
73          _umlaeufe.add(umlauf);
74          umlauf.setFahrzeug(this);
75          Iterator it = umlauf.getFahrten().iterator();
76          while (it.hasNext()) {
77              Fahrt fahrt = (Fahrt) it.next();
78              addInterval(fahrt);
79          }
80      }
81  
82      public void remUmlauf(Umlauf umlauf) {
83          if (_umlaeufe.contains(umlauf)) {
84              Iterator it = umlauf.getFahrten().iterator();
85              while (it.hasNext()) {
86                  Fahrt fahrt = (Fahrt) it.next();
87                  remInterval(fahrt);
88              }
89              remInterval(umlauf);
90  
91          }
92      }
93  
94      /***
95       * @param restKette
96       */
97      public void addUmlaufKette(UmlaufKette kette) {
98          Iterator it = kette.getUmlaeufe().iterator();
99          while (it.hasNext()) {
100             Umlauf u = (Umlauf) it.next();
101             addUmlauf(u);
102         }
103     }
104 
105     /***
106      * @param date
107      * @return
108      */
109     public int getFahrtRest(JaretDate date) {
110         List intervals = getIntervals(date);
111         Iterator it = intervals.iterator();
112         while (it.hasNext()) {
113             Interval interval = (Interval) it.next();
114             if (interval instanceof Fahrt) {
115                 return interval.getEnd().diffSeconds(date);
116             }
117         }
118         return 0;
119     }
120 
121     /***
122      * @param date
123      * @return
124      */
125     public Fahrt getFahrt(JaretDate date) {
126         List intervals = getIntervals(date);
127         Iterator it = intervals.iterator();
128         while (it.hasNext()) {
129             Interval interval = (Interval) it.next();
130             if (interval instanceof Fahrt) {
131                 return (Fahrt) interval;
132             }
133         }
134         return null;
135     }
136 
137 }