panda.cast.castor.AnySingleCastor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of panda-core Show documentation
Show all versions of panda-core Show documentation
Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.
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;
}
}