Path: blob/master/src/jdk.internal.jvmstat/share/classes/sun/jvmstat/monitor/Units.java
41159 views
/*1* Copyright (c) 2003, 2010, 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.jvmstat.monitor;2627/**28* Provides a typesafe enumeration for describing units of measurement29* attribute for instrumentation objects.30*31* @author Brian Doherty32*/33public class Units implements java.io.Serializable {3435/* The enumeration values for this typesafe enumeration must be36* kept in synchronization with the Units enum in the perfData.hpp file37* in the HotSpot source base.38*/3940private static final int NUNITS=8;4142private static Units[] map = new Units[NUNITS];4344private final String name;45private final int value;4647/**48* An Invalid Units value.49*/50public static final Units INVALID = new Units("Invalid", 0);5152/**53* Units attribute representing unit-less quantities.54*/55public static final Units NONE = new Units("None", 1);5657/**58* Units attribute representing Bytes.59*/60public static final Units BYTES = new Units("Bytes", 2);6162/**63* Units attribute representing Ticks.64*/65public static final Units TICKS = new Units("Ticks", 3);6667/**68* Units attribute representing a count of events.69*/70public static final Units EVENTS = new Units("Events", 4);7172/**73* Units attribute representing String data. Although not really74* a unit of measure, this Units value serves to distinguish String75* instrumentation objects from instrumentation objects of other types.76*/77public static final Units STRING = new Units("String", 5);7879/**80* Units attribute representing Hertz (frequency).81*/82public static final Units HERTZ = new Units("Hertz", 6);8384/**85* Returns a string describing this Unit of measurement attribute86*87* @return String - a descriptive string for this enum.88*/89public String toString() {90return name;91}9293/**94* Returns the integer representation of this Units attribute95*96* @return int - an integer representation of this Units attribute.97*/98public int intValue() {99return value;100}101102/**103* Maps an integer value to its corresponding Units attribute.104* If the integer value does not have a corresponding Units enum105* value, then {@link Units#INVALID} is returned.106*107* @param value an integer representation of counter Units108* @return Units - the Units object for the given <code>value</code>109* or {@link Units#INVALID} if out of range.110*/111public static Units toUnits(int value) {112113if (value < 0 || value >= map.length || map[value] == null) {114return INVALID;115}116117return map[value];118}119120private Units(String name, int value) {121this.name = name;122this.value = value;123map[value] = this;124}125126private static final long serialVersionUID = 6992337162326171013L;127}128129130