Operation class attributes and values

/ ** 
     * assigns them 
     * @param SUM
      * / 
    public  void SetFieldValue (CsFsessum SUM) { 
        String [] the fieldNames = getFiledName (SUM);
         for ( int J = 0; J <fieldNames.length; J ++) {      // iterate All properties 
            String name = the fieldNames [J];     // get property name 
            IF (name.startsWith ( "timeSt" )) { 
                setFieldValueByName (SUM, name, 0L ); 
            } 
        } 
        
    } 
    
    / **   
     * get property name array   
     * * /   
    Private static String [] getFiledName (Object O) {   
        Field, [] Fields = o.getClass () getDeclaredFields ();.   
        String [] the fieldNames = new new String [fields.length];  
         for ( int I = 0; I <fields.length ; I ++ ) {   
            the fieldNames [I] = Fields [I] .getName (); 
        }   
        return the fieldNames;   
    } 
    
    // assigned to the attribute by attribute name 
    Private  void setFieldValueByName (Object obj, String the fieldName, Object value) {
          the try {   
               // Get class file byte object obj 
              class c =obj.getClass ();
               // get the class member variables 
              Field, f = c.getDeclaredField (fieldName);
               // cancel language access checks 
              f.setAccessible ( to true );
               // assign values to variables 
              f.set (obj, value) ; 
          } the catch (Exception E) {     
              logger.info ( "error in assignment to the object field name} {" , e.getMessage ());     
          }    
         
    } 
    
    
    / * Get the name of the attribute property values according to   
     * * / 
    Private  static Object getFieldValueByName (String the fieldName , Object O) {  
         the try {    
            String firstLetter = fieldName.substring(0, 1).toUpperCase();    
            String getter = "get" + firstLetter + fieldName.substring(1);    
            Method method = o.getClass().getMethod(getter, new Class[] {});    
            Object value = method.invoke(o, new Object[] {});    
            return value;    
        } catch (Exception e) {    
            return null;    
        }    
    }

 

Guess you like

Origin www.cnblogs.com/tang-guo/p/11106740.html