1 19 20 package org.netbeans.editor; 21 22 import javax.swing.text.Position ; 23 24 25 33 34 final class MultiMark { 35 36 37 static final int BACKWARD_BIAS = 1; 38 39 40 static final int VALID = 2; 41 42 46 static final int REMOVED = 4; 47 48 53 static final int COMPATIBLE = 8; 54 55 58 static final int ZERO = 16; 59 60 61 int rawOffset; 62 63 64 int flags; 65 66 67 MarkVector markVector; 68 69 70 MultiMark(MarkVector markVector, int offset) { 71 this(markVector, offset, 72 (offset != 0) ? COMPATIBLE : (COMPATIBLE | ZERO | BACKWARD_BIAS)); 73 } 74 75 76 MultiMark(MarkVector markVector, int offset, Position.Bias bias) { 77 this(markVector, offset, 78 (bias == Position.Bias.Backward) ? BACKWARD_BIAS : 0); 79 } 80 81 83 private MultiMark(MarkVector markVector, int offset, int flags) { 84 this.markVector = markVector; 85 this.rawOffset = offset; this.flags = flags; 87 } 88 89 93 public Position.Bias getBias() { 94 return ((flags & BACKWARD_BIAS) != 0) 95 ? Position.Bias.Backward 96 : Position.Bias.Forward; 97 } 98 99 100 public int getOffset() { 101 synchronized (markVector) { 102 if ((flags & VALID) != 0) { 103 return ((flags & ZERO) == 0) 104 ? markVector.getOffset(rawOffset) 105 : 0; 106 } else { throw new IllegalStateException (); 108 } 109 } 110 } 111 112 117 public void dispose() { 118 synchronized (markVector) { 119 if ((flags & VALID) != 0) { 120 flags &= ~VALID; 121 markVector.notifyMarkDisposed(); 122 } else { throw new IllegalStateException (); 124 } 125 } 126 } 127 128 130 public boolean isValid() { 131 synchronized(markVector) { 132 return ((flags & VALID) != 0); 133 } 134 } 135 136 public String toString() { 137 StringBuffer sb = new StringBuffer (); 138 synchronized(markVector) { 139 if ((flags & VALID) != 0) { 140 sb.append("offset=" + getOffset()); } else { 142 sb.append("removed"); } 144 sb.append(", bias="); sb.append(getBias()); 146 147 return sb.toString(); 148 } 149 } 150 151 public String toStringDetail() { 152 StringBuffer sb = new StringBuffer (); 153 synchronized(markVector) { 154 sb.append(System.identityHashCode(this)); 155 sb.append(" ("); sb.append(rawOffset); 157 sb.append(" -> "); if ((flags & VALID) != 0) { 159 sb.append(getOffset()); 160 } else { 161 sb.append('X'); 162 sb.append(markVector.getOffset(rawOffset)); 163 sb.append('X'); 164 } 165 sb.append(", "); sb.append(((flags & BACKWARD_BIAS) != 0) ? 'B' : 'F'); 167 if ((flags & VALID) != 0) { 168 sb.append('V'); 169 } 170 if ((flags & REMOVED) != 0) { 171 sb.append('R'); 172 } 173 if ((flags & COMPATIBLE) != 0) { 174 sb.append('C'); 175 } 176 if ((flags & ZERO) != 0) { 177 sb.append('Z'); 178 } 179 sb.append(')'); 180 181 return sb.toString(); 182 } 183 } 184 185 186 } 187 | Popular Tags |