KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > isac > loadprofile > RampDescription


1 /*
2  * CLIF is a Load Injection Framework
3  * Copyright (C) 2004 France Telecom R&D
4  * Copyright (C) 2004 INRIA
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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * CLIF
21  *
22  * Contact: clif@objectweb.org
23  */

24 package org.objectweb.clif.scenario.util.isac.loadprofile;
25
26 import org.apache.log4j.Category;
27
28 /**
29  * This class represents a ramp, a ramp could be of different types and has some
30  * points to describe it
31  *
32  * @author JC Meillaud
33  * @author A Peyrard
34  */

35 public class RampDescription {
36     // logger
37
static Category cat = Category.getInstance(RampDescription.class.getName());
38
39     /**
40      * Type of RAMP defined
41      */

42     public static final int LINE = 0;
43
44     public static final int ARC = 1;
45
46     public static final int CRENEL_HV = 2;
47
48     public static final int CRENEL_VH = 3;
49
50     public static final String JavaDoc LINE_STRING = "line";
51
52     public static final String JavaDoc ARC_STRING = "arc";
53
54     public static final String JavaDoc CRENEL_HV_STRING = "crenelHV";
55
56     public static final String JavaDoc CRENEL_VH_STRING = "crenelVH";
57
58     public static final Point DEFAULTPOINT = new Point(0, 0);
59
60     public static final Point UNKNOWNPOINT = new Point(-1, -1);
61
62     public static final String JavaDoc POINT_START = "start";
63
64     public static final String JavaDoc POINT_END = "end";
65
66     public static final String JavaDoc POINT_ANGLE = "angle";
67     
68     public static final double UNKNOWN_VALUE = -1;
69
70     /**
71      * attributes
72      */

73     // type of the ramp
74
private int type;
75
76     // ID
77
private String JavaDoc rampId;
78
79     // points
80
private Point start;
81
82     private Point end;
83
84     private Point angle;
85
86     // the multiplying coefficient
87
private double coef = UNKNOWN_VALUE;
88
89     // the real value for a line equation
90
private double real = UNKNOWN_VALUE;
91
92     /////////////////////////////////////////////////////////////////////////
93
// Constructors
94
/////////////////////////////////////////////////////////////////////////
95

96     /**
97      * Build a new ramp description of the given type
98      *
99      * @param type
100      * The type of the ramp description
101      */

102     public RampDescription(String JavaDoc rampId, int type) {
103         this.type = type;
104         this.rampId = rampId;
105         // build the new ramp in function of it type
106
switch (type) {
107         case LINE:
108             this.start = DEFAULTPOINT;
109             this.end = DEFAULTPOINT;
110             this.angle = UNKNOWNPOINT;
111             break;
112         case ARC:
113             this.start = DEFAULTPOINT;
114             this.end = DEFAULTPOINT;
115             this.angle = DEFAULTPOINT;
116             break;
117         case CRENEL_HV:
118         case CRENEL_VH:
119             this.start = DEFAULTPOINT;
120             this.end = DEFAULTPOINT;
121             this.angle = UNKNOWNPOINT;
122             break;
123         default:
124             cat.warn("THIS TYPE OF RAMP IS UNKNOW !!!");
125         }
126     }
127
128     /**
129      * Build a new ramp description with the specified params
130      *
131      * @param type
132      * The type of the ramp description
133      * @param start
134      * The starting point
135      * @param end
136      * The ending point
137      * @param angle
138      * The angle point
139      */

140     public RampDescription(String JavaDoc rampId, int type, Point start, Point end,
141             Point angle) {
142         // set the attributes with the parameters values
143
this.type = type;
144         this.rampId = rampId;
145         this.start = new Point(start.x, start.y);
146         this.end = new Point(end.x, end.y);
147         this.angle = new Point(angle.x, angle.y);
148
149     }
150
151     /**
152      * Build a new ramp description which is the copy of the given ramp
153      * description WARNING THE RAMP KEY WILL BE THE SAME THAN THE RAMP COPIED,
154      * SO DON'T FORGET TO GENERATE A NEW ONE IF NECESSARY
155      *
156      * @param c
157      * The ramp description to be copied
158      */

159     public RampDescription(RampDescription c) {
160         this.type = c.getType();
161         this.rampId = c.getRampId();
162         this.start = new Point(c.getStart().x, c.getStart().y);
163         this.end = new Point(c.getEnd().x, c.getEnd().y);
164         this.angle = new Point(c.getAngle().x, c.getAngle().y);
165         this.coef = c.getCoef();
166         this.real = c.getReal();
167     }
168
169     ///////////////////////////////////////////////////////////////////////////
170
// Methods...
171
///////////////////////////////////////////////////////////////////////////
172

173     public static boolean isDefinedStyle(String JavaDoc style) {
174         if (style.equals(LINE_STRING)||style.equals(CRENEL_HV_STRING)||style.equals(CRENEL_VH_STRING)) {
175             return true ;
176         }
177         return false ;
178     }
179     
180     /**
181      * Overrides the clone method object
182      */

183     public Object JavaDoc clone() {
184         return new RampDescription(this);
185     }
186
187     public void updateRampData() {
188         switch (type) {
189         case LINE:
190             cat.debug("Found a Line Ramp");
191             if (((double) start.x) - ((double) end.x) != 0) {
192                 this.coef = (((double) start.y) - ((double) end.y))
193                         / (((double) start.x) - ((double) end.x));
194             } else
195                 this.coef = 0;
196
197             this.real = ((double) end.y) - (this.coef * ((double) end.x));
198             break;
199         case ARC:
200             cat.debug("Found an Arc Ramp");
201             break;
202         case CRENEL_HV:
203             cat.debug("Found a Crenel_HV Ramp");
204             break;
205         case CRENEL_VH:
206             cat.debug("Found a Crenel_VH Ramp");
207             break;
208         default:
209             cat.warn("THIS TYPE OF RAMP IS UNKNOW !!!");
210         }
211         cat.debug("RAMPDESCRIPTION updated: " + this.toString());
212
213     }
214
215     /**
216      * Method wich return the y value corresponding to x. It depends on the type
217      * of the ramp.
218      *
219      * @param x
220      * @return The corresponding y-axis value
221      */

222     public int getCorrespondingY(int x) {
223         int result = -1;
224         switch (type) {
225         case LINE:
226             result = (int) (this.coef * ((double) x) + this.real);
227             break;
228         case ARC:
229             cat.debug("Found an Arc Ramp");
230             break;
231         case CRENEL_HV:
232             result = this.start.x;
233             break;
234         case CRENEL_VH:
235             result = this.start.y;
236             break;
237         default:
238             cat.warn("THIS TYPE OF RAMP IS UNKNOW !!!");
239         }
240
241         return result;
242     }
243
244     ////////////////////////////////////////////////////////////////////////
245
// Attributes getters and setters
246
////////////////////////////////////////////////////////////////////////
247

248     /**
249      * @return Returns the angle.
250      */

251     public Point getAngle() {
252         return angle;
253     }
254
255     /**
256      * @param angle
257      * The angle to set.
258      */

259     public void setAngle(Point angle) {
260         this.angle = angle;
261     }
262
263     /**
264      * @return Returns the end.
265      */

266     public Point getEnd() {
267         return end;
268     }
269
270     /**
271      * @param end
272      * The end to set.
273      */

274     public void setEnd(Point end) {
275         this.end = end;
276     }
277
278     /**
279      * @return Returns the start.
280      */

281     public Point getStart() {
282         return start;
283     }
284
285     /**
286      * @param start
287      * The start to set.
288      */

289     public void setStart(Point start) {
290         this.start = start;
291     }
292
293     /**
294      * @return Returns the type.
295      */

296     public int getType() {
297         return type;
298     }
299
300     /**
301      * @return Returns the rampId.
302      */

303     public String JavaDoc getRampId() {
304         return rampId;
305     }
306
307     /**
308      * @param rampId
309      * The rampId to set.
310      */

311     public void setRampId(String JavaDoc rampId) {
312         this.rampId = rampId;
313     }
314
315     /**
316      * @return Returns the coef.
317      */

318     public double getCoef() {
319         return coef;
320     }
321
322     /**
323      * @param coef
324      * The coef to set.
325      */

326     public void setCoef(double coef) {
327         this.coef = coef;
328     }
329
330     /**
331      * @return Returns the real.
332      */

333     public double getReal() {
334         return real;
335     }
336
337     /**
338      * @param real
339      * The real to set.
340      */

341     public void setReal(double real) {
342         this.real = real;
343     }
344
345     public String JavaDoc toString() {
346         return "[" + rampId + "(" + type + ") -> start point : " + start
347                 + ",end point : " + end + ",angle point : " + angle
348                 + ",coef : " + coef + ",real : " + real + "]";
349     }
350 }
Popular Tags