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

panda.cast.castor.AnySingleCastor Maven / Gradle / Ivy

Go to download

Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.

There is a newer version: 1.8.0
Show newest version
package panda.cast.castor;

import java.lang.reflect.Type;
import java.util.Iterator;

import panda.lang.Iterators;

/**
 * @param  target type
 */
public abstract class AnySingleCastor extends AnyObjectCastor {
	public AnySingleCastor(Type toType) {
		super(toType);
	}

	/**
	 * @param value value
	 * @return one value of the array[1]
	 */
	protected Object prepare(Object value) {
		if (value instanceof byte[] || value instanceof char[]) {
			return value;
		}

		if (Iterators.isIterable(value)) {
			@SuppressWarnings("rawtypes")
			Iterator it = Iterators.asIterator(value);
			if (it.hasNext()) {
				Object v = it.next();
				if (!it.hasNext()) {
					return v;
				}
			}
		}
		return value;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy