本文整理匯總了Java中org.springframework.util.ObjectUtils.isArray方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectUtils.isArray方法的具體用法?Java ObjectUtils.isArray怎麽用?Java ObjectUtils.isArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.util.ObjectUtils
的用法示例。
在下文中一共展示了ObjectUtils.isArray方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: asAuthorities
import org.springframework.util.ObjectUtils; //導入方法依賴的package包/類
private String asAuthorities(Object object) {
List<Object> authorities = new ArrayList<>();
if (object instanceof Collection) {
Collection<?> collection = (Collection<?>) object;
object = collection.toArray(new Object[0]);
}
if (ObjectUtils.isArray(object)) {
Object[] array = (Object[]) object;
for (Object value : array) {
if (value instanceof String) {
authorities.add(value);
}
else if (value instanceof Map) {
authorities.add(asAuthority((Map<?, ?>) value));
}
else {
authorities.add(value);
}
}
return StringUtils.collectionToCommaDelimitedString(authorities);
}
return object.toString();
}
示例2: toCollection
import org.springframework.util.ObjectUtils; //導入方法依賴的package包/類
/**
* Returns the given argument as {@link Collection} which means it will return it as is if it's a
* {@link Collections}, turn an array into an {@link ArrayList} or simply wrap any other value into a single element
* {@link Collections}.
*
* @param value
* @return
*/
public static Collection<?> toCollection(Object value) {
if (value == null) {
return null;
}
if (value instanceof Collection) {
return (Collection<?>) value;
}
if (ObjectUtils.isArray(value)) {
return Arrays.asList(ObjectUtils.toObjectArray(value));
}
return Collections.singleton(value);
}
示例3: prepare
import org.springframework.util.ObjectUtils; //導入方法依賴的package包/類
@Override
public Object prepare(Object value) {
if (!ObjectUtils.isArray(value)) {
return value;
}
int length = Array.getLength(value);
Collection<Object> result = new ArrayList<Object>(length);
for (int i = 0; i < length; i++) {
result.add(Array.get(value, i));
}
return result;
}