本文整理汇总了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;
}