001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.camel.util;
018    
019    import java.util.Collection;
020    import java.util.Enumeration;
021    import java.util.Hashtable;
022    import java.util.Iterator;
023    import java.util.List;
024    import java.util.Map;
025    import java.util.Queue;
026    import java.util.Set;
027    import java.util.concurrent.Future;
028    
029    import javax.naming.NamingEnumeration;
030    
031    @SuppressWarnings("unchecked")
032    public final class CastUtils {
033        
034        private CastUtils() {
035            //utility class, never constructed
036        }
037        
038        public static <T, U> Map<T, U> cast(Map<?, ?> p) {
039            return (Map<T, U>)p;
040        }
041        public static <T, U> Map<T, U> cast(Map<?, ?> p, Class<T> t, Class<U> u) {
042            return (Map<T, U>)p;
043        }
044        
045        public static <T> Collection<T> cast(Collection<?> p) {
046            return (Collection<T>)p;
047        }
048        public static <T> Collection<T> cast(Collection<?> p, Class<T> cls) {
049            return (Collection<T>)p;
050        }
051        public static <T> List<T> cast(List<?> p) {
052            return (List<T>)p;
053        }
054        
055        public static <T> List<T> cast(List<?> p, Class<T> cls) {
056            return (List<T>)p;
057        }
058    
059        public static <T> Iterator<T> cast(Iterator<?> p) {
060            return (Iterator<T>)p;
061        }
062        
063        public static <T> Iterator<T> cast(Iterator<?> p, Class<T> cls) {
064            return (Iterator<T>)p;
065        }
066        
067        public static <T> Set<T> cast(Set<?> p) {
068            return (Set<T>)p;
069        }
070        public static <T> Set<T> cast(Set<?> p, Class<T> cls) {
071            return (Set<T>)p;
072        }
073    
074        public static <T> Queue<T> cast(Queue<?> p) {
075            return (Queue<T>)p;
076        }
077        public static <T> Queue<T> cast(Queue<?> p, Class<T> cls) {
078            return (Queue<T>)p;
079        }
080    
081        public static <T, U> Hashtable<T, U> cast(Hashtable<?, ?> p) {
082            return (Hashtable<T, U>)p;
083        }
084        public static <T, U> Hashtable<T, U> cast(Hashtable<?, ?> p, Class<T> pc, Class<U> uc) {
085            return (Hashtable<T, U>)p;
086        }
087    
088        public static <T, U> Map.Entry<T, U> cast(Map.Entry<?, ?> p) {
089            return (Map.Entry<T, U>)p;
090        }
091        public static <T, U> Map.Entry<T, U> cast(Map.Entry<?, ?> p, Class<T> pc, Class<U> uc) {
092            return (Map.Entry<T, U>)p;
093        }
094    
095        public static <T> Enumeration<T> cast(Enumeration<?> p) {
096            return (Enumeration<T>)p;
097        }
098        public static <T> NamingEnumeration<T> cast(NamingEnumeration<?> p) {
099            return (NamingEnumeration<T>)p;
100        }
101    
102        public static <T> Class<T> cast(Class<?> p) {
103            return (Class<T>)p;
104        }
105        public static <T> Class<T> cast(Class<?> p, Class<T> cls) {
106            return (Class<T>)p;
107        }
108    
109        public static <T> Future<T> cast(Future<?> p) {
110            return (Future<T>)p;
111        }
112    }