Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2012-2016 the original author or authors.
*/
package com.fitbur.assertj.util.introspection;
import static java.lang.String.format;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableList;
import static com.fitbur.assertj.util.IterableUtil.isNullOrEmpty;
import static com.fitbur.assertj.util.introspection.Introspection.getProperty;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.List;
import com.fitbur.assertj.util.VisibleForTesting;
/**
* Utility methods for properties access.
*
* @author Joel Costigliola
* @author Alex Ruiz
* @author Nicolas François
* @author Florent Biville
*/
public class PropertySupport {
private static final String SEPARATOR = ".";
private static final PropertySupport INSTANCE = new PropertySupport();
/**
* Returns the singleton instance of this class.
*
* @return the singleton instance of this class.
*/
public static PropertySupport instance() {
return INSTANCE;
}
@VisibleForTesting
JavaBeanDescriptor javaBeanDescriptor = new JavaBeanDescriptor();
@VisibleForTesting
PropertySupport() {
}
/**
* Returns a {@link List} containing the values of the given property name, from the elements of the
* given {@link Iterable}. If the given {@code Iterable} is empty or {@code null}, this method will
* return an empty {@code List}. This method supports nested properties (e.g. "address.street.number").
*
* @param propertyName the name of the property. It may be a nested property. It is left to the clients to validate
* for {@code null} or empty.
* @param target the given {@code Iterable}.
* @return an {@code Iterable} containing the values of the given property name, from the elements of the given
* {@code Iterable}.
* @throws IntrospectionError if an element in the given {@code Iterable} does not have a property with a matching
* name.
*/
public List propertyValues(String propertyName, Class clazz, Iterable> target) {
if (isNullOrEmpty(target)) {
return emptyList();
}
if (isNestedProperty(propertyName)) {
String firstPropertyName = popPropertyNameFrom(propertyName);
Iterable