Android Open Source - VideoExtand Bean Ref Util






From Project

Back to project page VideoExtand.

License

The source code is released under:

Apache License

If you think the Android project VideoExtand listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * ??????BeanRefUtils.java//w  w w  .j ava2  s  .  c o m
 * ?????<????>
 * ?????<????>
 * ????xiaoying
 * ?????2013-8-30
 * ????xiaoying
 * ?????2013-8-30
 * ???v1.0
 */
package com.yuninfo.videoextand.utils;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * ???
 * 
 * @author xiaoying
 * 
 */
public class BeanRefUtil {

  /**
   * Get all fields' value and put them to a map.
   * 
   * @param bean
   * @return Map
   */
  public static Map<String, Object> getFieldValueMap(Object bean) {
    Class<?> cls = bean.getClass();
    Map<String, Object> valueMap = new HashMap<String, Object>();
    // Get all fields.
    Field[] fields = cls.getDeclaredFields();

    for (Field field : fields) {  
      try {
        field.setAccessible(true);
        Object value = field.get(bean);
//        if(value == null) {
//          valueMap.put(field.getName(), "");
//          continue;
//        }
        valueMap.put(field.getName(), value);
      } catch (IllegalArgumentException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      }
        }  
        return valueMap;
  }

  /**
   * Set the fields' value.
   * 
   * @param bean
   * @param valMap
   */
  public static void setFieldValues(Object bean, Map<String, Object> valMap) {
    Class<?> cls = bean.getClass();
    //Get all fields.
    Field[] fields = cls.getDeclaredFields();

    for (Field field : fields) {
      if(valMap.containsKey(field.getName())) {
        field.setAccessible(true);
        try {
          field.set(bean, valMap.get(field.getName()));
        } catch (IllegalArgumentException e) {
          e.printStackTrace();
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        }
      }
    }
  }

}




Java Source Code List

com.example.androidtest.MainActivity.java
com.yuninfo.videoextand.BaseActivity.java
com.yuninfo.videoextand.Config.java
com.yuninfo.videoextand.ReadCardActivity.java
com.yuninfo.videoextand.SendCardActivity.java
com.yuninfo.videoextand.bean.CommonReq.java
com.yuninfo.videoextand.bean.ReadVideoResp.java
com.yuninfo.videoextand.bean.SendVideoResp.java
com.yuninfo.videoextand.bean.UploadReq.java
com.yuninfo.videoextand.bean.UploadResp.java
com.yuninfo.videoextand.player.VideoPlayerActivity.java
com.yuninfo.videoextand.recorder.RecorderActivity.java
com.yuninfo.videoextand.uploader.ProgressListener.java
com.yuninfo.videoextand.uploader.ProgressMultipartEntity.java
com.yuninfo.videoextand.uploader.ProgressOutputStream.java
com.yuninfo.videoextand.uploader.UploadHandler.java
com.yuninfo.videoextand.uploader.UploadThread.java
com.yuninfo.videoextand.utils.BeanRefUtil.java
com.yuninfo.videoextand.utils.DateUtil.java
com.yuninfo.videoextand.utils.FileUtil.java
com.yuninfo.videoextand.utils.HttpUtil.java
com.yuninfo.videoextand.utils.LogUtil.java
com.yuninfo.videoextand.utils.StringUtil.java
com.yuninfo.videoextand.widget.CustomPopupWindow.java
com.yuninfo.videoextand.widget.TitleBar.java
com.yuninfo.videoextand.widget.dialog.MenuDialog.java