Source Code Cross Referenced for Counter64.java in  » Net » snmp4j » org » snmp4j » smi » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » snmp4j » org.snmp4j.smi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*_############################################################################
002:          _## 
003:          _##  SNMP4J - Counter64.java  
004:          _## 
005:          _##  Copyright (C) 2003-2008  Frank Fock and Jochen Katz (SNMP4J.org)
006:          _##  
007:          _##  Licensed under the Apache License, Version 2.0 (the "License");
008:          _##  you may not use this file except in compliance with the License.
009:          _##  You may obtain a copy of the License at
010:          _##  
011:          _##      http://www.apache.org/licenses/LICENSE-2.0
012:          _##  
013:          _##  Unless required by applicable law or agreed to in writing, software
014:          _##  distributed under the License is distributed on an "AS IS" BASIS,
015:          _##  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016:          _##  See the License for the specific language governing permissions and
017:          _##  limitations under the License.
018:          _##  
019:          _##########################################################################*/
020:
021:        package org.snmp4j.smi;
022:
023:        import java.io.*;
024:        import java.math.BigInteger;
025:        import org.snmp4j.asn1.BER;
026:        import org.snmp4j.asn1.BERInputStream;
027:
028:        /**
029:         * The <code>Counter64</code> class represents a 64bit unsigned integer type.
030:         * It is used for monotonically increasing values that wrap around at
031:         * 2^64-1 (18446744073709551615).
032:         * <p>
033:         * The unsigned 64bit value is represented by a signed 64bit long value
034:         * internally.
035:         *
036:         * @author Frank Fock
037:         * @version 1.8
038:         */
039:        public class Counter64 extends AbstractVariable implements 
040:                AssignableFromLong, AssignableFromString {
041:
042:            private static final long serialVersionUID = 8741539680564150071L;
043:
044:            private long value = 0;
045:
046:            public Counter64() {
047:            }
048:
049:            public Counter64(long value) {
050:                setValue(value);
051:            }
052:
053:            public void encodeBER(OutputStream outputStream)
054:                    throws java.io.IOException {
055:                BER.encodeUnsignedInt64(outputStream, BER.COUNTER64, value);
056:            }
057:
058:            public void decodeBER(BERInputStream inputStream)
059:                    throws java.io.IOException {
060:                BER.MutableByte type = new BER.MutableByte();
061:                long newValue = BER.decodeUnsignedInt64(inputStream, type);
062:                if (type.getValue() != BER.COUNTER64) {
063:                    throw new IOException(
064:                            "Wrong type encountered when decoding Counter64: "
065:                                    + type.getValue());
066:                }
067:                setValue(newValue);
068:            }
069:
070:            public int getSyntax() {
071:                return SMIConstants.SYNTAX_COUNTER64;
072:            }
073:
074:            public int hashCode() {
075:                return (int) value;
076:            }
077:
078:            public int getBERLength() {
079:                if (value < 0L) {
080:                    return 11;
081:                }
082:                if (value < 0x80000000L) {
083:                    if (value < 0x8000L) {
084:                        return (value < 0x80L) ? 3 : 4;
085:                    }
086:                    return (value < 0x800000L) ? 5 : 6;
087:                }
088:                if (value < 0x800000000000L) {
089:                    return (value < 0x8000000000L) ? 7 : 8;
090:                }
091:                return (value < 0x80000000000000L) ? 9 : 10;
092:            }
093:
094:            public boolean equals(Object o) {
095:                if (o instanceof  Counter64) {
096:                    return ((Counter64) o).value == value;
097:                }
098:                return false;
099:            }
100:
101:            public int compareTo(Object o) {
102:                long other = ((Counter64) o).value;
103:                for (int i = 63; i >= 0; i--) {
104:                    if (((value >> i) & 1) != ((other >> i) & 1)) {
105:                        if (((value >> i) & 1) != 0) {
106:                            return 1;
107:                        } else {
108:                            return -1;
109:                        }
110:                    }
111:                }
112:                return 0;
113:            }
114:
115:            public String toString() {
116:                if ((value > 0) && (value < Long.MAX_VALUE)) {
117:                    return Long.toString(value);
118:                }
119:                byte[] bytes = new byte[8];
120:                for (int i = 0; i < 8; i++) {
121:                    bytes[i] = (byte) ((value >> ((7 - i) * 8)) & 0xFF);
122:                }
123:                BigInteger i64 = new BigInteger(1, bytes);
124:                return i64.toString();
125:            }
126:
127:            public void setValue(String value) {
128:                this .value = Long.parseLong(value);
129:            }
130:
131:            public void setValue(long value) {
132:                this .value = value;
133:            }
134:
135:            public long getValue() {
136:                return value;
137:            }
138:
139:            public Object clone() {
140:                return new Counter64(value);
141:            }
142:
143:            /**
144:             * Increment the value of the counter by one. If the current value is
145:             * 2^63-1 (9223372036854775807) then value will be set to -2^63. Nevertheless,
146:             * the BER encoded value of this counter will always be unsigned!
147:             */
148:            public void increment() {
149:                value++;
150:            }
151:
152:            public final int toInt() {
153:                return (int) getValue();
154:            }
155:
156:            public final long toLong() {
157:                return getValue();
158:            }
159:
160:            public OID toSubIndex(boolean impliedLength) {
161:                throw new UnsupportedOperationException();
162:            }
163:
164:            public void fromSubIndex(OID subIndex, boolean impliedLength) {
165:                throw new UnsupportedOperationException();
166:            }
167:
168:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.