KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > test > internal > performance > data > Dim


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.test.internal.performance.data;
12
13 import org.eclipse.test.internal.performance.InternalDimensions;
14 import org.eclipse.test.internal.performance.PerformanceTestPlugin;
15 import org.eclipse.test.performance.Dimension;
16
17 /**
18  * @since 3.1
19  */

20 public class Dim implements Dimension {
21     
22     private static Dim[] fgRegisteredDimensions= new Dim[100];
23     
24     private final int fId;
25     private final Unit fUnit;
26     private final int fMultiplier;
27     private final boolean fLargerIsBetter= false; // true indicates that larger values are better
28

29     public static Dim getDimension(int id) {
30         InternalDimensions.COMITTED.getId(); // trigger loading class InternalDimensions
31
if (id >= 0 && id < fgRegisteredDimensions.length)
32             return fgRegisteredDimensions[id];
33         return null;
34     }
35     
36     public Dim(int id) {
37         this(id, Unit.CARDINAL, 1);
38     }
39
40     public Dim(int id, Unit unit) {
41         this(id, unit, 1);
42     }
43
44     public Dim(int id, Unit unit, int multiplier) {
45         
46         if (id >= 0 && id < fgRegisteredDimensions.length) {
47             if (fgRegisteredDimensions[id] == null) {
48                 fgRegisteredDimensions[id]= this;
49             } else
50                 PerformanceTestPlugin.logError("dimension with id '" + id + "' already registered"); //$NON-NLS-1$ //$NON-NLS-2$
51
}
52         fId= id;
53         fUnit= unit;
54         fMultiplier= multiplier;
55     }
56
57     public int getId() {
58         return fId;
59     }
60     
61     public Unit getUnit() {
62         return fUnit;
63     }
64     
65     public int getMultiplier() {
66         return fMultiplier;
67     }
68
69     public boolean largerIsBetter() {
70         return fLargerIsBetter;
71     }
72     
73     public String JavaDoc getName() {
74         return DimensionMessages.getString(fId);
75     }
76     
77     public String JavaDoc toString() {
78         return "Dimension [name=" + getName() + ", " + fUnit + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
79
}
80     
81     public String JavaDoc getDisplayValue(Scalar scalar) {
82         return fUnit.getDisplayValue1(scalar.getMagnitude(), fMultiplier);
83     }
84     
85     public String JavaDoc getDisplayValue(double scalar) {
86         return fUnit.getDisplayValue1(scalar / fMultiplier);
87     }
88 }
89
Popular Tags