1 2 17 18 package org.apache.poi.hwpf.model; 19 20 import java.io.ByteArrayOutputStream ; 21 import java.util.Arrays ; 22 23 import org.apache.poi.hwpf.sprm.SprmBuffer; 24 25 31 public abstract class PropertyNode implements Comparable , Cloneable 32 { 33 protected Object _buf; 34 private int _cpStart; 35 private int _cpEnd; 36 37 38 43 protected PropertyNode(int fcStart, int fcEnd, Object buf) 44 { 45 _cpStart = fcStart; 46 _cpEnd = fcEnd; 47 _buf = buf; 48 49 } 50 51 54 public int getStart() 55 { 56 return _cpStart; 57 } 58 59 public void setStart(int start) 60 { 61 _cpStart = start; 62 } 63 64 67 public int getEnd() 68 { 69 return _cpEnd; 70 } 71 72 public void setEnd(int end) 73 { 74 _cpEnd = end; 75 } 76 77 82 public void adjustForDelete(int start, int length) 83 { 84 int end = start + length; 85 86 if (_cpEnd > start) 87 { 88 if (_cpStart < end) 89 { 90 _cpEnd = end >= _cpEnd ? start : _cpEnd - length; 91 _cpStart = Math.min(start, _cpStart); 92 } 93 else 94 { 95 _cpEnd -= length; 96 _cpStart -= length; 97 } 98 } 99 } 100 101 protected boolean limitsAreEqual(Object o) 102 { 103 return ((PropertyNode)o).getStart() == _cpStart && 104 ((PropertyNode)o).getEnd() == _cpEnd; 105 106 } 107 108 public boolean equals(Object o) 109 { 110 if (limitsAreEqual(o)) 111 { 112 Object testBuf = ((PropertyNode)o)._buf; 113 if (testBuf instanceof byte[] && _buf instanceof byte[]) 114 { 115 return Arrays.equals((byte[])testBuf, (byte[])_buf); 116 } 117 return _buf.equals(testBuf); 118 } 119 return false; 120 } 121 122 public Object clone() 123 throws CloneNotSupportedException 124 { 125 return super.clone(); 126 } 127 128 131 public int compareTo(Object o) 132 { 133 int cpEnd = ((PropertyNode)o).getEnd(); 134 if(_cpEnd == cpEnd) 135 { 136 return 0; 137 } 138 else if(_cpEnd < cpEnd) 139 { 140 return -1; 141 } 142 else 143 { 144 return 1; 145 } 146 } 147 148 149 150 151 152 } 153 | Popular Tags |