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

org.oddjob.arooa.convert.convertlets.CharacterConvertlets Maven / Gradle / Ivy

There is a newer version: 1.6.0
Show newest version
/*
 * (c) Rob Gordon 2006
 */
package org.oddjob.arooa.convert.convertlets;

import org.oddjob.arooa.convert.ConversionProvider;
import org.oddjob.arooa.convert.ConversionRegistry;
import org.oddjob.arooa.convert.Convertlet;
import org.oddjob.arooa.convert.FinalConvertlet;

public class CharacterConvertlets implements ConversionProvider {

	public void registerWith(ConversionRegistry registry) {
		
		registry.register(String.class, Character.class, 
				new Convertlet() {
			public Character convert(String from) {
				String stringValue = from.trim();
				if (stringValue.length() == 0) {
					return null;
				}
				else {
					return new Character(from.charAt(0));
				}
			}
		});
				
		registry.register(Number.class, Character.class, 
				new Convertlet() {
			public Character convert(Number from) {
				return new Character((char) from.intValue());
			};
		});
		
		registry.register(Character.class, Number.class, 
				new Convertlet() {
			public Number convert(Character from) {
				return new Integer(from.charValue());
			}
		});
		
		registry.register(Character.class, String.class, 
				new FinalConvertlet() {
			public String convert(Character from) {
				return from.toString();
			}
		});
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy