Java Code Examples for org.springframework.util.CollectionUtils#lastElement()

The following examples show how to use org.springframework.util.CollectionUtils#lastElement() . 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: ErrorsMethodArgumentResolver.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
@Nullable
public Object resolveArgument(MethodParameter parameter,
		@Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
		@Nullable WebDataBinderFactory binderFactory) throws Exception {

	Assert.state(mavContainer != null,
			"Errors/BindingResult argument only supported on regular handler methods");

	ModelMap model = mavContainer.getModel();
	String lastKey = CollectionUtils.lastElement(model.keySet());
	if (lastKey != null && lastKey.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
		return model.get(lastKey);
	}

	throw new IllegalStateException(
			"An Errors/BindingResult argument is expected to be declared immediately after " +
			"the model attribute, the @RequestBody or the @RequestPart arguments " +
			"to which they apply: " + parameter.getMethod());
}
 
Example 2
Source File: ErrorsMethodArgumentResolver.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
@Nullable
public Object resolveArgument(MethodParameter parameter,
		@Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
		@Nullable WebDataBinderFactory binderFactory) throws Exception {

	Assert.state(mavContainer != null,
			"Errors/BindingResult argument only supported on regular handler methods");

	ModelMap model = mavContainer.getModel();
	String lastKey = CollectionUtils.lastElement(model.keySet());
	if (lastKey != null && lastKey.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
		return model.get(lastKey);
	}

	throw new IllegalStateException(
			"An Errors/BindingResult argument is expected to be declared immediately after " +
			"the model attribute, the @RequestBody or the @RequestPart arguments " +
			"to which they apply: " + parameter.getMethod());
}
 
Example 3
Source File: JOptCommandLinePropertySource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public String[] getPropertyNames() {
	List<String> names = new ArrayList<>();
	for (OptionSpec<?> spec : this.source.specs()) {
		String lastOption = CollectionUtils.lastElement(spec.options());
		if (lastOption != null) {
			// Only the longest name is used for enumerating
			names.add(lastOption);
		}
	}
	return StringUtils.toStringArray(names);
}
 
Example 4
Source File: JOptCommandLinePropertySource.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public String[] getPropertyNames() {
	List<String> names = new ArrayList<>();
	for (OptionSpec<?> spec : this.source.specs()) {
		String lastOption = CollectionUtils.lastElement(spec.options());
		if (lastOption != null) {
			// Only the longest name is used for enumerating
			names.add(lastOption);
		}
	}
	return StringUtils.toStringArray(names);
}
 
Example 5
Source File: ConfigurationClassParser.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
@Nullable
public AnnotationMetadata getImportingClassFor(String importedClass) {
	return CollectionUtils.lastElement(this.imports.get(importedClass));
}
 
Example 6
Source File: CodeFlow.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Return the descriptor for the item currently on top of the stack (in the current scope).
 */
@Nullable
public String lastDescriptor() {
	return CollectionUtils.lastElement(this.compilationScopes.peek());
}
 
Example 7
Source File: ConfigurationClassParser.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
@Nullable
public AnnotationMetadata getImportingClassFor(String importedClass) {
	return CollectionUtils.lastElement(this.imports.get(importedClass));
}
 
Example 8
Source File: CodeFlow.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Return the descriptor for the item currently on top of the stack (in the current scope).
 */
@Nullable
public String lastDescriptor() {
	return CollectionUtils.lastElement(this.compilationScopes.peek());
}