Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/Revlog.java @ 356:91d75e1bac9f
Consistent approach to deal with adaptable objects. Give adaptable precedence over instanceof to allow conditional response when classes do implement desired interface
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Tue, 06 Dec 2011 14:25:52 +0100 |
| parents | f2c11fe7f3e9 |
| children | 189dc6dc1c3e |
comparison
equal
deleted
inserted
replaced
| 355:f2c11fe7f3e9 | 356:91d75e1bac9f |
|---|---|
| 251 start = lastRev; | 251 start = lastRev; |
| 252 } | 252 } |
| 253 if (end == TIP) { | 253 if (end == TIP) { |
| 254 end = lastRev; | 254 end = lastRev; |
| 255 } | 255 } |
| 256 final RevisionInspector revisionInsp = getAdapter(inspector, RevisionInspector.class); | 256 final RevisionInspector revisionInsp = Adaptable.Factory.getAdapter(inspector, RevisionInspector.class, null); |
| 257 final ParentInspector parentInsp = getAdapter(inspector, ParentInspector.class); | 257 final ParentInspector parentInsp = Adaptable.Factory.getAdapter(inspector, ParentInspector.class, null); |
| 258 final Nodeid[] allRevisions = parentInsp == null ? null : new Nodeid[end - start + 1]; | 258 final Nodeid[] allRevisions = parentInsp == null ? null : new Nodeid[end - start + 1]; |
| 259 | 259 |
| 260 content.iterate(start, end, false, new RevlogStream.Inspector() { | 260 content.iterate(start, end, false, new RevlogStream.Inspector() { |
| 261 | 261 |
| 262 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) { | 262 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) { |
| 270 allRevisions[revisionNumber] = nid; | 270 allRevisions[revisionNumber] = nid; |
| 271 parentInsp.next(revisionNumber, nid, parent1Revision, parent2Revision, p1, p2); | 271 parentInsp.next(revisionNumber, nid, parent1Revision, parent2Revision, p1, p2); |
| 272 } | 272 } |
| 273 } | 273 } |
| 274 }); | 274 }); |
| 275 } | |
| 276 private static <T> T getAdapter(Object o, Class<T> adapterClass) { | |
| 277 if (adapterClass.isInstance(o)) { | |
| 278 return adapterClass.cast(o); | |
| 279 } | |
| 280 if (o instanceof Adaptable) { | |
| 281 return ((Adaptable) o).getAdapter(adapterClass); | |
| 282 } | |
| 283 return null; | |
| 284 } | 275 } |
| 285 | 276 |
| 286 /** | 277 /** |
| 287 * MARKER | 278 * MARKER |
| 288 */ | 279 */ |
| 622 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) { | 613 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) { |
| 623 try { | 614 try { |
| 624 prepare(revisionNumber, da); // XXX perhaps, prepare shall return DA (sliced, if needed) | 615 prepare(revisionNumber, da); // XXX perhaps, prepare shall return DA (sliced, if needed) |
| 625 final ProgressSupport progressSupport = ProgressSupport.Factory.get(sink); | 616 final ProgressSupport progressSupport = ProgressSupport.Factory.get(sink); |
| 626 ByteBuffer buf = ByteBuffer.allocate(actualLen > 8192 ? 8192 : actualLen); | 617 ByteBuffer buf = ByteBuffer.allocate(actualLen > 8192 ? 8192 : actualLen); |
| 627 Preview p = getAdapter(sink, Preview.class); | 618 Preview p = Adaptable.Factory.getAdapter(sink, Preview.class, null); |
| 628 if (p != null) { | 619 if (p != null) { |
| 629 progressSupport.start(2 * da.length()); | 620 progressSupport.start(2 * da.length()); |
| 630 while (!da.isEmpty()) { | 621 while (!da.isEmpty()) { |
| 631 checkCancelled(); | 622 checkCancelled(); |
| 632 da.readBytes(buf); | 623 da.readBytes(buf); |
