1 57 58 package org.apache.commons.jrcs.diff; 59 60 import java.util.ArrayList ; 61 import java.util.Arrays ; 62 import java.util.Iterator ; 63 import java.util.LinkedList ; 64 import java.util.List ; 65 import java.util.ListIterator ; 66 67 import org.apache.commons.jrcs.diff.print.RCSPrint; 68 import org.apache.commons.jrcs.util.ToString; 69 70 71 90 91 public class Revision 92 extends ToString 93 { 94 95 List deltas_ = new LinkedList (); 96 97 98 101 public Revision() 102 { 103 } 105 106 107 111 public synchronized void addDelta(Delta delta) 112 { 113 if (delta == null) 114 { 115 throw new IllegalArgumentException ("new delta is null"); 116 } 117 deltas_.add(delta); 118 } 119 120 121 125 public synchronized void insertDelta(Delta delta) 126 { 127 if (delta == null) 128 { 129 throw new IllegalArgumentException ("new delta is null"); 130 } 131 deltas_.add(0, delta); 132 } 133 134 135 140 public Delta getDelta(int i) 141 { 142 return (Delta) deltas_.get(i); 143 } 144 145 149 public int size() 150 { 151 return deltas_.size(); 152 } 153 154 161 public Object [] patch(Object [] src) throws PatchFailedException 162 { 163 List target = new ArrayList (Arrays.asList(src)); 164 applyTo(target); 165 return target.toArray(); 166 } 167 168 174 public synchronized void applyTo(List target) throws PatchFailedException 175 { 176 ListIterator i = deltas_.listIterator(deltas_.size()); 177 while (i.hasPrevious()) 178 { 179 Delta delta = (Delta) i.previous(); 180 delta.patch(target); 181 } 182 } 183 184 189 public synchronized void toString(StringBuffer s) 190 { 191 Iterator i = deltas_.iterator(); 192 while (i.hasNext()) 193 { 194 ((Delta) i.next()).toString(s); 195 } 196 } 197 198 204 public synchronized void toRCSString(StringBuffer s, String EOL) 205 { 206 RCSPrint printer = new RCSPrint(s); 207 printer.setEOL(EOL); 208 accept(printer); 209 } 210 211 216 public void toRCSString(StringBuffer s) 217 { 218 toRCSString(s, Diff.NL); 219 } 220 221 225 public String toRCSString(String EOL) 226 { 227 StringBuffer s = new StringBuffer (); 228 toRCSString(s, EOL); 229 return s.toString(); 230 } 231 232 236 public String toRCSString() 237 { 238 return toRCSString(Diff.NL); 239 } 240 241 245 public void accept(RevisionVisitor visitor) { 246 visitor.visit(this); 247 Iterator iter = deltas_.iterator(); 248 while (iter.hasNext()) { 249 ((Delta) iter.next()).accept(visitor); 250 } 251 } 252 253 } 254 | Popular Tags |