1 20 21 package org.snmp4j.security; 22 23 29 public class ByteArrayWindow { 30 31 private byte[] value; 32 private int offset; 33 private int length; 34 35 45 public ByteArrayWindow(byte[] value, int offset, int length) { 46 this.value = value; 47 this.offset = offset; 48 this.length = length; 49 } 50 51 public byte[] getValue() { 52 return value; 53 } 54 55 public void setValue(byte[] value) { 56 this.value = value; 57 } 58 59 public int getOffset() { 60 return offset; 61 } 62 63 public void set(int i, byte b) { 64 if (i >= length) { 65 throw new IndexOutOfBoundsException ("" + i + " >= " + length); 66 } 67 if (i < 0) { 68 throw new IndexOutOfBoundsException ("" + i); 69 } 70 this.value[i+offset] = b; 71 } 72 73 public byte get(int i) { 74 if (i >= length) { 75 throw new IndexOutOfBoundsException ("" + i + " >= " + length); 76 } 77 if (i < 0) { 78 throw new IndexOutOfBoundsException ("" + i); 79 } 80 return value[i+offset]; 81 } 82 83 public int getLength() { 84 return length; 85 } 86 87 94 public boolean equals(Object obj) { 95 if (obj instanceof ByteArrayWindow) { 96 ByteArrayWindow other = (ByteArrayWindow) obj; 97 if (other.length != length) { 98 return false; 99 } 100 for (int i=0; i<length; i++) { 101 if (other.value[i] != value[i]) { 102 return false; 103 } 104 } 105 return true; 106 } 107 return false; 108 } 109 110 public boolean equals(ByteArrayWindow other, int maxBytesToCompare) { 111 if ((other.length < maxBytesToCompare) || 112 (length < maxBytesToCompare)) { 113 return false; 114 } 115 for (int i=0; i<maxBytesToCompare; i++) { 116 if (value[offset+i] != other.value[other.offset+i]) { 117 return false; 118 } 119 } 120 return true; 121 } 122 } 123 | Popular Tags |