1 20 21 22 package org.snmp4j.agent; 23 24 import org.snmp4j.smi.OctetString; 25 import org.snmp4j.smi.OID; 26 27 35 public class DefaultMOContextScope 36 extends DefaultMOScope implements MOContextScope 37 { 38 39 private OctetString context; 40 41 54 public DefaultMOContextScope(OctetString context, 55 OID lowerBound, boolean lowerIncluded, 56 OID upperBound, boolean upperIncluded) { 57 super(lowerBound, lowerIncluded, upperBound, upperIncluded); 58 this.context = context; 59 } 60 61 67 public DefaultMOContextScope(MOContextScope scope) { 68 super(scope.getLowerBound(), scope.isLowerIncluded(), scope.getUpperBound(), 69 scope.isUpperIncluded()); 70 this.context = scope.getContext(); 71 } 72 73 81 public DefaultMOContextScope(OctetString context, 82 MOScope extendedScope) { 83 super(extendedScope); 84 this.context = context; 85 } 86 87 92 public OctetString getContext() { 93 return context; 94 } 95 96 101 public void setContext(OctetString context) { 102 this.context = context; 103 } 104 105 113 public boolean equals(Object obj) { 114 if (obj instanceof MOContextScope) { 115 MOContextScope other = (MOContextScope)obj; 116 return (context.equals(other.getContext()) && super.equals(obj)); 117 } 118 return false; 119 } 120 121 public int hashCode() { 122 if (context != null) { 123 int hash = super.hashCode(); 124 for (int i = 0; i < context.length(); i++) { 126 hash += context.get(i); 127 hash += (hash << 10); 128 hash ^= (hash >> 6); 129 } 130 hash += (hash << 3); 131 hash ^= (hash >> 11); 132 hash += (hash << 15); 133 return hash; 134 } 135 return super.hashCode(); 136 } 137 138 151 public static final boolean isContextMatching(MOScope a, MOScope b) { 152 if ((a instanceof MOContextScope) && 153 (b instanceof MOContextScope)) { 154 OctetString ca = ((MOContextScope)a).getContext(); 155 OctetString cb = ((MOContextScope)b).getContext(); 156 if ((ca != null) && (!ca.equals(cb))) { 157 return false; 158 } 159 } 160 return true; 161 } 162 163 public boolean isCovered(MOScope other) { 164 if ((context != null) && (other instanceof MOContextScope)) { 165 if (!context.equals(((MOContextScope)other).getContext())) { 166 return false; 167 } 168 } 169 return covers(this, other); 170 } 171 172 public String toString() { 173 return getClass().getName()+"[context="+context+ 174 ",lowerBound="+lowerBound+ 175 ",lowerIncluded="+lowerIncluded+ 176 ",upperBound="+upperBound+ 177 ",upperIncluded="+upperIncluded+"]"; 178 } 179 180 public boolean isOverlapping(MOScope other) { 181 if (!isContextMatching(this, other)) { 182 return false; 183 } 184 return super.isOverlapping(other); 185 } 186 187 } 188 | Popular Tags |