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

org.hibernate.engine.config.spi.StandardConverters Maven / Gradle / Ivy

The newest version!
/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
 * See the lgpl.txt file in the root directory or .
 */
package org.hibernate.engine.config.spi;


import static org.hibernate.engine.config.spi.ConfigurationService.Converter;

/**
 * Standard set of setting converters
 *
 * @author Steve Ebersole
 */
public class StandardConverters {
	public static final Converter BOOLEAN = new Converter() {
		@Override
		public Boolean convert(Object value) {
			if ( value == null ) {
				throw new IllegalArgumentException( "Null value passed to convert" );
			}

			return Boolean.class.isInstance( value )
					? Boolean.class.cast( value )
					: Boolean.parseBoolean( value.toString() );
		}
	};

	public static final Converter STRING = new Converter() {
		@Override
		public String convert(Object value) {
			if ( value == null ) {
				throw new IllegalArgumentException( "Null value passed to convert" );
			}

			return value.toString();
		}
	};

	/**
	 * Disallow direct instantiation
	 */
	private StandardConverters() {
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy