Mercurial > jhg
comparison src/org/tmatesoft/hg/util/ProgressSupport.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 | 41a778e3fd31 |
| children | 48f993aa2f41 |
comparison
equal
deleted
inserted
replaced
| 355:f2c11fe7f3e9 | 356:91d75e1bac9f |
|---|---|
| 35 /** | 35 /** |
| 36 * @param target object that might be capable to report progress. Can be <code>null</code> | 36 * @param target object that might be capable to report progress. Can be <code>null</code> |
| 37 * @return support object extracted from target or an empty, no-op implementation | 37 * @return support object extracted from target or an empty, no-op implementation |
| 38 */ | 38 */ |
| 39 public static ProgressSupport get(Object target) { | 39 public static ProgressSupport get(Object target) { |
| 40 if (target instanceof ProgressSupport) { | 40 ProgressSupport ps = Adaptable.Factory.getAdapter(target, ProgressSupport.class, null); |
| 41 return (ProgressSupport) target; | 41 if (ps != null) { |
| 42 } | 42 return ps; |
| 43 if (target instanceof Adaptable) { | |
| 44 ProgressSupport ps = ((Adaptable) target).getAdapter(ProgressSupport.class); | |
| 45 if (ps != null) { | |
| 46 return ps; | |
| 47 } | |
| 48 } | 43 } |
| 49 return new ProgressSupport() { | 44 return new ProgressSupport() { |
| 50 public void start(int totalUnits) { | 45 public void start(int totalUnits) { |
| 51 } | 46 } |
| 52 public void worked(int units) { | 47 public void worked(int units) { |
