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

org.nakedobjects.metamodel.commons.lang.CastUtils Maven / Gradle / Ivy

The newest version!
package org.nakedobjects.metamodel.commons.lang;

import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.Vector;


/**
 * Helpers to co-erce existing (Java 1.1 code) into type-safe generics without having to suppress compiler
 * warnings all over the place.
 * 
 */
public final class CastUtils {

    private CastUtils() {}

    @SuppressWarnings("unchecked")
    public static  T cast(final Object obj) {
        return (T) obj;
    }

    @SuppressWarnings("unchecked")
    public static  Enumeration enumerationOver(final Object obj, final Class castTo) {
        return (Enumeration) obj;
    }

    @SuppressWarnings("unchecked")
    public static  Iterator iteratorOver(final Object obj, final Class castTo) {
        return (Iterator) obj;
    }

    @SuppressWarnings("unchecked")
    public static  Collection collectionOf(final Object obj, final Class castTo) {
        return (Collection) obj;
    }

    @SuppressWarnings("unchecked")
    public static  List listOf(final Object obj, final Class castTo) {
        return (List) obj;
    }

    @SuppressWarnings("unchecked")
    public static  Vector vectorOf(final Object obj, final Class castTo) {
        return (Vector) obj;
    }

    @SuppressWarnings("unchecked")
    public static  Set setOf(final Object obj, final Class castTo) {
        return (Set) obj;
    }

    @SuppressWarnings("unchecked")
    public static  SortedSet sortedSetOf(final Object obj, final Class castTo) {
        return (SortedSet) obj;
    }

    @SuppressWarnings("unchecked")
    public static  Map mapOf(final Object obj, final Class keyCastTo, final Class valueCastTo) {
        return (Map) obj;
    }

    @SuppressWarnings("unchecked")
    public static  SortedMap sortedMapOf(final Object obj, final Class keyCastTo, final Class valueCastTo) {
        return (SortedMap) obj;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy