View Javadoc

1   /*
2    *  File: Umlauf.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.Collections;
24  import java.util.Comparator;
25  import java.util.List;
26  
27  import de.jaret.util.date.Interval;
28  import de.jaret.util.date.IntervalImpl;
29  
30  /***
31   * @author Peter Kliem
32   * @version $Id: Umlauf.java 259 2007-02-16 13:54:00Z olk $
33   */
34  public class Umlauf extends IntervalImpl {
35      protected String _umlaufbezeichnug;
36      protected List _fahrten = new ArrayList();
37      protected Fahrzeug _fahrzeug;
38  
39      /***
40       * @param umlaufbezeichnug
41       */
42      public Umlauf(String umlaufbezeichnug) {
43          _umlaufbezeichnug = umlaufbezeichnug;
44      }
45  
46      /***
47       * @return Returns the fahrzeug.
48       */
49      public Fahrzeug getFahrzeug() {
50          return _fahrzeug;
51      }
52  
53      /***
54       * @param fahrzeug The fahrzeug to set.
55       */
56      public void setFahrzeug(Fahrzeug fahrzeug) {
57          Fahrzeug oldVal = _fahrzeug;
58          _fahrzeug = fahrzeug;
59          firePropertyChange("Fahrzeug", oldVal, fahrzeug);
60      }
61  
62      /***
63       * @return Returns the fahrten.
64       */
65      public List getFahrten() {
66          return _fahrten;
67      }
68  
69      public void addFahrt(Fahrt fahrt) {
70          _fahrten.add(fahrt);
71          // not very fast ...
72          Collections.sort(_fahrten, new Comparator() {
73              public int compare(Object arg0, Object arg1) {
74                  Interval i1 = (Interval) arg0;
75                  Interval i2 = (Interval) arg1;
76  
77                  return i1.getBegin().compareTo(i2.getBegin());
78              }
79          });
80          // TODO könnte man auch direkt aus der sortierten Liste holen
81          if (_begin == null) {
82              setBegin(fahrt.getBegin().copy());
83              setEnd(fahrt.getEnd().copy());
84          } else {
85              if (_begin.compareTo(fahrt.getBegin()) > 0) {
86                  setBegin(fahrt.getBegin().copy());
87              } else if (_end.compareTo(fahrt.getEnd()) < 0) {
88                  setEnd(fahrt.getEnd().copy());
89              }
90          }
91      }
92  
93      /***
94       * @return Returns the umlaufbezeichnug.
95       */
96      public String getUmlaufbezeichnug() {
97          return _umlaufbezeichnug;
98      }
99  }