本文整理匯總了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);
}