001: /*_############################################################################
002: _##
003: _## SNMP4J-AgentX - AgentXRegion.java
004: _##
005: _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
006: _##
007: _## This program is free software; you can redistribute it and/or modify
008: _## it under the terms of the GNU General Public License version 2 as
009: _## published by the Free Software Foundation.
010: _##
011: _## This program is distributed in the hope that it will be useful,
012: _## but WITHOUT ANY WARRANTY; without even the implied warranty of
013: _## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: _## GNU General Public License for more details.
015: _##
016: _## You should have received a copy of the GNU General Public License
017: _## along with this program; if not, write to the Free Software
018: _## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
019: _## MA 02110-1301 USA
020: _##
021: _##########################################################################*/
022:
023: package org.snmp4j.agent.agentx;
024:
025: import org.snmp4j.agent.DefaultMOScope;
026: import org.snmp4j.smi.OID;
027:
028: public class AgentXRegion extends DefaultMOScope implements Comparable {
029:
030: private boolean singleOID;
031: private byte rangeSubID;
032:
033: public AgentXRegion(OID lowerBound, OID upperBound) {
034: super (lowerBound, true, upperBound, false);
035: }
036:
037: public AgentXRegion(AgentXRegion other) {
038: super (other.getLowerBound(), other.isLowerIncluded(), other
039: .getUpperBound(), other.isUpperIncluded());
040: this .singleOID = other.singleOID;
041: this .rangeSubID = other.rangeSubID;
042: }
043:
044: public byte getRangeSubID() {
045: return rangeSubID;
046: }
047:
048: public boolean isSingleOID() {
049: return singleOID;
050: }
051:
052: public void setRangeSubID(byte rangeSubID) {
053: this .rangeSubID = rangeSubID;
054: }
055:
056: public void setSingleOID(boolean singleOID) {
057: this .singleOID = singleOID;
058: }
059:
060: public int getUpperBoundSubID() {
061: if (rangeSubID != 0) {
062: return upperBound.get(rangeSubID - 1);
063: }
064: return 0;
065: }
066:
067: public boolean isRange() {
068: return (rangeSubID > 0);
069: }
070:
071: public boolean isEmpty() {
072: return (lowerBound.compareTo(upperBound) >= 0);
073: }
074:
075: public int getLowerBoundSubID() {
076: if (rangeSubID != 0) {
077: return lowerBound.get(rangeSubID - 1);
078: }
079: return 0;
080: }
081:
082: public int compareTo(Object o) {
083: AgentXRegion other = (AgentXRegion) o;
084: int c = lowerBound.compareTo(other.lowerBound);
085: if (c == 0) {
086: c = upperBound.compareTo(other.upperBound);
087: if (c == 0) {
088: c = rangeSubID - other.rangeSubID;
089: }
090: }
091: return c;
092: }
093:
094: public String toString() {
095: return getClass().getName() + "[lowerBound=" + lowerBound
096: + ",lowerIncluded=" + lowerIncluded + ",upperBound="
097: + upperBound + ",upperIncluded=" + upperIncluded
098: + ",rangeSubID=" + rangeSubID + ",upperBoundSubID="
099: + getUpperBoundSubID() + "]";
100: }
101: }
|