View Javadoc
1   package org.codehaus.plexus.component;
2   
3   import org.apache.xbean.recipe.RecipeHelper;
4   
5   import java.util.Collection;
6   import java.util.Iterator;
7   import java.util.List;
8   import java.util.Map;
9   import java.util.Set;
10  
11  @SuppressWarnings({"unchecked", "UnusedDeclaration"})
12  public final class CastUtils {
13      private CastUtils() {
14          //utility class, never constructed
15      }
16  
17      public static <T, U> Map<T, U> cast(Map<?, ?> p) {
18          return (Map<T, U>) p;
19      }
20  
21      public static <T, U> Map<T, U> cast(Map<?, ?> p, Class<T> t, Class<U> u) {
22          return (Map<T, U>) p;
23      }
24  
25      public static <T> Collection<T> cast(Collection<?> p) {
26          return (Collection<T>) p;
27      }
28  
29      public static <T> Collection<T> cast(Collection<?> p, Class<T> cls) {
30          return (Collection<T>) p;
31      }
32  
33      public static <T> List<T> cast(List<?> p) {
34          return (List<T>) p;
35      }
36  
37      public static <T> List<T> cast(List<?> p, Class<T> cls) {
38          return (List<T>) p;
39      }
40  
41      public static <T> Iterator<T> cast(Iterator<?> p) {
42          return (Iterator<T>) p;
43      }
44  
45      public static <T> Iterator<T> cast(Iterator<?> p, Class<T> cls) {
46          return (Iterator<T>) p;
47      }
48  
49      public static <T> Set<T> cast(Set<?> p) {
50          return (Set<T>) p;
51      }
52  
53      public static <T> Set<T> cast(Set<?> p, Class<T> cls) {
54          return (Set<T>) p;
55      }
56  
57      public static <T, U> Map.Entry<T, U> cast(Map.Entry<?, ?> p) {
58          return (Map.Entry<T, U>) p;
59      }
60  
61      public static <T, U> Map.Entry<T, U> cast(Map.Entry<?, ?> p, Class<T> pc, Class<U> uc) {
62          return (Map.Entry<T, U>) p;
63      }
64  
65      // todo remove when recipe helper accecpts nulls
66      public static boolean isAssignableFrom(Class<?> expected, Class<?> actual) {
67          return actual != null && RecipeHelper.isAssignableFrom( expected, actual );
68      }
69  }