Path: blob/master/src/jdk.jcmd/share/classes/sun/tools/jstat/Scale.java
41159 views
/*1* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.tools.jstat;2627import java.util.*;2829/**30* A typesafe enumeration for describing data scaling semantics31*32* @author Brian Doherty33* @since 1.534*/35public class Scale {36private static int nextOrdinal = 0;37private static HashMap<String, Scale> map = new HashMap<String, Scale>();3839private final String name;40private final int ordinal = nextOrdinal++;41private final double factor;4243private Scale(String name, double factor) {44this.name = name;45this.factor = factor;46assert !map.containsKey(name);47map.put(name, this);48}4950/**51* Scale representing a no scaling52*/53public static final Scale RAW = new Scale("raw", 1);5455/**56* Scale representing a percent scaling57*/58public static final Scale PERCENT = new Scale("percent", 1/100);5960/**61* Scale representing a kilo scaling62*/63public static final Scale KILO = new Scale("K", 1024);6465/**66* Scale representing a mega scaling67*/68public static final Scale MEGA = new Scale("M", 1024*1024);6970/**71* Scale representing a giga scaling72*/73public static final Scale GIGA = new Scale("G", 1024*1024*1024);7475/**76* Scale representing a tera scaling77*/78public static final Scale TERA = new Scale("T", 1024*1024*1024*1024);7980/**81* Scale representing a tera scaling82*/83public static final Scale PETA = new Scale("P", 1024*1024*1024*1024*1024);8485/**86* Scale representing a pico scaling87*/88public static final Scale PICO = new Scale("p", 10.0E-12);8990/**91* Scale representing a nano scaling92*/93public static final Scale NANO = new Scale("n", 10.0E-9);9495/**96* Scale representing a micro scaling97*/98public static final Scale MICRO = new Scale("u", 10.0E-6);99100/**101* Scale representing a milli scaling102*/103public static final Scale MILLI = new Scale("m", 10.0E-3);104105/**106* Scale representing a picosecond scaling107*/108public static final Scale PSEC = new Scale("ps", 10.0E-12);109110/**111* Scale representing a nanosecond scaling112*/113public static final Scale NSEC = new Scale("ns", 10.0E-9);114115/**116* Scale representing a microsecond scaling117*/118public static final Scale USEC = new Scale("us", 10.0E-6);119120/**121* Scale representing a millisecond scaling122*/123public static final Scale MSEC = new Scale("ms", 10.0E-3);124125/**126* Scale representing a second scaling127*/128public static final Scale SEC = new Scale("s", 1);129public static final Scale SEC2 = new Scale("sec", 1);130131/**132* Scale representing a minutes scaling133*/134public static final Scale MINUTES = new Scale("min", 1/60.0);135136/**137* Scale representing a hours scaling138*/139public static final Scale HOUR = new Scale("h", 1/(60.0*60.0));140public static final Scale HOUR2 = new Scale("hour", 1/(60.0*60.0));141142/**143* Returns the scaling factor of this Scale object144*145* @return the scaling factor of this Scale object146*/147public double getFactor() {148return factor;149}150151/**152* Returns the string representation of this Scale object.153* The string representation is the name of the Scale object.154*155* @return the string representation of this Scale object156*/157public String toString() {158return name;159}160161/**162* Maps a string to its corresponding Scale object.163*164* @param s a string to match against Scale objects.165* @return The Scale object matching the given string.166*/167public static Scale toScale(String s) {168return map.get(s);169}170171/**172* Returns an enumeration of the keys for this enumerated type173*174* @param s an string to match against Scale objects.175* @return The Scale object matching the given string.176*/177protected static Set<String> keySet() {178return map.keySet();179}180181protected double scale(double value) {182return value/factor;183}184}185186187