Esempio n. 1
0
 /**
  * 使用自定义的属性过滤函数
  *
  * @param srcBean 原Bean
  * @param destBean 目标bean
  * @param filter 自定义的过滤函数
  */
 public static void copyPropertiesPeaceful(
     Object srcBean, Object destBean, PropertyFilter filter) {
   add(srcBean);
   add(destBean);
   Map<String, BeanStruct> srcMap = simpleProperties(srcBean);
   Map<String, BeanStruct> dstMap = simpleProperties(destBean);
   if (valid.valid(srcMap, dstMap)) {
     Map<String, String> srcMapFilter = new HashMap<>();
     Map<String, String> dstMapFilter = new HashMap<>();
     for (Map.Entry<String, BeanStruct> entry : srcMap.entrySet()) {
       srcMapFilter.put(filter.Properties(entry.getKey()), entry.getKey());
     }
     for (Map.Entry<String, BeanStruct> entry : dstMap.entrySet()) {
       dstMapFilter.put(filter.Properties(entry.getKey()), entry.getKey());
     }
     Map<String, String> intersection = CollectionUtil.intersection(srcMapFilter, dstMapFilter);
     if (valid.valid(intersection)) {
       for (Map.Entry<String, String> entry : intersection.entrySet()) {
         String key = entry.getKey();
         String srcKey = srcMapFilter.get(key);
         String dstKey = dstMapFilter.get(key);
         try {
           Object value = readMethod(srcBean, getReadMethod(srcBean, srcKey));
           writeMethod(destBean, getWriteMethod(destBean, dstKey), value);
         } catch (InvocationTargetException e) {
           e.printStackTrace();
         } catch (IllegalAccessException e) {
           e.printStackTrace();
         }
       }
     }
   }
 }
Esempio n. 2
0
 /**
  * 使用自定义的filter进行属性设值
  *
  * @param bean 操作的Bean
  * @param pro 类型属性
  * @param value 设置属性的值
  * @param filter 自定义的函数
  * @throws InvocationTargetException
  * @throws IllegalAccessException
  */
 public static void setPropertyFilter(Object bean, String pro, Object value, PropertyFilter filter)
     throws InvocationTargetException, IllegalAccessException {
   add(bean);
   pro = filter.Properties(pro);
   Map<String, BeanStruct> map = simpleProperties(bean);
   if (valid.valid(map)) {
     Set<String> set = map.keySet();
     for (String s : set) {
       if (pro.equals(filter.Properties(s))) {
         writeMethod(bean, getWriteMethodIgnore(bean, pro), value);
       }
     }
   }
 }
Esempio n. 3
0
 /**
  * 使用自定义的过滤器
  *
  * @param bean 判断的目标bean
  * @param pro 判断的属性
  * @param filter 自定义的属性过滤函数
  * @return 是否存在
  */
 public static boolean hasPropertyFilter(Object bean, String pro, PropertyFilter filter) {
   add(bean);
   pro = filter.Properties(pro);
   Map<String, BeanStruct> map = simpleProperties(bean);
   if (valid.valid(map)) {
     Set<String> set = map.keySet();
     for (String s : set) {
       if (pro.equals(filter.Properties(s))) {
         return true;
       }
     }
   }
   return false;
 }
Esempio n. 4
0
 /**
  * 使用自定义的过滤器获取对象的属性获取对象的属性
  *
  * @param bean 操作的Bean
  * @param pro 类型属性
  * @param filter 自定义的过滤函数
  * @return 返回属性的值如果发生异常返回空
  * @throws InvocationTargetException
  * @throws IllegalAccessException
  */
 public static Object getPropertyFilter(Object bean, String pro, PropertyFilter filter)
     throws InvocationTargetException, IllegalAccessException {
   add(bean);
   Object result = null;
   pro = filter.Properties(pro);
   Map<String, BeanStruct> map = simpleProperties(bean);
   if (valid.valid(map)) {
     Set<String> set = map.keySet();
     for (String s : set) {
       if (pro.equals(filter.Properties(s))) {
         result = readMethod(bean, getReadMethod(bean, s));
       }
     }
   }
   return result;
 }
Esempio n. 5
0
 /**
  * 使用自定义的filter进行属性设值
  *
  * @param bean 操作的Bean
  * @param pro 类型属性
  * @param value 设置属性的值
  * @param filter 自定义的函数
  */
 public static void setPropertyFilterPeaceful(
     Object bean, String pro, Object value, PropertyFilter filter) {
   add(bean);
   pro = filter.Properties(pro);
   Map<String, BeanStruct> map = simpleProperties(bean);
   if (valid.valid(map)) {
     Set<String> set = map.keySet();
     try {
       for (String s : set) {
         if (pro.equals(filter.Properties(s))) {
           writeMethod(bean, getWriteMethodIgnore(bean, pro), value);
         }
       }
     } catch (InvocationTargetException | IllegalAccessException e) {
       e.printStackTrace();
     }
   }
 }
Esempio n. 6
0
 /**
  * 使用自定义的过滤器获取对象的属性
  *
  * @param bean 操作的Bean
  * @param pro 类型属性
  * @param filter 自定义的过滤函数
  * @return 返回属性的值如果发生异常返回空
  */
 public static Object getPropertyFilterPeaceful(Object bean, String pro, PropertyFilter filter) {
   add(bean);
   Object result = null;
   pro = filter.Properties(pro);
   Map<String, BeanStruct> map = simpleProperties(bean);
   if (valid.valid(map)) {
     Set<String> set = map.keySet();
     try {
       for (String s : set) {
         if (pro.equals(filter.Properties(s))) {
           result = readMethod(bean, getReadMethod(bean, s));
         }
       }
     } catch (InvocationTargetException | IllegalAccessException e) {
       e.printStackTrace();
     }
   }
   return result;
 }