Mercurial > jhg
comparison src/org/tmatesoft/hg/util/CancelSupport.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 | f9f3e9b67ccc |
| children | 9c9c442b5f2e |
comparison
equal
deleted
inserted
replaced
| 355:f2c11fe7f3e9 | 356:91d75e1bac9f |
|---|---|
| 52 } | 52 } |
| 53 }; | 53 }; |
| 54 } | 54 } |
| 55 | 55 |
| 56 public static CancelSupport get(Object target, CancelSupport defaultValue) { | 56 public static CancelSupport get(Object target, CancelSupport defaultValue) { |
| 57 if (target instanceof CancelSupport) { | 57 return Adaptable.Factory.getAdapter(target, CancelSupport.class, defaultValue); |
| 58 return (CancelSupport) target; | |
| 59 } | |
| 60 if (target instanceof Adaptable) { | |
| 61 CancelSupport cs = ((Adaptable) target).getAdapter(CancelSupport.class); | |
| 62 if (cs != null) { | |
| 63 return cs; | |
| 64 } | |
| 65 } | |
| 66 return defaultValue; | |
| 67 } | 58 } |
| 68 } | 59 } |
| 69 | 60 |
| 70 interface Target<T> { | 61 interface Target<T> { |
| 71 T set(CancelSupport cs); | 62 T set(CancelSupport cs); |
