1 package net.sf.mbus4j.dataframes.datablocks.vif;
2
3 /*
4 * #%L
5 * mbus4j-core
6 * %%
7 * Copyright (C) 2009 - 2014 MBus4J
8 * %%
9 * mbus4j - Drivers for the M-Bus protocol - http://mbus4j.sourceforge.net/
10 * Copyright (C) 2009-2014, mbus4j.sf.net, and individual contributors as indicated
11 * by the @authors tag. See the copyright.txt in the distribution for a
12 * full listing of individual contributors.
13 *
14 * This is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 3 of
17 * the License, or (at your option) any later version.
18 *
19 * This software is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this software; if not, write to the Free
26 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
28 * #L%
29 */
30 /**
31 *
32 * @author arnep@users.sourceforge.net
33 * @version $Id: SiPrefix.java 158 2016-05-06 20:11:35Z arnep $
34 */
35 public enum SiPrefix {
36
37 PICO("p", -15),
38 NANO("n", -12),
39 MICRO("ยต", -6),
40 MILLI("m", -3),
41 CENTI("c", -2),
42 DECI("d", -1),
43 ONE("", 0),
44 DECA("D", 1),
45 HECTO("h",2),
46 KILO("k", 3),
47 MEGA("M", 6),
48 GIGA("G", 12);
49 private final String label;
50 private final double factor;
51 private final int exponent;
52
53 private SiPrefix(String label, int exponent) {
54 this.label = label;
55 this.factor = Math.pow(10, exponent);
56 this.exponent = exponent;
57 }
58
59 @Override
60 public String toString() {
61 return label;
62 }
63
64 /**
65 * @return the label
66 */
67 public String getLabel() {
68 return label;
69 }
70
71 public static SiPrefix fromLabel(String label) {
72 if (label == null) {
73 return null;
74 }
75 for (SiPrefix value : values()) {
76 if (value.getLabel().equals(label)) {
77 return value;
78 }
79 }
80 return valueOf(label);
81 }
82
83 /**
84 * @return the factor
85 */
86 final public double getFactor() {
87 return factor;
88 }
89
90 /**
91 * @return the pow10
92 */
93 final public int getExponent() {
94 return exponent;
95 }
96
97 }