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 */
017package org.apache.wicket.util.lang;
018
019import java.util.ArrayList;
020import java.util.HashMap;
021import java.util.Iterator;
022import java.util.concurrent.ConcurrentHashMap;
023
024/**
025 * Generics related utilities
026 * 
027 * @author igor.vaynberg
028 */
029public class Generics
030{
031        private Generics()
032        {
033
034        }
035
036        /**
037         * Silences generics warning when need to cast iterator types
038         * 
039         * @param <T>
040         * @param delegate
041         * @return <code>delegate</code> iterator cast to proper generics type
042         */
043        @SuppressWarnings("unchecked")
044        public static <T> Iterator<T> iterator(final Iterator<?> delegate)
045        {
046                return (Iterator<T>)delegate;
047        }
048
049        /**
050         * Creates a new HashMap
051         * 
052         * @param <K>
053         * @param <V>
054         * @return new hash map
055         */
056        public static <K, V> HashMap<K, V> newHashMap()
057        {
058                return new HashMap<>();
059        }
060
061        /**
062         * Creates a new HashMap
063         * 
064         * @param <K>
065         * @param <V>
066         * @param capacity
067         *            initial capacity
068         * @return new hash map
069         */
070        public static <K, V> HashMap<K, V> newHashMap(final int capacity)
071        {
072                return new HashMap<>(capacity);
073        }
074
075        /**
076         * Creates a new ArrayList
077         * 
078         * @param <T>
079         * @param capacity
080         *            initial capacity
081         * @return array list
082         */
083        public static <T> ArrayList<T> newArrayList(final int capacity)
084        {
085                return new ArrayList<>(capacity);
086        }
087
088        /**
089         * Creates a new ArrayList
090         * 
091         * @param <T>
092         * @return array list
093         */
094        public static <T> ArrayList<T> newArrayList()
095        {
096                return new ArrayList<>();
097        }
098
099        /**
100         * Creates a new ConcurrentHashMap
101         * 
102         * @param <K>
103         * @param <V>
104         * @return new hash map
105         */
106        public static <K, V> ConcurrentHashMap<K, V> newConcurrentHashMap()
107        {
108                return new ConcurrentHashMap<>();
109        }
110
111        /**
112         * Creates a new ConcurrentHashMap
113         * 
114         * @param <K>
115         * @param <V>
116         * @param initialCapacity
117         *            initial capacity
118         * @return new hash map
119         */
120        public static <K, V> ConcurrentHashMap<K, V> newConcurrentHashMap(final int initialCapacity)
121        {
122                return new ConcurrentHashMap<>(initialCapacity);
123        }
124
125
126}