本文整理汇总了Java中org.apache.commons.lang3.ArrayUtils.nullToEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayUtils.nullToEmpty方法的具体用法?Java ArrayUtils.nullToEmpty怎么用?Java ArrayUtils.nullToEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.ArrayUtils
的用法示例。
在下文中一共展示了ArrayUtils.nullToEmpty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAccessibleMethod
import org.apache.commons.lang3.ArrayUtils; //导入方法依赖的package包/类
/**
* 循环向上转型, 获取对象的DeclaredMethod, 并强制设置为可访问.
*
* 如向上转型到Object仍无法找到, 返回null.
*
* 匹配函数名+参数类型.
*
* 因为class.getMethod() 不能获取父类的private函数, 因此采用循环向上的getDeclaredMethod();
*/
@SuppressWarnings("rawtypes")
public static Method getAccessibleMethod(final Class<?> clazz, final String methodName,
Class<?>... parameterTypes) {
Validate.notNull(clazz, "class can't be null");
Validate.notEmpty(methodName, "methodName can't be blank");
Class[] theParameterTypes = ArrayUtils.nullToEmpty(parameterTypes);
// 处理原子类型与对象类型的兼容
ClassUtil.wrapClassses(theParameterTypes);
for (Class<?> searchType = clazz; searchType != Object.class; searchType = searchType.getSuperclass()) {
try {
Method method = searchType.getDeclaredMethod(methodName, theParameterTypes);
ClassUtil.makeAccessible(method);
return method;
} catch (NoSuchMethodException e) {
// Method不在当前类定义,继续向上转型
}
}
return null;
}
示例2: findAllNoCache
import org.apache.commons.lang3.ArrayUtils; //导入方法依赖的package包/类
/**
* Fetch and return all normalized groups. Note the result use cache, so does not reflect the current state of LDAP.
* LDAP.
*
* @return the groups. Key is the normalized name, Value is the corresponding LDAP group containing real CN, DN and
* normalized UID members.
*/
public Map<String, GroupOrg> findAllNoCache() {
final Map<String, GroupOrg> groups = new HashMap<>();
final Map<String, Set<String>> subGroupsDn = new HashMap<>();
final Map<String, GroupOrg> dnToGroups = new HashMap<>();
// First pass, collect the groups and dirty relationships
for (final DirContextAdapter groupRaw : template.search(groupsBaseDn, new EqualsFilter("objectClass", GROUP_OF_UNIQUE_NAMES).encode(),
(Object ctx) -> (DirContextAdapter) ctx)) {
final Set<String> members = new HashSet<>();
final String dn = Normalizer.normalize(groupRaw.getDn().toString());
final String name = groupRaw.getStringAttribute("cn");
final HashSet<String> subGroups = new HashSet<>();
for (final String memberDN : ArrayUtils.nullToEmpty(groupRaw.getStringAttributes(UNIQUE_MEMBER))) {
if (memberDN.startsWith("uid")) {
// User membership
members.add(memberDN);
} else {
// Group (or whatever) membership
subGroups.add(memberDN);
}
}
final GroupOrg group = new GroupOrg(dn, name, members);
subGroupsDn.put(group.getId(), subGroups);
groups.put(group.getId(), group);
dnToGroups.put(dn, group);
}
// Second pass to validate the sub-groups and complete the opposite relation
updateSubGroups(groups, subGroupsDn, dnToGroups);
return groups;
}
示例3: invokeMethod
import org.apache.commons.lang3.ArrayUtils; //导入方法依赖的package包/类
/**
* 直接调用对象方法, 无视private/protected修饰符.
*
* 根据传入参数的实际类型进行匹配
*/
public static <T> T invokeMethod(Object obj, String methodName, Object... args) {
Object[] theArgs = ArrayUtils.nullToEmpty(args);
final Class<?>[] parameterTypes = ClassUtils.toClass(theArgs);
return (T) invokeMethod(obj, methodName, theArgs, parameterTypes);
}