All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bremersee.utils.CastUtils Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
/*
 * Copyright 2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.bremersee.utils;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 

* This utility class has methods to cast collections. *

* * @author Christian Bremer */ @SuppressWarnings("unchecked") public abstract class CastUtils { private CastUtils() { // utility class, never constructed } /** * Casts a collection. */ public static Collection cast(Collection col) { return (Collection) col; } /** * Casts a collection. */ public static Collection cast(Collection col, Class t) { return (Collection) col; } /** * Casts a list. */ public static List cast(List list) { return (List) list; } /** * Casts a list. */ public static List cast(List list, Class t) { return (List) list; } /** * Casts an iterator. */ public static Iterator cast(Iterator iter) { return (Iterator) iter; } /** * Casts an iterator. */ public static Iterator cast(Iterator iter, Class t) { return (Iterator) iter; } /** * Casts a set. */ public static Set cast(Set set) { return (Set) set; } /** * Casts a set. */ public static Set cast(Set set, Class t) { return (Set) set; } /** * Casts a map. */ public static Map cast(Map map) { return (Map) map; } /** * Casts a map. */ public static Map cast(Map map, Class t, Class u) { return (Map) map; } /** * Casts a map entry. */ public static Map.Entry cast(Map.Entry mapEntry) { return (Map.Entry) mapEntry; } /** * Casts a map entry. */ public static Map.Entry cast(Map.Entry mapEntry, Class t, Class u) { return (Map.Entry) mapEntry; } }