diff 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
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/Revlog.java	Tue Dec 06 12:57:21 2011 +0100
+++ b/src/org/tmatesoft/hg/repo/Revlog.java	Tue Dec 06 14:25:52 2011 +0100
@@ -253,8 +253,8 @@
 		if (end == TIP) {
 			end = lastRev;
 		}
-		final RevisionInspector revisionInsp = getAdapter(inspector, RevisionInspector.class);
-		final ParentInspector parentInsp = getAdapter(inspector, ParentInspector.class);
+		final RevisionInspector revisionInsp = Adaptable.Factory.getAdapter(inspector, RevisionInspector.class, null);
+		final ParentInspector parentInsp = Adaptable.Factory.getAdapter(inspector, ParentInspector.class, null);
 		final Nodeid[] allRevisions = parentInsp == null ? null : new Nodeid[end - start + 1]; 
 
 		content.iterate(start, end, false, new RevlogStream.Inspector() {
@@ -273,15 +273,6 @@
 			}
 		});
 	}
-	private static <T> T getAdapter(Object o, Class<T> adapterClass) {
-		if (adapterClass.isInstance(o)) {
-			return adapterClass.cast(o);
-		}
-		if (o instanceof Adaptable) {
-			return ((Adaptable) o).getAdapter(adapterClass);
-		}
-		return null;
-	}
 
 	/**
 	 * MARKER 
@@ -624,7 +615,7 @@
 				prepare(revisionNumber, da); // XXX perhaps, prepare shall return DA (sliced, if needed)
 				final ProgressSupport progressSupport = ProgressSupport.Factory.get(sink);
 				ByteBuffer buf = ByteBuffer.allocate(actualLen > 8192 ? 8192 : actualLen);
-				Preview p = getAdapter(sink, Preview.class);
+				Preview p = Adaptable.Factory.getAdapter(sink, Preview.class, null);
 				if (p != null) {
 					progressSupport.start(2 * da.length());
 					while (!da.isEmpty()) {