KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > monitorenter > gui > chart > traces > Trace2DBijective


1 /*
2  * Trace2DBijective, a list- based implementation of a ITrace2D that only
3  * allows a single occurance of a certain x- value.
4  * Copyright (C) 2002 Achim Westermann, Achim.Westermann@gmx.de
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library 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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  * If you modify or optimize the code in a useful way please let me know.
21  * Achim.Westermann@gmx.de
22  */

23
24 package info.monitorenter.gui.chart.traces;
25
26
27 import info.monitorenter.gui.chart.TracePoint2D;
28
29 import java.util.Iterator JavaDoc;
30
31 /**
32  * A <code> Trace2D</code> who only allows a single occurance of a tracepoint
33  * with a certain x- value xi. <br>
34  * <p>
35  * From <i>y1 = f(x1) = f(x2) </i> follows: <i>x1==x2 </i> (injective) <br>
36  * For every y- value yi contained there exists at least one value xi
37  * (surjective) <br>
38  * Both qualities joined result in a bijective assignment between x and y
39  * values.
40  * </p>
41  * <p>
42  * The policy for both <code>addPoint</code>- methods is implemented as
43  * follows: <br>
44  * <ul>
45  * <li>Every point whose x- value is not contained yet is appended at the end
46  * of the internal list.</li>
47  * <li>If the x- value is contained before, the tracepoint with that value is
48  * removed and the new point is added to the end of the internal list. <b>In
49  * that case the new tracepoint is not inserted at the location where the old
50  * point used to be! </b></li>
51  * </ul>
52  * </p>
53  *
54  * @author Achim Westermann <a
55  * HREF='mailto:Achim.Westermann@gmx.de'>Achim.Westermann@gmx.de </a>
56  *
57  * @version $Revision: 1.2 $
58  */

59 public class Trace2DBijective extends Trace2DSimple {
60
61   /**
62    * Defcon of this stateless instance.
63    */

64   public Trace2DBijective() {
65   }
66
67   /**
68    * @see ATrace2D#addPointInternal(info.monitorenter.gui.chart.TracePoint2D)
69    */

70   public boolean addPointInternal(final TracePoint2D p) {
71     double px = p.getX();
72     synchronized (this) {
73       Iterator JavaDoc it = this.m_points.iterator();
74       TracePoint2D tmp = null, removed = null;
75       while (it.hasNext()) {
76         tmp = (TracePoint2D) it.next();
77         if (tmp.getX() == px) {
78           it.remove();
79           removed = tmp;
80           break;
81         }
82       }
83       if (removed != null) {
84         this.removePoint(removed);
85         // dont use bound check routines of calling addPoint.
86
return false;
87       }
88       return super.addPointInternal(p);
89     }
90   }
91 }
92
Popular Tags