Mercurial > jhg
comparison src/org/tmatesoft/hg/util/CancelSupport.java @ 312:f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 27 Sep 2011 05:29:12 +0200 |
parents | 41a778e3fd31 |
children | 91d75e1bac9f |
comparison
equal
deleted
inserted
replaced
311:b9592e21176a | 312:f9f3e9b67ccc |
---|---|
41 * | 41 * |
42 * @param target any object (or <code>null</code>) that might have cancel support. For <code>null</code>, returns an instance than never cancels. | 42 * @param target any object (or <code>null</code>) that might have cancel support. For <code>null</code>, returns an instance than never cancels. |
43 * @return target if it's capable checking cancellation status or no-op implementation that never cancels. | 43 * @return target if it's capable checking cancellation status or no-op implementation that never cancels. |
44 */ | 44 */ |
45 public static CancelSupport get(Object target) { | 45 public static CancelSupport get(Object target) { |
46 CancelSupport cs = get(target, null); | |
47 if (cs != null) { | |
48 return cs; | |
49 } | |
50 return new CancelSupport() { | |
51 public void checkCancelled() { | |
52 } | |
53 }; | |
54 } | |
55 | |
56 public static CancelSupport get(Object target, CancelSupport defaultValue) { | |
46 if (target instanceof CancelSupport) { | 57 if (target instanceof CancelSupport) { |
47 return (CancelSupport) target; | 58 return (CancelSupport) target; |
48 } | 59 } |
49 if (target instanceof Adaptable) { | 60 if (target instanceof Adaptable) { |
50 CancelSupport cs = ((Adaptable) target).getAdapter(CancelSupport.class); | 61 CancelSupport cs = ((Adaptable) target).getAdapter(CancelSupport.class); |
51 if (cs != null) { | 62 if (cs != null) { |
52 return cs; | 63 return cs; |
53 } | 64 } |
54 } | 65 } |
55 return new CancelSupport() { | 66 return defaultValue; |
56 public void checkCancelled() { | |
57 } | |
58 }; | |
59 } | 67 } |
60 } | 68 } |
61 | 69 |
62 interface Target<T> { | 70 interface Target<T> { |
63 T set(CancelSupport cs); | 71 T set(CancelSupport cs); |