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

org.oddjob.arooa.convert.NullConversions Maven / Gradle / Ivy

There is a newer version: 1.6.0
Show newest version
package org.oddjob.arooa.convert;

import java.util.HashMap;
import java.util.Map;

/**
 * Helper to provide null conversions.
 * 
 * @author rob
 *
 */
public class NullConversions {

	private static final Map, Object> NULL_CONVERSIONS =
			new HashMap, Object>(8);
	
	static {
		NULL_CONVERSIONS.put(boolean.class, false);
		NULL_CONVERSIONS.put(byte.class, (byte) 0);
		NULL_CONVERSIONS.put(char.class, '\0');
		NULL_CONVERSIONS.put(short.class, (short) 0);
		NULL_CONVERSIONS.put(int.class, 0);
		NULL_CONVERSIONS.put(long.class, 0L);
		NULL_CONVERSIONS.put(float.class, 0.0F);
		NULL_CONVERSIONS.put(double.class, 0.0);
	}
	
	@SuppressWarnings("unchecked")
	public static  T nullConversionFor(Class required) {
		return (T) NULL_CONVERSIONS.get(required);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy