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

org.unix4j.convert.ArrayConverters Maven / Gradle / Ivy

There is a newer version: 0.6
Show newest version
package org.unix4j.convert;

import java.util.Collection;

public class ArrayConverters {
	public static final ValueConverter COLLECTION_TO_ARRAY = new ValueConverter() {
		@Override
		public Object[] convert(Object value) throws IllegalArgumentException {
			if (value instanceof Collection) {
				return ((Collection)value).toArray();
			}
			return null;
		}
	};
	public static final ValueConverter OBJECT_TO_SINGLETON_ARRAY = new ValueConverter() {
		@Override
		public Object[] convert(Object value) throws IllegalArgumentException {
			if (value != null) {
				return new Object[] {value};
			}
			return null;
		}
	};
	
	public static final ValueConverter COLLECTION_OR_ARRAY_TO_FLAT_ARRAY = new ConcatenatedConverter(ListConverters.COLLECTION_OR_ARRAY_TO_FLAT_LIST, COLLECTION_TO_ARRAY);
	public static final ValueConverter DEFAULT = new CompositeValueConverter().add(COLLECTION_TO_ARRAY).add(OBJECT_TO_SINGLETON_ARRAY);
	public static final ValueConverter FLATTEN = new CompositeValueConverter().add(COLLECTION_OR_ARRAY_TO_FLAT_ARRAY).add(OBJECT_TO_SINGLETON_ARRAY);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy