Java Code Examples for org.apache.commons.lang3.ArrayUtils.nullToEmpty()

The following are Jave code examples for showing how to use nullToEmpty() of the org.apache.commons.lang3.ArrayUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: util   File:   View Source Code Vote up 6 votes
 * 循环向上转型, 获取对象的DeclaredMethod, 并强制设置为可访问.
 * 如向上转型到Object仍无法找到, 返回null.
 * 匹配函数名+参数类型.
 * 因为class.getMethod() 不能获取父类的private函数, 因此采用循环向上的getDeclaredMethod();
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);

	// 处理原子类型与对象类型的兼容

	for (Class<?> searchType = clazz; searchType != Object.class; searchType = searchType.getSuperclass()) {
		try {
			Method method = searchType.getDeclaredMethod(methodName, theParameterTypes);
			return method;
		} catch (NoSuchMethodException e) {
			// Method不在当前类定义,继续向上转型
	return null;
Example 2
Project: plugin-id-ldap   File:   View Source Code Vote up 5 votes
 * 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 :, 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
			} else {
				// Group (or whatever) membership
		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;
Example 3
Project: util   File:   View Source Code Vote up 4 votes
 * 直接调用对象方法, 无视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);