Example usage for org.apache.commons.beanutils PropertyUtils getProperty

List of usage examples for org.apache.commons.beanutils PropertyUtils getProperty

Introduction

In this page you can find the example usage for org.apache.commons.beanutils PropertyUtils getProperty.

Prototype

public static Object getProperty(Object bean, String name)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException 

Source Link

Document

Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.

For more details see PropertyUtilsBean.

Usage

From source file:com.eryansky.common.utils.collections.Collections3.java

/**
 * ????(Getter), ??Map.//from  w  w  w. j  a v  a  2  s.c o m
 * 
 * @param collection ???.
 * @param keyPropertyName ????MapKey??.
 * @param valuePropertyName ????MapValue??.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Map extractToMap(final Collection collection, final String keyPropertyName,
        final String valuePropertyName) {
    Map map = new HashMap(collection.size());

    try {
        for (Object obj : collection) {
            map.put(PropertyUtils.getProperty(obj, keyPropertyName),
                    PropertyUtils.getProperty(obj, valuePropertyName));
        }
    } catch (Exception e) {
        throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }

    return map;
}

From source file:com.clican.pluto.common.util.SearchUtils.java

/**
 * ???????source???// w w w . j av  a2  s.c  om
 * 
 * @param <T>
 *            
 * @param <K>
 *            
 * @param source
 *            ?
 * @param comparablePropName
 *            ?
 * @param comp
 *            
 * @return
 */
@SuppressWarnings("unchecked")
public static <T, K> T binarySearch(List<T> source, String comparablePropName, Comparable<K> comp) {
    if (source == null || source.size() == 0) {
        return null;
    }
    int first = 0, upto = source.size();
    while (first < upto) {
        int midIdx = (first + upto) / 2;// Compute mid point.
        T mid = source.get(midIdx);
        try {
            K value = (K) PropertyUtils.getProperty(mid, comparablePropName);
            if (comp.compareTo(value) < 0) {
                upto = midIdx; // repeat search in bottom half.
            } else if (comp.compareTo(value) > 0) {
                first = midIdx + 1; // Repeat search in top half.
            } else {
                return source.get(midIdx);// Found it. return position
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return null; // Failed to find key
}

From source file:apm.common.utils.Collections3.java

/**
 * ????(Getter), ??Map.//from w w w  .j a  v a2s. co m
 * 
 * @param collection ???.
 * @param keyPropertyName ????MapKey??.
 * @param valuePropertyName ????MapValue??.
 */
@SuppressWarnings("unchecked")
public static Map extractToMap(final Collection collection, final String keyPropertyName,
        final String valuePropertyName) {
    Map map = new HashMap(collection.size());

    try {
        for (Object obj : collection) {
            map.put(PropertyUtils.getProperty(obj, keyPropertyName),
                    PropertyUtils.getProperty(obj, valuePropertyName));
        }
    } catch (Exception e) {
        throw Reflections.convertReflectionExceptionToUnchecked(e);
    }

    return map;
}

From source file:info.donsun.core.utils.Collections3.java

/**
 * ????(Getter), ??Map./*from  w ww  .  j a v a  2 s .  c o  m*/
 * 
 * @param collection ???.
 * @param keyPropertyName ????MapKey??.
 */

public static Map extractToMap(final Collection collection, final String keyPropertyName) {
    Map map = new HashMap(collection.size());
    try {
        for (Object obj : collection) {
            map.put(PropertyUtils.getProperty(obj, keyPropertyName), obj);
        }
    } catch (Exception e) {
        throw Reflections.convertReflectionExceptionToUnchecked(e);
    }

    return map;
}

From source file:com.hihframework.core.utils.CollectionUtils.java

/**
 * ????(Getter), ??Map./*from   w w w  . ja  v a2s  .co m*/
 * add by zhujw ???map
 * @param collection ???.
 * @param keyPropertyName ????MapKey??.
 * @param valuePropertyName ????MapValue??.
 */
public static Map<Object, Object> fetchPropertyToMap(final Collection<?> collection,
        final String keyPropertyName, final String valuePropertyName) throws Exception {
    Map<Object, Object> map = new HashMap<Object, Object>();
    for (Object obj : collection) {
        map.put(PropertyUtils.getProperty(obj, keyPropertyName),
                PropertyUtils.getProperty(obj, valuePropertyName));
    }
    return map;
}

From source file:com.doculibre.constellio.utils.EqualityUtils.java

public static <T extends Object> boolean contains(Collection<T> collection, T bean, String propertyName) {
    Object propertyValue;/*from  w  ww . j a  v a 2s  .  com*/
    try {
        propertyValue = PropertyUtils.getProperty(bean, propertyName);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    }
    EqualPredicate equalityPredicate = new EqualPredicate(propertyValue);
    BeanPredicate beanPredicate = new BeanPredicate(propertyName, equalityPredicate);
    return CollectionUtils.exists(collection, beanPredicate);
}

From source file:com.framework.infrastructure.utils.Collections3.java

/**
 * (Getter), Map.// w ww  .jav  a2 s .co m
 * 
 * @param collection .
 * @param keyPropertyName MapKey.
 * @param valuePropertyName MapValue.
 */
public static Map extractToMap(final Collection collection, final String keyPropertyName,
        final String valuePropertyName) {
    Map map = new HashMap(collection.size());

    try {
        for (Object obj : collection) {
            map.put(PropertyUtils.getProperty(obj, keyPropertyName),
                    PropertyUtils.getProperty(obj, valuePropertyName));
        }
    } catch (Exception e) {
        throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }

    return map;
}

From source file:cc.sion.core.utils.Collections3.java

/**
 * ????(Getter), ??Map./*from   w  ww .  j  a v a 2  s.  c om*/
 *
 * @param collection ???.
 * @param keyPropertyName ????MapKey??.
 * @param valuePropertyName ????MapValue??.
 */
public static Map extractToMap(final Collection collection, final String keyPropertyName,
        final String valuePropertyName) {
    Map map = new HashMap(collection.size());

    try {
        for (Object obj : collection) {
            map.put(PropertyUtils.getProperty(obj, keyPropertyName),
                    PropertyUtils.getProperty(obj, valuePropertyName));
        }
    } catch (Exception e) {
        throw Reflections.convertReflectionExceptionToUnchecked(e);
    }

    return map;
}

From source file:com.cnksi.core.tools.utils.Collections3.java

/**
 * ????(Getter), ??Map./*from   w w w.j  av  a2 s  .c om*/
 * 
 * @param collection ???.
 * @param keyPropertyName ????MapKey??.
 * @param valuePropertyName ????MapValue??.
 */
public static Map extractToMap(final Collection collection, final String keyPropertyName,
        final String valuePropertyName) {

    Map map = new HashMap(collection.size());

    try {
        for (Object obj : collection) {
            map.put(PropertyUtils.getProperty(obj, keyPropertyName),
                    PropertyUtils.getProperty(obj, valuePropertyName));
        }
    } catch (Exception e) {
        throw Reflections.convertReflectionExceptionToUnchecked(e);
    }

    return map;
}

From source file:com.xsw.utils.Collections3.java

/**
 * ????(Getter), ??Map./*from w  w  w .j av  a2s. co m*/
 * 
 * @param collection ???.
 * @param keyPropertyName ????MapKey??.
 * @param valuePropertyName ????MapValue??.
 */
@SuppressWarnings("all")
public static Map extractToMap(final Collection collection, final String keyPropertyName,
        final String valuePropertyName) {
    Map map = new HashMap(collection.size());

    try {
        for (Object obj : collection) {
            map.put(PropertyUtils.getProperty(obj, keyPropertyName),
                    PropertyUtils.getProperty(obj, valuePropertyName));
        }
    } catch (Exception e) {
        throw Reflections.convertReflectionExceptionToUnchecked(e);
    }

    return map;
}