Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/jmx/snmp/SnmpCounter64.java
38924 views
/*1* Copyright (c) 1997, 2011, 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*/242526package com.sun.jmx.snmp;27282930/**31* Represents an SNMP 64bits counter.32*33* <p><b>This API is a Sun Microsystems internal API and is subject34* to change without notice.</b></p>35*/3637public class SnmpCounter64 extends SnmpValue {38private static final long serialVersionUID = 8784850650494679937L;3940// CONSTRUCTORS41//-------------42/**43* Constructs a new <CODE>SnmpCounter64</CODE> from the specified long value.44* @param v The initialization value.45* @exception IllegalArgumentException The specified value is negative46* or larger than <CODE>Long.MAX_VALUE</CODE>.47*/48public SnmpCounter64(long v) throws IllegalArgumentException {4950// NOTE:51// The max value for a counter64 variable is 2^64 - 1.52// The max value for a Long is 2^63 - 1.53// All the allowed values for a conuter64 variable cannot be covered !!!54//55if ((v < 0) || (v > Long.MAX_VALUE)) {56throw new IllegalArgumentException() ;57}58value = v ;59}6061/**62* Constructs a new <CODE>SnmpCounter64</CODE> from the specified <CODE>Long</CODE> value.63* @param v The initialization value.64* @exception IllegalArgumentException The specified value is negative65* or larger than <CODE>Long.MAX_VALUE</CODE>.66*/67public SnmpCounter64(Long v) throws IllegalArgumentException {68this(v.longValue()) ;69}7071// PUBLIC METHODS72//---------------73/**74* Returns the counter value of this <CODE>SnmpCounter64</CODE>.75* @return The value.76*/77public long longValue() {78return value ;79}8081/**82* Converts the counter value to its <CODE>Long</CODE> form.83* @return The <CODE>Long</CODE> representation of the value.84*/85public Long toLong() {86return new Long(value) ;87}8889/**90* Converts the counter value to its integer form.91* @return The integer representation of the value.92*/93public int intValue() {94return (int)value ;95}9697/**98* Converts the counter value to its <CODE>Integer</CODE> form.99* @return The <CODE>Integer</CODE> representation of the value.100*/101public Integer toInteger() {102return new Integer((int)value) ;103}104105/**106* Converts the counter value to its <CODE>String</CODE> form.107* @return The <CODE>String</CODE> representation of the value.108*/109public String toString() {110return String.valueOf(value) ;111}112113/**114* Converts the counter value to its <CODE>SnmpOid</CODE> form.115* @return The OID representation of the value.116*/117public SnmpOid toOid() {118return new SnmpOid(value) ;119}120121/**122* Extracts the counter from an index OID and returns its123* value converted as an <CODE>SnmpOid</CODE>.124* @param index The index array.125* @param start The position in the index array.126* @return The OID representing the counter value.127* @exception SnmpStatusException There is no counter value128* available at the start position.129*/130public static SnmpOid toOid(long[] index, int start) throws SnmpStatusException {131try {132return new SnmpOid(index[start]) ;133}134catch(IndexOutOfBoundsException e) {135throw new SnmpStatusException(SnmpStatusException.noSuchName) ;136}137}138139/**140* Scans an index OID, skips the counter value and returns the position141* of the next value.142* @param index The index array.143* @param start The position in the index array.144* @return The position of the next value.145* @exception SnmpStatusException There is no counter value146* available at the start position.147*/148public static int nextOid(long[] index, int start) throws SnmpStatusException {149if (start >= index.length) {150throw new SnmpStatusException(SnmpStatusException.noSuchName) ;151}152else {153return start + 1 ;154}155}156157/**158* Appends an <CODE>SnmpOid</CODE> representing an <CODE>SnmpCounter64</CODE> to another OID.159* @param source An OID representing an <CODE>SnmpCounter64</CODE> value.160* @param dest Where source should be appended.161*/162public static void appendToOid(SnmpOid source, SnmpOid dest) {163if (source.getLength() != 1) {164throw new IllegalArgumentException() ;165}166dest.append(source) ;167}168169/**170* Performs a clone action. This provides a workaround for the171* <CODE>SnmpValue</CODE> interface.172* @return The SnmpValue clone.173*/174final synchronized public SnmpValue duplicate() {175return (SnmpValue)clone() ;176}177178/**179* Clones the <CODE>SnmpCounter64</CODE> object, making a copy of its data.180* @return The object clone.181*/182final synchronized public Object clone() {183SnmpCounter64 newclone = null ;184try {185newclone = (SnmpCounter64) super.clone() ;186newclone.value = value ;187} catch (CloneNotSupportedException e) {188throw new InternalError(e) ; // vm bug.189}190return newclone ;191}192193/**194* Returns a textual description of the type object.195* @return ASN.1 textual description.196*/197final public String getTypeName() {198return name ;199}200201// VARIABLES202//----------203/**204* Name of the type.205*/206final static String name = "Counter64" ;207208/**209* This is where the value is stored. This long is positive.210* @serial211*/212private long value = 0 ;213}214215216