Return the Class object for the given type.

@param type the given type to cast into Class

@return the Class casted object
177970
public static Class<?> getClassFromType(final Type type) {
        Class<?> returnClass = null;
        if (type instanceof Class<?>) {
            returnClass = (Class<?>) type;
        } else if (type instanceof ParameterizedType) {
            returnClass = getClassFromType(((ParameterizedType) type).getRawType());
        }
        return returnClass;
    }
725478
public <K, T extends Persistable<K>>
    CastorDao<K, T> getDao(
                    final Class<T> type
                    )
    {
        CastorDao<K, T>  dao = _daoRegistry.getDao( type );
        dao.setDaoRegistry( _daoRegistry );

        return dao;
    }
221462
public static Class getPrimitiveType(Class type) {
        if (type == int.class || type == Integer.class) {
            return int.class;
        } else if (type == long.class || type == Long.class) {
            return long.class;
        } else if (type == short.class || type == Short.class) {
            return short.class;
        } else if (type == double.class || type == Double.class) {
            return double.class;
        } else if (type == float.class || type == Float.class) {
            return float.class;
        } else if (type == char.class || type == Character.class) {
            return char.class;
        } else if (type == byte.class || type == Byte.class) {
            return byte.class;
        } else if (type == boolean.class || type == Boolean.class) {
            return boolean.class;
        }
        throw new IllegalArgumentException("Type '" + type + "' can not be converted to primitive type.");
    }
903735
public <T> List<T> getItems(Class<T> type) {
        List<T> r = new ArrayList<>();
        for (TopLevelItem i : getItems())
            if (type.isInstance(i))
                 r.add(type.cast(i));
        return r;
    }
418207
public static <P extends ParaObject> P toObject(String type) {
		try {
			return (P) toClass(type).getConstructor().newInstance();
		} catch (Exception ex) {
			logger.error(null, ex);
			return null;
		}
	}
849920
public static <T extends Serializable> T deserializeAndCheckObject(final byte[] object, final Class<T> type) {
        val result = deserialize(object, type);
        if (!type.isAssignableFrom(result.getClass())) {
            throw new ClassCastException("Decoded object is of type " + result.getClass() + " when we were expecting " + type);
        }
        return (T) result;
    }
339031
public static Class<?> rawClassOf(Type type) {
        if (type instanceof Class<?>) {
            return (Class<?>) type;
        } else if (type instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType) type;
            Type rawType = parameterizedType.getRawType();
            return (Class<?>) rawType;
        } else if (type instanceof GenericArrayType) {
            Type componentType = ((GenericArrayType) type).getGenericComponentType();
            return Array.newInstance(rawClassOf(componentType), 0).getClass();
        } else if (type instanceof TypeVariable) {
            return Object.class;
        } else {
            throw new IllegalArgumentException("Unsupported type " + type.getTypeName());
        }
    }
570861
@SuppressWarnings("rawtypes")
	public static Class getTypeClass(String type) throws ClassNotFoundException{
		Class clazz = null;
		if(type.equals("int")){
			clazz = int.class;
		} else if(type.equals("boolean")){
			clazz = boolean.class;
		} else if(type.equals("float")){
			clazz = float.class;
		} else if(type.equals("double")){
			clazz = double.class;
		} else if(type.equals("short")){
			clazz = short.class;
		} else if(type.equals("char")){
			clazz = char.class;
		} else if(type.equals("long")){
			clazz = long.class;
		} else if(type.equals("byte")){
			clazz = byte.class;
		} else {
			clazz = Class.forName(type);
		}
		return clazz;
	}
51952
public static Converter converterFor( Class type )
    {
        if (!converters.containsKey( type ))
            throw new IllegalArgumentException( "Don't know type: " + type );

        return converters.get( type );
    }
1287328
@SuppressWarnings("unchecked")
	public static <T> T cast(Object obj, Class<T> type){
		if(obj == null){
			return null;
		}
		if(obj.getClass() == type){
			return (T) obj;
		}
		if(isNativeNumberType(obj.getClass()) && isNativeNumberType(type)){
			return castToNativeNumber((Number)obj, type);
		}
		return type.cast(obj);
	}
749246
public static Class<?> forType(Type type)
  {
    if(type instanceof Class) {
      return (Class<?>)type;
    }

    if(type instanceof ParameterizedType) {
      return forType(((ParameterizedType)type).getRawType());
    }

    if(!(type instanceof GenericArrayType)) {
      return null;
    }

    Type componentType = ((GenericArrayType)type).getGenericComponentType();
    Class<?> componentClass = forType(componentType);
    return componentClass != null ? Array.newInstance(componentClass, 0).getClass() : null;
  }
903376
public static Class<?> erase(Type type)
	{
		if (type instanceof Class<?>)
		{
			return (Class<?>) type;
		}
		else if (type instanceof ParameterizedType)
		{
			return (Class<?>) ((ParameterizedType) type).getRawType();
		}
		else if (type instanceof TypeVariable<?>)
		{
			TypeVariable<?> tv = (TypeVariable<?>) type;
			if (tv.getBounds().length == 0)
				return Object.class;
			else
				return erase(tv.getBounds()[0]);
		}
		else if (type instanceof GenericArrayType)
		{
			GenericArrayType aType = (GenericArrayType) type;
			return GenericArrayTypeImpl.createArrayType(erase(aType.getGenericComponentType()));
		}
		else
		{
			// TODO at least support CaptureType here
			throw new RuntimeException("not supported: " + type.getClass());
		}
	}
461264
function getTypeClass(type) {
  switch (type) {
    case String:
      return types.String;
    case Number:
      return types.Number;
    case Date:
      return types.Date;
    case Boolean:
      return types.Boolean;
    case Buffer:
      return types.Buffer;
  }

  if (typeof type === 'string') return types[type];

  for (const ii in types) {
    if (types[ii] === type) return types[ii];
  }
  return null;
}
899853
public static Class<?> getRawType(Type type) {
		if (type instanceof Class<?>) {
			// type is a normal class.
			return (Class<?>) type;

		} else if (type instanceof ParameterizedType) {
			ParameterizedType parameterizedType = (ParameterizedType) type;

			// I'm not exactly sure why getRawType() returns Type instead of Class.
			// Neal isn't either but suspects some pathological case related
			// to nested classes exists.
			Type rawType = parameterizedType.getRawType();
			if (!(rawType instanceof Class)) {
				String message = MessageFormat.format("Expected a Class, but <{0}> is of type {1}", type, type.getClass()
						.getName());
				throw new IllegalArgumentException(message);
			}
			return (Class<?>) rawType;

		} else if (type instanceof GenericArrayType) {
			Type componentType = ((GenericArrayType) type).getGenericComponentType();
			return Array.newInstance(getRawType(componentType), 0).getClass();

		} else if (type instanceof TypeVariable) {
			// we could use the variable's bounds, but that'll won't work if there are multiple.
			// having a raw type that's more general than necessary is okay  
			return Object.class;

		} else {
			throw new IllegalArgumentException("Expected a Class, ParameterizedType, or " + "GenericArrayType, but <"
					+ type + "> is of type " + type.getClass().getName());
		}
	}
1075624
public static Class<?> toPrimitive(Class<?> type) {
        if (type.isPrimitive()) {
            return type;
        } else if (type == Boolean.class) {
            return Boolean.TYPE;
        } else if (type == Character.class) {
            return Character.TYPE;
        } else if (type == Byte.class) {
            return Byte.TYPE;
        } else if (type == Short.class) {
            return Short.TYPE;
        } else if (type == Integer.class) {
            return Integer.TYPE;
        } else if (type == Long.class) {
            return Long.TYPE;
        } else if (type == Float.class) {
            return Float.TYPE;
        } else if (type == Double.class) {
            return Double.TYPE;
        } else {
            return null;
        }
    }
442779
protected Object getObject(String pType) 
    /*throws XxxException*/ {
    	// Get class
    	Class cl = getType(pType);

    	// Return the new instance (requires empty public constructor)
    	try {
    	    return cl.newInstance();
    	}
    	catch (Exception e) {
    	    // throw new XxxException(e);
    	    throw new RuntimeException(e.getMessage());
    	}
    	
    	// Can't happen
    	//return null;
    }
1059929
public static Class<?> getRawType(Type type) {
		if (type instanceof Class) {
			return (Class<?>) type;
		} else if (type instanceof ParameterizedType) {
			ParameterizedType actualType = (ParameterizedType) type;
			return getRawType(actualType.getRawType());
		} else if (type instanceof GenericArrayType) {
			GenericArrayType genericArrayType = (GenericArrayType) type;
			Object rawArrayType = Array.newInstance(getRawType(genericArrayType
					.getGenericComponentType()), 0);
			return rawArrayType.getClass();
		} else if (type instanceof WildcardType) {
			WildcardType castedType = (WildcardType) type;
			return getRawType(castedType.getUpperBounds()[0]);
		} else {
			throw new IllegalArgumentException(
					"Type \'"
							+ type
							+ "\' is not a Class, "
							+ "ParameterizedType, or GenericArrayType. Can't extract class.");
		}
	}