Java Code Examples for org.springframework.util.ObjectUtils#toObjectArray()

The following examples show how to use org.springframework.util.ObjectUtils#toObjectArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrderComparator.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Determine the order value for the given object.
 * <p>The default implementation checks against the given {@link OrderSourceProvider}
 * using {@link #findOrder} and falls back to a regular {@link #getOrder(Object)} call.
 * @param obj the object to check
 * @return the order value, or {@code Ordered.LOWEST_PRECEDENCE} as fallback
 */
private int getOrder(@Nullable Object obj, @Nullable OrderSourceProvider sourceProvider) {
	Integer order = null;
	if (obj != null && sourceProvider != null) {
		Object orderSource = sourceProvider.getOrderSource(obj);
		if (orderSource != null) {
			if (orderSource.getClass().isArray()) {
				Object[] sources = ObjectUtils.toObjectArray(orderSource);
				for (Object source : sources) {
					order = findOrder(source);
					if (order != null) {
						break;
					}
				}
			}
			else {
				order = findOrder(orderSource);
			}
		}
	}
	return (order != null ? order : getOrder(obj));
}
 
Example 2
Source File: OrderComparator.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Determine the order value for the given object.
 * <p>The default implementation checks against the given {@link OrderSourceProvider}
 * using {@link #findOrder} and falls back to a regular {@link #getOrder(Object)} call.
 * @param obj the object to check
 * @return the order value, or {@code Ordered.LOWEST_PRECEDENCE} as fallback
 */
private int getOrder(@Nullable Object obj, @Nullable OrderSourceProvider sourceProvider) {
	Integer order = null;
	if (obj != null && sourceProvider != null) {
		Object orderSource = sourceProvider.getOrderSource(obj);
		if (orderSource != null) {
			if (orderSource.getClass().isArray()) {
				Object[] sources = ObjectUtils.toObjectArray(orderSource);
				for (Object source : sources) {
					order = findOrder(source);
					if (order != null) {
						break;
					}
				}
			}
			else {
				order = findOrder(orderSource);
			}
		}
	}
	return (order != null ? order : getOrder(obj));
}
 
Example 3
Source File: OrderComparator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determine the order value for the given object.
 * <p>The default implementation checks against the given {@link OrderSourceProvider}
 * using {@link #findOrder} and falls back to a regular {@link #getOrder(Object)} call.
 * @param obj the object to check
 * @return the order value, or {@code Ordered.LOWEST_PRECEDENCE} as fallback
 */
private int getOrder(Object obj, OrderSourceProvider sourceProvider) {
	Integer order = null;
	if (sourceProvider != null) {
		Object orderSource = sourceProvider.getOrderSource(obj);
		if (orderSource != null && orderSource.getClass().isArray()) {
			Object[] sources = ObjectUtils.toObjectArray(orderSource);
			for (Object source : sources) {
				order = findOrder(source);
				if (order != null) {
					break;
				}
			}
		}
		else {
			order = findOrder(orderSource);
		}
	}
	return (order != null ? order : getOrder(obj));
}
 
Example 4
Source File: OrderComparator.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Determine the order value for the given object.
 * <p>The default implementation checks against the given {@link OrderSourceProvider}
 * using {@link #findOrder} and falls back to a regular {@link #getOrder(Object)} call.
 * @param obj the object to check
 * @return the order value, or {@code Ordered.LOWEST_PRECEDENCE} as fallback
 */
private int getOrder(Object obj, OrderSourceProvider sourceProvider) {
	Integer order = null;
	if (sourceProvider != null) {
		Object orderSource = sourceProvider.getOrderSource(obj);
		if (orderSource != null && orderSource.getClass().isArray()) {
			Object[] sources = ObjectUtils.toObjectArray(orderSource);
			for (Object source : sources) {
				order = findOrder(source);
				if (order != null) {
					break;
				}
			}
		}
		else {
			order = findOrder(orderSource);
		}
	}
	return (order != null ? order : getOrder(obj));
}
 
Example 5
Source File: CacheAspectSupport.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private Object[] extractArgs(Method method, Object[] args) {
	if (!method.isVarArgs()) {
		return args;
	}
	Object[] varArgs = ObjectUtils.toObjectArray(args[args.length - 1]);
	Object[] combinedArgs = new Object[args.length - 1 + varArgs.length];
	System.arraycopy(args, 0, combinedArgs, 0, args.length - 1);
	System.arraycopy(varArgs, 0, combinedArgs, args.length - 1, varArgs.length);
	return combinedArgs;
}
 
Example 6
Source File: MessageTag.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Resolve the given arguments Object into an arguments array.
 * @param arguments the specified arguments Object
 * @return the resolved arguments as array
 * @throws JspException if argument conversion failed
 * @see #setArguments
 */
@Nullable
protected Object[] resolveArguments(@Nullable Object arguments) throws JspException {
	if (arguments instanceof String) {
		String[] stringArray =
				StringUtils.delimitedListToStringArray((String) arguments, this.argumentSeparator);
		if (stringArray.length == 1) {
			Object argument = stringArray[0];
			if (argument != null && argument.getClass().isArray()) {
				return ObjectUtils.toObjectArray(argument);
			}
			else {
				return new Object[] {argument};
			}
		}
		else {
			return stringArray;
		}
	}
	else if (arguments instanceof Object[]) {
		return (Object[]) arguments;
	}
	else if (arguments instanceof Collection) {
		return ((Collection<?>) arguments).toArray();
	}
	else if (arguments != null) {
		// Assume a single argument object.
		return new Object[] {arguments};
	}
	else {
		return null;
	}
}
 
Example 7
Source File: CacheAspectSupport.java    From java-technology-stack with MIT License 5 votes vote down vote up
private Object[] extractArgs(Method method, Object[] args) {
	if (!method.isVarArgs()) {
		return args;
	}
	Object[] varArgs = ObjectUtils.toObjectArray(args[args.length - 1]);
	Object[] combinedArgs = new Object[args.length - 1 + varArgs.length];
	System.arraycopy(args, 0, combinedArgs, 0, args.length - 1);
	System.arraycopy(varArgs, 0, combinedArgs, args.length - 1, varArgs.length);
	return combinedArgs;
}
 
Example 8
Source File: MessageTag.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Resolve the given arguments Object into an arguments array.
 * @param arguments the specified arguments Object
 * @return the resolved arguments as array
 * @throws JspException if argument conversion failed
 * @see #setArguments
 */
@Nullable
protected Object[] resolveArguments(@Nullable Object arguments) throws JspException {
	if (arguments instanceof String) {
		String[] stringArray =
				StringUtils.delimitedListToStringArray((String) arguments, this.argumentSeparator);
		if (stringArray.length == 1) {
			Object argument = stringArray[0];
			if (argument != null && argument.getClass().isArray()) {
				return ObjectUtils.toObjectArray(argument);
			}
			else {
				return new Object[] {argument};
			}
		}
		else {
			return stringArray;
		}
	}
	else if (arguments instanceof Object[]) {
		return (Object[]) arguments;
	}
	else if (arguments instanceof Collection) {
		return ((Collection<?>) arguments).toArray();
	}
	else if (arguments != null) {
		// Assume a single argument object.
		return new Object[] {arguments};
	}
	else {
		return null;
	}
}
 
Example 9
Source File: LimiterExecutionContext.java    From Limiter with Apache License 2.0 5 votes vote down vote up
private Object[] extractArgs(Method method, Object[] args) {
    if (!method.isVarArgs()) {
        return args;
    } else {
        Object[] varArgs = ObjectUtils.toObjectArray(args[args.length - 1]);
        Object[] combinedArgs = new Object[args.length - 1 + varArgs.length];
        System.arraycopy(args, 0, combinedArgs, 0, args.length - 1);
        System.arraycopy(varArgs, 0, combinedArgs, args.length - 1, varArgs.length);
        return combinedArgs;
    }
}
 
Example 10
Source File: MessageTag.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Resolve the given arguments Object into an arguments array.
 * @param arguments the specified arguments Object
 * @return the resolved arguments as array
 * @throws JspException if argument conversion failed
 * @see #setArguments
 */
protected Object[] resolveArguments(Object arguments) throws JspException {
	if (arguments instanceof String) {
		String[] stringArray =
				StringUtils.delimitedListToStringArray((String) arguments, this.argumentSeparator);
		if (stringArray.length == 1) {
			Object argument = stringArray[0];
			if (argument != null && argument.getClass().isArray()) {
				return ObjectUtils.toObjectArray(argument);
			}
			else {
				return new Object[] {argument};
			}
		}
		else {
			return stringArray;
		}
	}
	else if (arguments instanceof Object[]) {
		return (Object[]) arguments;
	}
	else if (arguments instanceof Collection) {
		return ((Collection<?>) arguments).toArray();
	}
	else if (arguments != null) {
		// Assume a single argument object.
		return new Object[] {arguments};
	}
	else {
		return null;
	}
}
 
Example 11
Source File: CacheAspectSupport.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private Object[] extractArgs(Method method, Object[] args) {
	if (!method.isVarArgs()) {
		return args;
	}
	Object[] varArgs = ObjectUtils.toObjectArray(args[args.length - 1]);
	Object[] combinedArgs = new Object[args.length - 1 + varArgs.length];
	System.arraycopy(args, 0, combinedArgs, 0, args.length - 1);
	System.arraycopy(varArgs, 0, combinedArgs, args.length - 1, varArgs.length);
	return combinedArgs;
}
 
Example 12
Source File: CacheAspectSupport.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private Object[] extractArgs(Method method, Object[] args) {
	if (!method.isVarArgs()) {
		return args;
	}
	Object[] varArgs = ObjectUtils.toObjectArray(args[args.length - 1]);
	Object[] combinedArgs = new Object[args.length - 1 + varArgs.length];
	System.arraycopy(args, 0, combinedArgs, 0, args.length - 1);
	System.arraycopy(varArgs, 0, combinedArgs, args.length - 1, varArgs.length);
	return combinedArgs;
}
 
Example 13
Source File: MessageTag.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Resolve the given arguments Object into an arguments array.
 * @param arguments the specified arguments Object
 * @return the resolved arguments as array
 * @throws JspException if argument conversion failed
 * @see #setArguments
 */
protected Object[] resolveArguments(Object arguments) throws JspException {
	if (arguments instanceof String) {
		String[] stringArray =
				StringUtils.delimitedListToStringArray((String) arguments, this.argumentSeparator);
		if (stringArray.length == 1) {
			Object argument = stringArray[0];
			if (argument != null && argument.getClass().isArray()) {
				return ObjectUtils.toObjectArray(argument);
			}
			else {
				return new Object[] {argument};
			}
		}
		else {
			return stringArray;
		}
	}
	else if (arguments instanceof Object[]) {
		return (Object[]) arguments;
	}
	else if (arguments instanceof Collection) {
		return ((Collection<?>) arguments).toArray();
	}
	else if (arguments != null) {
		// Assume a single argument object.
		return new Object[] {arguments};
	}
	else {
		return null;
	}
}
 
Example 14
Source File: MockHttpServletRequestBuilder.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Add all headers to the request. Values are always added.
 * @param httpHeaders the headers and values to add
 */
public MockHttpServletRequestBuilder headers(HttpHeaders httpHeaders) {
	MediaType mediaType = httpHeaders.getContentType();
	if (mediaType != null) {
		this.contentType = mediaType.toString();
	}
	for (String name : httpHeaders.keySet()) {
		Object[] values = ObjectUtils.toObjectArray(httpHeaders.get(name).toArray());
		addToMultiValueMap(this.headers, name, values);
	}
	return this;
}
 
Example 15
Source File: HibernateDao.java    From opencron with Apache License 2.0 4 votes vote down vote up
private static Object handle(Object value) {
    if (value != null && value.getClass().isArray()) {
        return ObjectUtils.toObjectArray(value);
    }
    return value;
}