List of usage examples for org.springframework.beans BeanWrapperImpl BeanWrapperImpl
public BeanWrapperImpl(Class<?> clazz)
From source file:tetrad.rrd.ReflectTest.java
/** * @param args/*from w w w .ja va 2 s .c om*/ * @throws IllegalAccessException * @throws IllegalArgumentException * @throws InvocationTargetException */ public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { // TODO Auto-generated method stub ServerStatus serverstatus = new ServerStatus(); serverstatus.setDeviceCode(12); serverstatus.setType("a"); BeanWrapper wrapper = new BeanWrapperImpl(serverstatus); PropertyDescriptor[] ps = wrapper.getPropertyDescriptors(); for (PropertyDescriptor p : ps) { String s = p.getName(); System.out.println(s + " : " + wrapper.getPropertyValue(s)); } // Field[] fields = serverstatus.getClass().getDeclaredFields(); // Method[] methods = serverstatus.getClass().getMethods(); // // int idex = 0; // for (Field field : fields) { // System.out.println("name : " + field.getName()); // System.out.println("name : " + field.getType()); // Method method = methods[idex]; // if (method.getReturnType() == String.class) { // System.out.println(method.invoke(method.getName(), "")); // } // Object objValue = field.get(Object.class); // if (objValue instanceof java.lang.String) { // System.out.println(objValue.toString()); // } else if (objValue instanceof java.lang.Integer) { // System.out.println(((java.lang.Integer) objValue).intValue()); // } else if (objValue instanceof java.lang.Double) { // System.out.println(((java.lang.Double) objValue).doubleValue()); // } else if (objValue instanceof java.lang.Float) { // System.out.println(((java.lang.Float) objValue).floatValue()); // } else { // System.out.println(objValue); // } // idex++; // } }
From source file:Main.java
public static boolean valueExists(String propertyName, Object value, Collection<?> collection) { for (Object o : collection) { BeanWrapper bw = new BeanWrapperImpl(o); Object propertyValue = bw.getPropertyValue(propertyName); if (propertyValue.equals(value)) { return true; }//from w ww . j a va2 s. c o m } return false; }
From source file:Main.java
public static int countTrue(String propertyName, Collection<?> collection) { int count = 0; for (Object o : collection) { BeanWrapper bw = new BeanWrapperImpl(o); Boolean propertyValue = (Boolean) bw.getPropertyValue(propertyName); if (Boolean.TRUE.equals(propertyValue)) { count++;// ww w . j a va2 s .c om } } return count; }
From source file:Main.java
public static int countFalse(String propertyName, Collection<?> collection) { int count = 0; for (Object o : collection) { BeanWrapper bw = new BeanWrapperImpl(o); Boolean propertyValue = (Boolean) bw.getPropertyValue(propertyName); if (Boolean.FALSE.equals(propertyValue)) { count++;/*ww w . j av a 2 s . co m*/ } } return count; }
From source file:Main.java
public static int countValue(String propertyName, Object value, Collection<?> collection) { int count = 0; for (Object o : collection) { BeanWrapper bw = new BeanWrapperImpl(o); Object propertyValue = bw.getPropertyValue(propertyName); if (propertyValue.equals(value)) { count++;/* w w w . j a v a 2s. com*/ } } return count; }
From source file:Main.java
public static <T> List<T> sortCollection(List<T> collection, String sortCol, boolean isAsc) { for (int i = 0; i < collection.size(); i++) { for (int j = i + 1; j < collection.size(); j++) { BeanWrapper bwi = new BeanWrapperImpl(collection.get(i)); BeanWrapper bwj = new BeanWrapperImpl(collection.get(j)); int leftI = (Integer) bwi.getPropertyValue(sortCol); int leftJ = (Integer) bwj.getPropertyValue(sortCol); if (isAsc) { if (leftI > leftJ) { T obj = collection.get(j); collection.set(j, collection.get(i)); collection.set(i, obj); }/* w w w . java 2 s. co m*/ } else { if (leftI < leftJ) { T obj = collection.get(j); collection.set(j, collection.get(i)); collection.set(i, obj); } } } } return collection; }
From source file:Main.java
public static Collection<?> filterByValue(String propertyName, Object value, Collection<?> collection) { List<Object> list = new ArrayList<Object>(collection.size()); for (Object o : collection) { BeanWrapper bw = new BeanWrapperImpl(o); Object propertyValue = bw.getPropertyValue(propertyName); if (propertyValue.equals(value)) { list.add(o);/* w w w. j a v a 2s . c o m*/ } } return list; }
From source file:Main.java
public static Collection<?> filterByNotValue(String propertyName, Object value, Collection<?> collection) { List<Object> list = new ArrayList<Object>(collection.size()); for (Object o : collection) { BeanWrapper bw = new BeanWrapperImpl(o); Object propertyValue = bw.getPropertyValue(propertyName); if (!propertyValue.equals(value)) { list.add(o);/*from w ww. j a v a 2 s . c o m*/ } } return list; }
From source file:Main.java
/** * Returns the first element within the given {@link Collection} which has the given field set to the given value. * * @param <E> elements of the {@link Collection} * @param col the {@link Collection}// w w w .ja va2s . c o m * @param fieldName the name of the property (e.g. "key" for getKey()) * @param value the value to compare (using equals) against the returned value of the object * @return the first object whose field equals the given value or null if none found */ public static <E> E getRealMatch(Collection<E> col, String fieldName, String value) { if (col != null) { for (E e : col) { BeanWrapper w = new BeanWrapperImpl(e); if (fieldName != null && value != null && value.equals(w.getPropertyValue(fieldName))) { return e; } } } return null; }
From source file:org.ng200.openolympus.util.Beans.java
public static <T> void copy(T from, T to) { final BeanWrapper src = new BeanWrapperImpl(from); final BeanWrapper trg = new BeanWrapperImpl(to); for (final String propertyName : Stream.of(src.getPropertyDescriptors()).map(pd -> pd.getName()) .collect(Collectors.toList())) { if (!trg.isWritableProperty(propertyName)) { continue; }//from ww w. j a va2 s . c om trg.setPropertyValue(propertyName, src.getPropertyValue(propertyName)); } }