]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/units/internal/deprecated/Magnitude.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / units / internal / deprecated / Magnitude.java
1 /*******************************************************************************
2  *  Copyright (c) 2010 Association for Decentralized Information Management in
3  *  Industry THTH ry.
4  *  All rights reserved. This program and the accompanying materials
5  *  are made available under the terms of the Eclipse Public License v1.0
6  *  which accompanies this distribution, and is available at
7  *  http://www.eclipse.org/legal/epl-v10.html
8  *
9  *  Contributors:
10  *      VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.databoard.units.internal.deprecated;
13
14 public enum Magnitude {
15         
16         yotta("Y", 24, "yotta"),
17         zetta("Z", 21, "zetta"),
18         exa("E", 18, "exa"),
19         peta("P", 15, "peta"),
20         tera("T", 12, "tera"),
21         giga("G", 9, "giga"),
22         mega("M", 6, "mega"),
23         kilo("k", 3, "kilo"),
24         hecto("h", 2, "hecto"),
25         deca("da", 1, "deca"),
26         unscaled("", 0, ""),
27         deci("d", -1, "deci"),
28         centi("c", -2, "centi"),
29         milli("m", -3, "milli"),
30         micro("ยต", -6, "micro"),
31         nano("n", -9, "nano"),
32         pico("p", -12, "pico"),
33         femto("f", -15, "femto"),
34         atto("a", -18, "atto"),
35         zepto("z", -21, "zepto"),
36         yocto("y", -24, "yocto")        
37         ;       
38         
39         String symbol;
40         int exp;
41         String name;
42         
43         private Magnitude(String symbol, int exp, String prefix) {
44                 this.symbol = symbol;
45                 this.exp = exp;
46                 this.name = prefix;
47         }
48         
49         public String getPrefix() {
50                 return name;
51         }
52         
53         @Override
54         public String toString() {
55                 return name;
56         }
57         
58         public int getExponent() {
59                 return exp;
60         }
61         
62         /**
63          * Get most suitable magnitude for a value 
64          * 
65          * @param value
66          * @return suitable magnitude
67          */
68         public static Magnitude getSuitable(double value)
69         {
70                 double exp = Math.log10(value);
71                 for (Magnitude m : values()) {
72                         if (m.equals(hecto)||m.equals(deca)) continue;
73                         if (m.exp<exp)
74                                 return m;
75                 }
76                 return yotta;
77         }
78         
79                 
80 }