<commit_before>/*
 * $HeadURL: https://svn.iizuka.co.uk/common/binding/guava/tags/1.0.0-beta-1/src/main/java/uk/co/iizuka/common/binding/guava/GuavaConverters.java $
 * 
 * (c) 2011 IIZUKA Software Technologies Ltd.  All rights reserved.
 */
package uk.co.iizuka.common.binding.guava;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;

import org.hobsoft.entangle.Converter;

/**
 * Factory for adapting Guava to converters.
 * 
 * @author <NAME>
 * @version $Id: GuavaConverters.java 97383 2011-12-28 20:22:56Z <EMAIL> $
 */
public final class GuavaConverters
{
	// constructors -----------------------------------------------------------
	
	private GuavaConverters()
	{
		throw new AssertionError();
	}
	
	// public methods ---------------------------------------------------------
	
	public static <S> Converter<S, Boolean> forPredicate(Predicate<? super S> predicate)
	{
		return forFunction(Functions.forPredicate(predicate));
	}
	
	public static <T> Converter<Object, T> forSupplier(Supplier<? extends T> supplier)
	{
		return forFunction(Functions.forSupplier(supplier));
	}
	
	public static <S, T> Converter<S, T> forFunction(Function<? super S, ? extends T> function)
	{
		return forFunction(function, null);
	}
	
	public static <S, T> Converter<S, T> forFunction(final Function<? super S, ? extends T> toFunction,
		final Function<? super T, ? extends S> fromFunction)
	{
		checkNotNull(toFunction, "toFunction cannot be null");
		
		return new Converter<S, T>()
		{
			@Override
			public T convert(S source)
			{
				return toFunction.apply(source);
			}
			
			@Override
			public S unconvert(T target)
			{
				if (fromFunction == null)
				{
					throw new UnsupportedOperationException();
				}
				
				return fromFunction.apply(target);
			}
		};
	}
}<commit_msg>Converted source to Java5<commit_after>/*
 * $HeadURL: https://svn.iizuka.co.uk/common/binding/guava/tags/1.0.0-beta-1/src/main/java/uk/co/iizuka/common/binding/guava/GuavaConverters.java $
 * 
 * (c) 2011 IIZUKA Software Technologies Ltd.  All rights reserved.
 */
package uk.co.iizuka.common.binding.guava;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;

import org.hobsoft.entangle.Converter;

/**
 * Factory for adapting Guava to converters.
 * 
 * @author <NAME>
 * @version $Id: GuavaConverters.java 97383 2011-12-28 20:22:56Z <EMAIL> $
 */
public final class GuavaConverters
{
	// constructors -----------------------------------------------------------
	
	private GuavaConverters()
	{
		throw new AssertionError();
	}
	
	// public methods ---------------------------------------------------------
	
	public static <S> Converter<S, Boolean> forPredicate(Predicate<? super S> predicate)
	{
		return forFunction(Functions.forPredicate(predicate));
	}
	
	public static <T> Converter<Object, T> forSupplier(Supplier<? extends T> supplier)
	{
		return forFunction(Functions.forSupplier(supplier));
	}
	
	public static <S, T> Converter<S, T> forFunction(Function<? super S, ? extends T> function)
	{
		return forFunction(function, null);
	}
	
	public static <S, T> Converter<S, T> forFunction(final Function<? super S, ? extends T> toFunction,
		final Function<? super T, ? extends S> fromFunction)
	{
		checkNotNull(toFunction, "toFunction cannot be null");
		
		return new Converter<S, T>()
		{
			public T convert(S source)
			{
				return toFunction.apply(source);
			}
			
			public S unconvert(T target)
			{
				if (fromFunction == null)
				{
					throw new UnsupportedOperationException();
				}
				
				return fromFunction.apply(target);
			}
		};
	}
}
{'fraction_non_alphanumeric': 0.1781874039938556, 'fraction_numerical': 0.01408090117767537, 'mean_word_length': 2.994887525562372, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6721277', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1224, 'n_words': 283}