KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > snmp > SnmpTimeticks


1 /*
2  * @(#)file SnmpTimeticks.java
3  * @(#)author Sun Microsystems, Inc.
4  * @(#)version 4.11
5  * @(#)date 08/02/09
6  *
7  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
8  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
9  *
10  */

11 // Copyright (c) 1995-96 by Cisco Systems, Inc.
12

13 package com.sun.jmx.snmp;
14
15
16
17 /**
18  * Contains an <CODE>SnmpTimeTick</CODE> value which
19  * has units of 1/100th of a second.
20  *
21  * <p><b>This API is a Sun Microsystems internal API and is subject
22  * to change without notice.</b></p>
23  * @version 4.11 12/19/03
24  * @author Sun Microsystems, Inc
25  * @author Cisco Systems, Inc.
26  */

27
28 public class SnmpTimeticks extends SnmpUnsignedInt {
29
30     // CONSTRUCTORS
31
//-------------
32
/**
33      * Constructs a new <CODE>SnmpTimeticks</CODE> from the specified
34      * integer value.
35      * @param v The initialization value.
36      * @exception IllegalArgumentException The specified value is negative.
37      */

38     public SnmpTimeticks(int v) throws IllegalArgumentException JavaDoc {
39     super(v) ;
40     }
41
42     /**
43      * Constructs a new <CODE>SnmpTimeticks</CODE> from the specified
44      * <CODE>Integer</CODE> value.
45      * @param v The initialization value.
46      * @exception IllegalArgumentException The specified value is negative.
47      */

48     public SnmpTimeticks(Integer JavaDoc v) throws IllegalArgumentException JavaDoc {
49     super(v) ;
50     }
51
52     /**
53      * Constructs a new <CODE>SnmpTimeticks</CODE> from the specified long
54      * value.
55      * <p>If the specified value is greater than {@link
56      * SnmpUnsignedInt#MAX_VALUE SnmpUnsignedInt.MAX_VALUE}, the SnmpTimeTicks
57      * will be initialized with <code>v%(SnmpUnsignedInt.MAX_VALUE+1)</code>.
58      * @param v The initialization value.
59      * @exception IllegalArgumentException if the specified value is negative.
60      */

61     public SnmpTimeticks(long v) throws IllegalArgumentException JavaDoc {
62     super(((v>0)?v&SnmpUnsignedInt.MAX_VALUE:v)) ;
63     }
64
65     /**
66      * Constructs a new <CODE>SnmpTimeticks</CODE> from the specified
67      * <CODE>Long</CODE> value.
68      * <p>If the specified value is greater than {@link
69      * SnmpUnsignedInt#MAX_VALUE SnmpUnsignedInt.MAX_VALUE}, the SnmpTimeTicks
70      * will be initialized with <code>v%(SnmpUnsignedInt.MAX_VALUE+1)</code>.
71      * @param v The initialization value.
72      * @exception IllegalArgumentException if the specified value is negative.
73      */

74     public SnmpTimeticks(Long JavaDoc v) throws IllegalArgumentException JavaDoc {
75     this(v.longValue()) ;
76     }
77
78     // PUBLIC METHODS
79
//---------------
80
/**
81      * Parses the specified long value with time units and
82      * returns a <CODE>String</CODE> of the form <CODE>d days hh:mm:ss</CODE>.
83      * @param timeticks The value to be parsed.
84      * @return The <CODE>String</CODE> representation of the value.
85      */

86     final static public String JavaDoc printTimeTicks(long timeticks) {
87     int seconds, minutes, hours, days;
88     StringBuffer JavaDoc buf = new StringBuffer JavaDoc() ;
89
90     timeticks /= 100;
91     days = (int)(timeticks / (60 * 60 * 24));
92     timeticks %= (60 * 60 * 24);
93
94     hours = (int)(timeticks / (60 * 60)) ;
95     timeticks %= (60 * 60);
96
97     minutes = (int)(timeticks / 60) ;
98     seconds = (int)(timeticks % 60) ;
99
100     if (days == 0) {
101         buf.append(hours + ":" + minutes + ":" + seconds) ;
102         return buf.toString() ;
103     }
104     if (days == 1) {
105         buf.append("1 day ") ;
106     } else {
107         buf.append(days + " days ") ;
108     }
109     buf.append(hours + ":" + minutes + ":" + seconds) ;
110     return buf.toString() ;
111     }
112
113     /**
114      * Converts the timeticks value to its <CODE>String</CODE> form.
115      * The format of the returned <CODE>String</CODE> is <CODE>d days hh:mm:ss</CODE>.
116      * <BR>Note: this method simply calls the {@link #printTimeTicks printTimeTicks} method.
117      * @return The <CODE>String</CODE> representation of the value.
118      */

119     final public String JavaDoc toString() {
120     return printTimeTicks((long)value) ;
121     }
122
123     /**
124      * Returns a textual description of the type object.
125      * @return ASN.1 textual description.
126      */

127     final public String JavaDoc getTypeName() {
128     return name;
129     }
130   
131     // VARIABLES
132
//----------
133
/**
134      * Name of the type.
135      */

136     final static String JavaDoc name = "TimeTicks" ;
137     static final private long serialVersionUID = -5486435222360030630L;
138 }
139
Popular Tags