List of usage examples for org.apache.commons.beanutils PropertyUtils getProperty
public static Object getProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
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
.
From source file:cn.com.axiom.utils.Collections3.java
/** * ????(Getter), ??Map./*w w w . j av 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 Reflections.convertReflectionExceptionToUnchecked(e); } return map; }
From source file:com.njmd.framework.utils.CollectionsUtil.java
/** * ????(Getter), ??Map.//from w w w . j a va 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(); try { for (Object obj : collection) { map.put(PropertyUtils.getProperty(obj, keyPropertyName), PropertyUtils.getProperty(obj, valuePropertyName)); } } catch (Exception e) { throw ReflectionUtil.convertReflectionExceptionToUnchecked(e); } return map; }
From source file:com.jythonui.server.RUtils.java
private static Optional<String> retrieveS(Object o, String propName) { String v = null;// w w w .j a v a 2s .c om try { v = (String) PropertyUtils.getProperty(o, propName); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { return null; } return Optional.fromNullable(v); }
From source file:de.iritgo.simplelife.bean.BeanTools.java
/** * Copy all attributes from the given bean to the given map * //from ww w . j a va 2s.co m * @param object The bean * @param map The map * @param overwrite If true existing attributes in the map will be * overwritten */ static public void copyBean2Map(Object object, Map<String, Object> map, boolean overwrite) { for (PropertyDescriptor pd : PropertyUtils.getPropertyDescriptors(object)) { String name = pd.getName(); if (!overwrite && map.containsKey(name)) { continue; } try { map.put(name, PropertyUtils.getProperty(object, name)); } catch (Exception ignore) { } } }
From source file:com.micmiu.modules.utils.Collections3.java
/** * ????(Getter), ??Map./* w w w . j av a 2 s .com*/ * * @param collection ???. * @param keyPropertyName ????MapKey??. * @param valuePropertyName ????MapValue??. */ public static Map<?, ?> extractToMap(final Collection<?> collection, final String keyPropertyName, final String valuePropertyName) { Map<Object, Object> map = new HashMap<Object, Object>(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:$.Collections3.java
/** * ????(Getter), ??Map.//from www.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.age.back.frame.auth.CollectionUtils.java
/** * ????(Getter), ??Map./*from w w w. j a v a 2 s .c o m*/ * * @param collection ???. * @param keyPropertyName ????MapKey??. * @param valuePropertyName ????MapValue??. */ public static Map extractToMap(Collection collection, String keyPropertyName, String valuePropertyName) { Map map = new HashMap(); try { for (Object obj : collection) { map.put(PropertyUtils.getProperty(obj, keyPropertyName), PropertyUtils.getProperty(obj, valuePropertyName)); } } catch (Exception e) { e.printStackTrace(); } return map; }
From source file:com.maomao.framework.utils.ReflectUtils.java
/** * get// ww w . ja v a2 s.com * @param bean * @param name * @return * @throws Exception */ public static Object doGetMethod(Object bean, String name) throws Exception { return PropertyUtils.getProperty(bean, name); }
From source file:com.iotekclass.common.util.Collections3.java
/** * ????(Getter), ??Map.// w w w. j ava 2 s.c om * * @param collection ???. * @param linked ??. * @param keyPropertyName ????MapKey??. * @param valuePropertyName ????MapValue??. */ public static Map extractToMap(final Collection collection, boolean linked, final String keyPropertyName, final String valuePropertyName) { Map map = null; if (linked) { map = new LinkedHashMap(collection.size()); } else { 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.yunmel.syncretic.utils.commons.CollectionsUtils.java
/** * ????(Getter), ??Map.// w w w . ja va2 s .c o 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 = Maps.newHashMapWithExpectedSize(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; }