signature:
public class Times { /** * 取得指定日期过 day 天后的日期 ( 当 day 为负数表示指日期之前 ) ;
 * @ param date
 * 日期 为null时表示当天
 * @ param day
 * 相加 ( 相减 ) 的月数 */
public static Date nextDay ( Date date , int day ) { } }

implementation: Calendar cal = Calendar . getInstance ( ) ; if ( date != null ) { cal . setTime ( date ) ; } cal . add ( Calendar . DAY_OF_YEAR , day ) ; return cal . getTime ( ) ;


signature:
public class Times { /** * 取得当前时间距离1900/1/1的天数
 * @ return 天数 */
public static int getDayNum ( ) { } }

implementation: int daynum = 0 ; GregorianCalendar gd = new GregorianCalendar ( ) ; Date dt = gd . getTime ( ) ; GregorianCalendar gd1 = new GregorianCalendar ( 1900 , 1 , 1 ) ; Date dt1 = gd1 . getTime ( ) ; daynum = ( int ) ( ( dt . getTime ( ) - dt1 . getTime ( ) ) / ( 24 * 60 * 60 * 1000 ) ) ; return daynum ;


signature:
public class Times { /** * getDayNum的逆方法 ( 用于处理Excel取出的日期格式数据等 )
 * @ param day
 * 天数
 * @ return 反推出的时间 */
public static Date getDateByNum ( int day ) { } }

implementation: GregorianCalendar gd = new GregorianCalendar ( 1900 , 1 , 1 ) ; Date date = gd . getTime ( ) ; date = nextDay ( date , day ) ; return date ;


signature:
public class Times { /** * 取得距离今天 day 日的日期
 * @ param day
 * 天数
 * @ return 日期字符串 */
public static String nextDay ( int day ) { } }

implementation: Calendar cal = Calendar . getInstance ( ) ; cal . setTime ( now ( ) ) ; cal . add ( Calendar . DAY_OF_YEAR , day ) ; return format ( DF_DATE , cal . getTime ( ) ) ;


signature:
public class Times { /** * 获取本月最后一天
 * @ return 本月最后一天 */
public static String getLastDayOfMonth ( ) { } }

implementation: Calendar cal = Calendar . getInstance ( ) ; cal . set ( Calendar . DATE , 1 ) ; cal . add ( Calendar . MONTH , 1 ) ; cal . add ( Calendar . DATE , - 1 ) ; return format ( DF_DATE , cal . getTime ( ) ) ;


signature:
public class Times { /** * 获取本月第一天
 * @ return 本月第一天 */
public static String getFirstDayOfMonth ( ) { } }

implementation: Calendar cal = Calendar . getInstance ( ) ; cal . set ( Calendar . DATE , 1 ) ; return format ( DF_DATE , cal . getTime ( ) ) ;


signature:
public class Times { /** * 判断两个日期相差的时长
 * @ param s
 * 起始日期
 * @ param e
 * 结束日期
 * @ param unit
 * 相差的单位 T _ 1MS 毫秒 T _ 1S 秒 T _ 1M 分 T _ 1H 时 T _ 1D 天 T _ 1W 周
 * @ return 相差的数量 */
public static long between ( Date s , Date e , long unit ) { } }

implementation: Date start ; Date end ; if ( s . before ( e ) ) { start = s ; end = e ; } else { start = e ; end = s ; } long diff = end . getTime ( ) - start . getTime ( ) ; return diff / unit ;


signature:
public class Times { /** * 取得指定日期过 minute 分钟后的日期 ( 当 minute 为负数表示指定分钟之前 )
 * @ param date
 * 日期 为null时表示当天 */
public static Date nextMinute ( Date date , int minute ) { } }

implementation: Calendar cal = Calendar . getInstance ( ) ; if ( date != null ) { cal . setTime ( date ) ; } cal . add ( Calendar . MINUTE , minute ) ; return cal . getTime ( ) ;


signature:
public class Times { /** * 取得指定日期过 second 秒后的日期 ( 当 second 为负数表示指定秒之前 )
 * @ param date
 * 日期 为null时表示当天 */
public static Date nextSecond ( Date date , int second ) { } }

implementation: Calendar cal = Calendar . getInstance ( ) ; if ( date != null ) { cal . setTime ( date ) ; } cal . add ( Calendar . SECOND , second ) ; return cal . getTime ( ) ;


signature:
public class Times { /** * 取得指定日期过 hour 小时后的日期 ( 当 hour 为负数表示指定小时之前 )
 * @ param date
 * 日期 为null时表示当天 */
public static Date nextHour ( Date date , int hour ) { } }

implementation: Calendar cal = Calendar . getInstance ( ) ; if ( date != null ) { cal . setTime ( date ) ; } cal . add ( Calendar . HOUR , hour ) ; return cal . getTime ( ) ;


signature:
public class NutEntity { /** * 当所有字段增加完成 , 这个方法必须被调用 , 用来搜索复合主键
 * @ param names
 * 复合主键的 Java 字段名数组 */
public void checkCompositeFields ( String [ ] names ) { } }

implementation: if ( ! Lang . isEmptyArray ( names ) && names . length > 1 ) { for ( String name : names ) { if ( byJava . containsKey ( name ) && byJava . get ( name ) . isCompositePk ( ) ) theComposites . add ( byJava . get ( name ) ) ; else throw Lang . makeThrow ( "Fail to find comosite field '%s' in class '%s'!" , name , type . getName ( ) ) ; } this . pkType = PkType . COMPOSITE ; } else if ( null != this . theId ) { this . pkType = PkType . ID ; } else if ( null != this . theName ) { this . pkType = PkType . NAME ; }


signature:
public class NutEntity { /** * 增加映射字段
 * @ param field
 * 数据库实体字段 */
public void addMappingField ( MappingField field ) { } }

implementation:
if ( field . isId ( ) ) theId = field ; else if ( field . isName ( ) ) theName = field ; // wjw ( 2017-04-10 ) , add , 乐观锁
else if ( field . isVersion ( ) ) theVersion = field ; byJava . put ( field . getName ( ) , field ) ; byDB . put ( field . getColumnName ( ) , field ) ; fields . add ( field ) ; columnComments . put ( field . getName ( ) , field . getColumnComment ( ) ) ;


signature:
public class NutEntity { /** * 增加实体索引
 * @ param index
 * 实体索引 */
public void addIndex ( EntityIndex index ) { } }

implementation: indexes . add ( index ) ; indexMap . put ( index . getName ( this ) , index ) ;


signature:
public class MaplMerge { /** * 转换器中间对象合并器 < br / >
 * 合并 { @ link Mapl } 中定义的中间结构 . < br / >
 * 规则 : < br >
 * < ul >
 * < li > 普通对象 , 保存为List , 但是要去掉重复 .
 * < li > 合并 map , 如果 key 值相同 , 那么后一个值覆盖前面的值 . 递归合并
 * < li > list不做递归合并 , 只做简单的合并 , 清除重复的操作 .
 * < / ul > */
public Object mergeItems ( Object ... objs ) { } }

implementation:
if ( objs == null || objs . length == 0 ) { return null ; } if ( objs . length == 1 ) { return objs [ 0 ] ; } // @ TODO 这里要不要判断是否兼容呢 ?
if ( objs [ 0 ] instanceof Map ) { return mergeMap ( objs ) ; } if ( objs [ 0 ] instanceof List ) { return mergeList ( objs ) ; } return mergeObj ( objs ) ;


signature:
public class MaplMerge { /** * 对象合并
 * @ param objs
 * @ return */
@ SuppressWarnings ( { } }

implementation: "rawtypes" , "unchecked" } ) private static Object mergeObj ( Object [ ] objs ) { List list = new ArrayList ( ) ; for ( Object obj : objs ) { if ( list . contains ( obj ) ) { continue ; } list . add ( obj ) ; } return list ;


signature:
public class MaplMerge { /** * list合并
 * @ param objs
 * @ return */
@ SuppressWarnings ( { } }

implementation: "rawtypes" , "unchecked" } ) private static Object mergeList ( Object ... objs ) { List list = new ArrayList ( ) ; for ( Object li : objs ) { List src = ( List ) li ; for ( Object obj : src ) { if ( ! list . contains ( obj ) ) { list . add ( obj ) ; } } } return list ;


signature:
public class MaplMerge { /** * map合并
 * @ param objs
 * @ return */
@ SuppressWarnings ( { } }

implementation: "unchecked" , "rawtypes" } ) private static Object mergeMap ( Object ... objs ) { Map obj = new LinkedHashMap ( ) ; for ( int i = 0 ; i < objs . length ; i ++ ) { Map map = ( Map ) objs [ i ] ; for ( Object key : map . keySet ( ) ) { Object objval = obj . get ( key ) ; Object val = map . get ( key ) ; if ( objval != null && ( val instanceof List || val instanceof Map ) ) { val = merge ( objval , val ) ; } obj . put ( key , val ) ; } } return obj ;


signature:
public class Frame { /** * Sets this frame to the given value .
 * @ param cw
 * the ClassWriter to which this label belongs .
 * @ param nLocal
 * the number of local variables .
 * @ param local
 * the local variable types . Primitive types are represented by
 * { @ link Opcodes # TOP } , { @ link Opcodes # INTEGER } ,
 * { @ link Opcodes # FLOAT } , { @ link Opcodes # LONG } ,
 * { @ link Opcodes # DOUBLE } , { @ link Opcodes # NULL } or
 * { @ link Opcodes # UNINITIALIZED _ THIS } ( long and double are
 * represented by a single element ) . Reference types are
 * represented by String objects ( representing internal names ) ,
 * and uninitialized types by Label objects ( this label
 * designates the NEW instruction that created this uninitialized
 * value ) .
 * @ param nStack
 * the number of operand stack elements .
 * @ param stack
 * the operand stack types ( same format as the " local " array ) . */
final void set ( ClassWriter cw , final int nLocal , final Object [ ] local , final int nStack , final Object [ ] stack ) { } }

implementation: int i = convert ( cw , nLocal , local , inputLocals ) ; while ( i < local . length ) { inputLocals [ i ++ ] = TOP ; } int nStackTop = 0 ; for ( int j = 0 ; j < nStack ; ++ j ) { if ( stack [ j ] == Opcodes . LONG || stack [ j ] == Opcodes . DOUBLE ) { ++ nStackTop ; } } inputStack = new int [ nStack + nStackTop ] ; convert ( cw , nStack , stack , inputStack ) ; outputStackTop = 0 ; initializationCount = 0 ;


signature:
public class Frame { /** * Converts types from the MethodWriter . visitFrame ( ) format to the Frame
 * format .
 * @ param cw
 * the ClassWriter to which this label belongs .
 * @ param nInput
 * the number of types to convert .
 * @ param input
 * the types to convert . Primitive types are represented by
 * { @ link Opcodes # TOP } , { @ link Opcodes # INTEGER } ,
 * { @ link Opcodes # FLOAT } , { @ link Opcodes # LONG } ,
 * { @ link Opcodes # DOUBLE } , { @ link Opcodes # NULL } or
 * { @ link Opcodes # UNINITIALIZED _ THIS } ( long and double are
 * represented by a single element ) . Reference types are
 * represented by String objects ( representing internal names ) ,
 * and uninitialized types by Label objects ( this label
 * designates the NEW instruction that created this uninitialized
 * value ) .
 * @ param output
 * where to store the converted types .
 * @ return the number of output elements . */
private static int convert ( ClassWriter cw , int nInput , Object [ ] input , int [ ] output ) { } }

implementation: int i = 0 ; for ( int j = 0 ; j < nInput ; ++ j ) { if ( input [ j ] instanceof Integer ) { output [ i ++ ] = BASE | ( ( Integer ) input [ j ] ) . intValue ( ) ; if ( input [ j ] == Opcodes . LONG || input [ j ] == Opcodes . DOUBLE ) { output [ i ++ ] = TOP ; } } else if ( input [ j ] instanceof String ) { output [ i ++ ] = type ( cw , Type . getObjectType ( ( String ) input [ j ] ) . getDescriptor ( ) ) ; } else { output [ i ++ ] = UNINITIALIZED | cw . addUninitializedType ( "" , ( ( Label ) input [ j ] ) . position ) ; } } return i ;


signature:
public class Frame { /** * Sets this frame to the value of the given frame . WARNING : after this
 * method is called the two frames share the same data structures . It is
 * recommended to discard the given frame f to avoid unexpected side
 * effects .
 * @ param f
 * The new frame value . */
final void set ( final Frame f ) { } }

implementation: inputLocals = f . inputLocals ; inputStack = f . inputStack ; outputLocals = f . outputLocals ; outputStack = f . outputStack ; outputStackTop = f . outputStackTop ; initializationCount = f . initializationCount ; initializations = f . initializations ;


signature:
public class Frame { /** * Returns the output frame local variable type at the given index .
 * @ param local
 * the index of the local that must be returned .
 * @ return the output frame local variable type at the given index . */
private int get ( final int local ) { } }

implementation:
if ( outputLocals == null || local >= outputLocals . length ) { // this local has never been assigned in this basic block ,
// so it is still equal to its value in the input frame
return LOCAL | local ; } else { int type = outputLocals [ local ] ; if ( type == 0 ) { // this local has never been assigned in this basic block ,
// so it is still equal to its value in the input frame
type = outputLocals [ local ] = LOCAL | local ; } return type ; }


signature:
public class Frame { /** * Sets the output frame local variable type at the given index .
 * @ param local
 * the index of the local that must be set .
 * @ param type
 * the value of the local that must be set . */
private void set ( final int local , final int type ) { } }

implementation:
// creates and / or resizes the output local variables array if necessary
if ( outputLocals == null ) { outputLocals = new int [ 10 ] ; } int n = outputLocals . length ; if ( local >= n ) { int [ ] t = new int [ Math . max ( local + 1 , 2 * n ) ] ; System . arraycopy ( outputLocals , 0 , t , 0 , n ) ; outputLocals = t ; } // sets the local variable
outputLocals [ local ] = type ;


signature:
public class Frame { /** * Pushes a new type onto the output frame stack .
 * @ param cw
 * the ClassWriter to which this label belongs .
 * @ param desc
 * the descriptor of the type to be pushed . Can also be a method
 * descriptor ( in this case this method pushes its return type
 * onto the output frame stack ) . */
private void push ( final ClassWriter cw , final String desc ) { } }

implementation: int type = type ( cw , desc ) ; if ( type != 0 ) { push ( type ) ; if ( type == LONG || type == DOUBLE ) { push ( TOP ) ; } }


signature:
public class Frame { /** * Returns the int encoding of the given type .
 * @ param cw
 * the ClassWriter to which this label belongs .
 * @ param desc
 * a type descriptor .
 * @ return the int encoding of the given type . */
private static int type ( final ClassWriter cw , final String desc ) { } }

implementation:
String t ; int index = desc . charAt ( 0 ) == '(' ? desc . indexOf ( ')' ) + 1 : 0 ; switch ( desc . charAt ( index ) ) { case 'V' : return 0 ; case 'Z' : case 'C' : case 'B' : case 'S' : case 'I' : return INTEGER ; case 'F' : return FLOAT ; case 'J' : return LONG ; case 'D' : return DOUBLE ; case 'L' : // stores the internal name , not the descriptor !
t = desc . substring ( index + 1 , desc . length ( ) - 1 ) ; return OBJECT | cw . addType ( t ) ; // case ' [ ' :
default : // extracts the dimensions and the element type
int data ; int dims = index + 1 ; while ( desc . charAt ( dims ) == '[' ) { ++ dims ; } switch ( desc . charAt ( dims ) ) { case 'Z' : data = BOOLEAN ; break ; case 'C' : data = CHAR ; break ; case 'B' : data = BYTE ; break ; case 'S' : data = SHORT ; break ; case 'I' : data = INTEGER ; break ; case 'F' : data = FLOAT ; break ; case 'J' : data = LONG ; break ; case 'D' : data = DOUBLE ; break ; // case ' L ' :
default : // stores the internal name , not the descriptor
t = desc . substring ( dims + 1 , desc . length ( ) - 1 ) ; data = OBJECT | cw . addType ( t ) ; } return ( dims - index ) << 28 | data ; }


signature:
public class Frame { /** * Pops the given number of types from the output frame stack .
 * @ param elements
 * the number of types that must be popped . */
private void pop ( final int elements ) { } }

implementation:
if ( outputStackTop >= elements ) { outputStackTop -= elements ; } else { // if the number of elements to be popped is greater than the number
// of elements in the output stack , clear it , and pops the remaining
// elements from the input stack .
owner . inputStackTop -= elements - outputStackTop ; outputStackTop = 0 ; }


signature:
public class Frame { /** * Pops a type from the output frame stack .
 * @ param desc
 * the descriptor of the type to be popped . Can also be a method
 * descriptor ( in this case this method pops the types
 * corresponding to the method arguments ) . */
private void pop ( final String desc ) { } }

implementation: char c = desc . charAt ( 0 ) ; if ( c == '(' ) { pop ( ( Type . getArgumentsAndReturnSizes ( desc ) >> 2 ) - 1 ) ; } else if ( c == 'J' || c == 'D' ) { pop ( 2 ) ; } else { pop ( 1 ) ; }


signature:
public class Frame { /** * Adds a new type to the list of types on which a constructor is invoked in
 * the basic block .
 * @ param var
 * a type on a which a constructor is invoked . */
private void init ( final int var ) { } }

implementation:
// creates and / or resizes the initializations array if necessary
if ( initializations == null ) { initializations = new int [ 2 ] ; } int n = initializations . length ; if ( initializationCount >= n ) { int [ ] t = new int [ Math . max ( initializationCount + 1 , 2 * n ) ] ; System . arraycopy ( initializations , 0 , t , 0 , n ) ; initializations = t ; } // stores the type to be initialized
initializations [ initializationCount ++ ] = var ;


signature:
public class Frame { /** * Replaces the given type with the appropriate type if it is one of the
 * types on which a constructor is invoked in the basic block .
 * @ param cw
 * the ClassWriter to which this label belongs .
 * @ param t
 * a type
 * @ return t or , if t is one of the types on which a constructor is invoked
 * in the basic block , the type corresponding to this constructor . */
private int init ( final ClassWriter cw , final int t ) { } }

implementation: int s ; if ( t == UNINITIALIZED_THIS ) { s = OBJECT | cw . addType ( cw . thisName ) ; } else if ( ( t & ( DIM | BASE_KIND ) ) == UNINITIALIZED ) { String type = cw . typeTable [ t & BASE_VALUE ] . strVal1 ; s = OBJECT | cw . addType ( type ) ; } else { return t ; } for ( int j = 0 ; j < initializationCount ; ++ j ) { int u = initializations [ j ] ; int dim = u & DIM ; int kind = u & KIND ; if ( kind == LOCAL ) { u = dim + inputLocals [ u & VALUE ] ; } else if ( kind == STACK ) { u = dim + inputStack [ inputStack . length - ( u & VALUE ) ] ; } if ( t == u ) { return s ; } } return t ;


signature:
public class Frame { /** * Simulates the action of the given instruction on the output stack frame .
 * @ param opcode
 * the opcode of the instruction .
 * @ param arg
 * the operand of the instruction , if any .
 * @ param cw
 * the class writer to which this label belongs .
 * @ param item
 * the operand of the instructions , if any . */
void execute ( final int opcode , final int arg , final ClassWriter cw , final Item item ) { } }

implementation:
int t1 , t2 , t3 , t4 ; switch ( opcode ) { case Opcodes . NOP : case Opcodes . INEG : case Opcodes . LNEG : case Opcodes . FNEG : case Opcodes . DNEG : case Opcodes . I2B : case Opcodes . I2C : case Opcodes . I2S : case Opcodes . GOTO : case Opcodes . RETURN : break ; case Opcodes . ACONST_NULL : push ( NULL ) ; break ; case Opcodes . ICONST_M1 : case Opcodes . ICONST_0 : case Opcodes . ICONST_1 : case Opcodes . ICONST_2 : case Opcodes . ICONST_3 : case Opcodes . ICONST_4 : case Opcodes . ICONST_5 : case Opcodes . BIPUSH : case Opcodes . SIPUSH : case Opcodes . ILOAD : push ( INTEGER ) ; break ; case Opcodes . LCONST_0 : case Opcodes . LCONST_1 : case Opcodes . LLOAD : push ( LONG ) ; push ( TOP ) ; break ; case Opcodes . FCONST_0 : case Opcodes . FCONST_1 : case Opcodes . FCONST_2 : case Opcodes . FLOAD : push ( FLOAT ) ; break ; case Opcodes . DCONST_0 : case Opcodes . DCONST_1 : case Opcodes . DLOAD : push ( DOUBLE ) ; push ( TOP ) ; break ; case Opcodes . LDC : switch ( item . type ) { case ClassWriter . INT : push ( INTEGER ) ; break ; case ClassWriter . LONG : push ( LONG ) ; push ( TOP ) ; break ; case ClassWriter . FLOAT : push ( FLOAT ) ; break ; case ClassWriter . DOUBLE : push ( DOUBLE ) ; push ( TOP ) ; break ; case ClassWriter . CLASS : push ( OBJECT | cw . addType ( "java/lang/Class" ) ) ; break ; case ClassWriter . STR : push ( OBJECT | cw . addType ( "java/lang/String" ) ) ; break ; case ClassWriter . MTYPE : push ( OBJECT | cw . addType ( "java/lang/invoke/MethodType" ) ) ; break ; // case ClassWriter . HANDLE _ BASE + [ 1 . . 9 ] :
default : push ( OBJECT | cw . addType ( "java/lang/invoke/MethodHandle" ) ) ; } break ; case Opcodes . ALOAD : push ( get ( arg ) ) ; break ; case Opcodes . IALOAD : case Opcodes . BALOAD : case Opcodes . CALOAD : case Opcodes . SALOAD : pop ( 2 ) ; push ( INTEGER ) ; break ; case Opcodes . LALOAD : case Opcodes . D2L : pop ( 2 ) ; push ( LONG ) ; push ( TOP ) ; break ; case Opcodes . FALOAD : pop ( 2 ) ; push ( FLOAT ) ; break ; case Opcodes . DALOAD : case Opcodes . L2D : pop ( 2 ) ; push ( DOUBLE ) ; push ( TOP ) ; break ; case Opcodes . AALOAD : pop ( 1 ) ; t1 = pop ( ) ; push ( ELEMENT_OF + t1 ) ; break ; case Opcodes . ISTORE : case Opcodes . FSTORE : case Opcodes . ASTORE : t1 = pop ( ) ; set ( arg , t1 ) ; if ( arg > 0 ) { t2 = get ( arg - 1 ) ; // if t2 is of kind STACK or LOCAL we cannot know its size !
if ( t2 == LONG || t2 == DOUBLE ) { set ( arg - 1 , TOP ) ; } else if ( ( t2 & KIND ) != BASE ) { set ( arg - 1 , t2 | TOP_IF_LONG_OR_DOUBLE ) ; } } break ; case Opcodes . LSTORE : case Opcodes . DSTORE : pop ( 1 ) ; t1 = pop ( ) ; set ( arg , t1 ) ; set ( arg + 1 , TOP ) ; if ( arg > 0 ) { t2 = get ( arg - 1 ) ; // if t2 is of kind STACK or LOCAL we cannot know its size !
if ( t2 == LONG || t2 == DOUBLE ) { set ( arg - 1 , TOP ) ; } else if ( ( t2 & KIND ) != BASE ) { set ( arg - 1 , t2 | TOP_IF_LONG_OR_DOUBLE ) ; } } break ; case Opcodes . IASTORE : case Opcodes . BASTORE : case Opcodes . CASTORE : case Opcodes . SASTORE : case Opcodes . FASTORE : case Opcodes . AASTORE : pop ( 3 ) ; break ; case Opcodes . LASTORE : case Opcodes . DASTORE : pop ( 4 ) ; break ; case Opcodes . POP : case Opcodes . IFEQ : case Opcodes . IFNE : case Opcodes . IFLT : case Opcodes . IFGE : case Opcodes . IFGT : case Opcodes . IFLE : case Opcodes . IRETURN : case Opcodes . FRETURN : case Opcodes . ARETURN : case Opcodes . TABLESWITCH : case Opcodes . LOOKUPSWITCH : case Opcodes . ATHROW : case Opcodes . MONITORENTER : case Opcodes . MONITOREXIT : case Opcodes . IFNULL : case Opcodes . IFNONNULL : pop ( 1 ) ; break ; case Opcodes . POP2 : case Opcodes . IF_ICMPEQ : case Opcodes . IF_ICMPNE : case Opcodes . IF_ICMPLT : case Opcodes . IF_ICMPGE : case Opcodes . IF_ICMPGT : case Opcodes . IF_ICMPLE : case Opcodes . IF_ACMPEQ : case Opcodes . IF_ACMPNE : case Opcodes . LRETURN : case Opcodes . DRETURN : pop ( 2 ) ; break ; case Opcodes . DUP : t1 = pop ( ) ; push ( t1 ) ; push ( t1 ) ; break ; case Opcodes . DUP_X1 : t1 = pop ( ) ; t2 = pop ( ) ; push ( t1 ) ; push ( t2 ) ; push ( t1 ) ; break ; case Opcodes . DUP_X2 : t1 = pop ( ) ; t2 = pop ( ) ; t3 = pop ( ) ; push ( t1 ) ; push ( t3 ) ; push ( t2 ) ; push ( t1 ) ; break ; case Opcodes . DUP2 : t1 = pop ( ) ; t2 = pop ( ) ; push ( t2 ) ; push ( t1 ) ; push ( t2 ) ; push ( t1 ) ; break ; case Opcodes . DUP2_X1 : t1 = pop ( ) ; t2 = pop ( ) ; t3 = pop ( ) ; push ( t2 ) ; push ( t1 ) ; push ( t3 ) ; push ( t2 ) ; push ( t1 ) ; break ; case Opcodes . DUP2_X2 : t1 = pop ( ) ; t2 = pop ( ) ; t3 = pop ( ) ; t4 = pop ( ) ; push ( t2 ) ; push ( t1 ) ; push ( t4 ) ; push ( t3 ) ; push ( t2 ) ; push ( t1 ) ; break ; case Opcodes . SWAP : t1 = pop ( ) ; t2 = pop ( ) ; push ( t1 ) ; push ( t2 ) ; break ; case Opcodes . IADD : case Opcodes . ISUB : case Opcodes . IMUL : case Opcodes . IDIV : case Opcodes . IREM : case Opcodes . IAND : case Opcodes . IOR : case Opcodes . IXOR : case Opcodes . ISHL : case Opcodes . ISHR : case Opcodes . IUSHR : case Opcodes . L2I : case Opcodes . D2I : case Opcodes . FCMPL : case Opcodes . FCMPG : pop ( 2 ) ; push ( INTEGER ) ; break ; case Opcodes . LADD : case Opcodes . LSUB : case Opcodes . LMUL : case Opcodes . LDIV : case Opcodes . LREM : case Opcodes . LAND : case Opcodes . LOR : case Opcodes . LXOR : pop ( 4 ) ; push ( LONG ) ; push ( TOP ) ; break ; case Opcodes . FADD : case Opcodes . FSUB : case Opcodes . FMUL : case Opcodes . FDIV : case Opcodes . FREM : case Opcodes . L2F : case Opcodes . D2F : pop ( 2 ) ; push ( FLOAT ) ; break ; case Opcodes . DADD : case Opcodes . DSUB : case Opcodes . DMUL : case Opcodes . DDIV : case Opcodes . DREM : pop ( 4 ) ; push ( DOUBLE ) ; push ( TOP ) ; break ; case Opcodes . LSHL : case Opcodes . LSHR : case Opcodes . LUSHR : pop ( 3 ) ; push ( LONG ) ; push ( TOP ) ; break ; case Opcodes . IINC : set ( arg , INTEGER ) ; break ; case Opcodes . I2L : case Opcodes . F2L : pop ( 1 ) ; push ( LONG ) ; push ( TOP ) ; break ; case Opcodes . I2F : pop ( 1 ) ; push ( FLOAT ) ; break ; case Opcodes . I2D : case Opcodes . F2D : pop ( 1 ) ; push ( DOUBLE ) ; push ( TOP ) ; break ; case Opcodes . F2I : case Opcodes . ARRAYLENGTH : case Opcodes . INSTANCEOF : pop ( 1 ) ; push ( INTEGER ) ; break ; case Opcodes . LCMP : case Opcodes . DCMPL : case Opcodes . DCMPG : pop ( 4 ) ; push ( INTEGER ) ; break ; case Opcodes . JSR : case Opcodes . RET : throw new RuntimeException ( "JSR/RET are not supported with computeFrames option" ) ; case Opcodes . GETSTATIC : push ( cw , item . strVal3 ) ; break ; case Opcodes . PUTSTATIC : pop ( item . strVal3 ) ; break ; case Opcodes . GETFIELD : pop ( 1 ) ; push ( cw , item . strVal3 ) ; break ; case Opcodes . PUTFIELD : pop ( item . strVal3 ) ; pop ( ) ; break ; case Opcodes . INVOKEVIRTUAL : case Opcodes . INVOKESPECIAL : case Opcodes . INVOKESTATIC : case Opcodes . INVOKEINTERFACE : pop ( item . strVal3 ) ; if ( opcode != Opcodes . INVOKESTATIC ) { t1 = pop ( ) ; if ( opcode == Opcodes . INVOKESPECIAL && item . strVal2 . charAt ( 0 ) == '<' ) { init ( t1 ) ; } } push ( cw , item . strVal3 ) ; break ; case Opcodes . INVOKEDYNAMIC : pop ( item . strVal2 ) ; push ( cw , item . strVal2 ) ; break ; case Opcodes . NEW : push ( UNINITIALIZED | cw . addUninitializedType ( item . strVal1 , arg ) ) ; break ; case Opcodes . NEWARRAY : pop ( ) ; switch ( arg ) { case Opcodes . T_BOOLEAN : push ( ARRAY_OF | BOOLEAN ) ; break ; case Opcodes . T_CHAR : push ( ARRAY_OF | CHAR ) ; break ; case Opcodes . T_BYTE : push ( ARRAY_OF | BYTE ) ; break ; case Opcodes . T_SHORT : push ( ARRAY_OF | SHORT ) ; break ; case Opcodes . T_INT : push ( ARRAY_OF | INTEGER ) ; break ; case Opcodes . T_FLOAT : push ( ARRAY_OF | FLOAT ) ; break ; case Opcodes . T_DOUBLE : push ( ARRAY_OF | DOUBLE ) ; break ; // case Opcodes . T _ LONG :
default : push ( ARRAY_OF | LONG ) ; break ; } break ; case Opcodes . ANEWARRAY : String s = item . strVal1 ; pop ( ) ; if ( s . charAt ( 0 ) == '[' ) { push ( cw , '[' + s ) ; } else { push ( ARRAY_OF | OBJECT | cw . addType ( s ) ) ; } break ; case Opcodes . CHECKCAST : s = item . strVal1 ; pop ( ) ; if ( s . charAt ( 0 ) == '[' ) { push ( cw , s ) ; } else { push ( OBJECT | cw . addType ( s ) ) ; } break ; // case Opcodes . MULTIANEWARRAY :
default : pop ( arg ) ; push ( cw , item . strVal1 ) ; break ; }


signature:
public class Frame { /** * Merges the input frame of the given basic block with the input and output
 * frames of this basic block . Returns < tt > true < / tt > if the input frame of
 * the given label has been changed by this operation .
 * @ param cw
 * the ClassWriter to which this label belongs .
 * @ param frame
 * the basic block whose input frame must be updated .
 * @ param edge
 * the kind of the { @ link Edge } between this label and ' label ' .
 * See { @ link Edge # info } .
 * @ return < tt > true < / tt > if the input frame of the given label has been
 * changed by this operation . */
final boolean merge ( final ClassWriter cw , final Frame frame , final int edge ) { } }

implementation: boolean changed = false ; int i , s , dim , kind , t ; int nLocal = inputLocals . length ; int nStack = inputStack . length ; if ( frame . inputLocals == null ) { frame . inputLocals = new int [ nLocal ] ; changed = true ; } for ( i = 0 ; i < nLocal ; ++ i ) { if ( outputLocals != null && i < outputLocals . length ) { s = outputLocals [ i ] ; if ( s == 0 ) { t = inputLocals [ i ] ; } else { dim = s & DIM ; kind = s & KIND ; if ( kind == BASE ) { t = s ; } else { if ( kind == LOCAL ) { t = dim + inputLocals [ s & VALUE ] ; } else { t = dim + inputStack [ nStack - ( s & VALUE ) ] ; } if ( ( s & TOP_IF_LONG_OR_DOUBLE ) != 0 && ( t == LONG || t == DOUBLE ) ) { t = TOP ; } } } } else { t = inputLocals [ i ] ; } if ( initializations != null ) { t = init ( cw , t ) ; } changed |= merge ( cw , t , frame . inputLocals , i ) ; } if ( edge > 0 ) { for ( i = 0 ; i < nLocal ; ++ i ) { t = inputLocals [ i ] ; changed |= merge ( cw , t , frame . inputLocals , i ) ; } if ( frame . inputStack == null ) { frame . inputStack = new int [ 1 ] ; changed = true ; } changed |= merge ( cw , edge , frame . inputStack , 0 ) ; return changed ; } int nInputStack = inputStack . length + owner . inputStackTop ; if ( frame . inputStack == null ) { frame . inputStack = new int [ nInputStack + outputStackTop ] ; changed = true ; } for ( i = 0 ; i < nInputStack ; ++ i ) { t = inputStack [ i ] ; if ( initializations != null ) { t = init ( cw , t ) ; } changed |= merge ( cw , t , frame . inputStack , i ) ; } for ( i = 0 ; i < outputStackTop ; ++ i ) { s = outputStack [ i ] ; dim = s & DIM ; kind = s & KIND ; if ( kind == BASE ) { t = s ; } else { if ( kind == LOCAL ) { t = dim + inputLocals [ s & VALUE ] ; } else { t = dim + inputStack [ nStack - ( s & VALUE ) ] ; } if ( ( s & TOP_IF_LONG_OR_DOUBLE ) != 0 && ( t == LONG || t == DOUBLE ) ) { t = TOP ; } } if ( initializations != null ) { t = init ( cw , t ) ; } changed |= merge ( cw , t , frame . inputStack , nInputStack + i ) ; } return changed ;


signature:
public class Frame { /** * Merges the type at the given index in the given type array with the given
 * type . Returns < tt > true < / tt > if the type array has been modified by this
 * operation .
 * @ param cw
 * the ClassWriter to which this label belongs .
 * @ param t
 * the type with which the type array element must be merged .
 * @ param types
 * an array of types .
 * @ param index
 * the index of the type that must be merged in ' types ' .
 * @ return < tt > true < / tt > if the type array has been modified by this
 * operation . */
private static boolean merge ( final ClassWriter cw , int t , final int [ ] types , final int index ) { } }

implementation:
int u = types [ index ] ; if ( u == t ) { // if the types are equal , merge ( u , t ) = u , so there is no change
return false ; } if ( ( t & ~ DIM ) == NULL ) { if ( u == NULL ) { return false ; } t = NULL ; } if ( u == 0 ) { // if types [ index ] has never been assigned , merge ( u , t ) = t
types [ index ] = t ; return true ; } int v ; if ( ( u & BASE_KIND ) == OBJECT || ( u & DIM ) != 0 ) { // if u is a reference type of any dimension
if ( t == NULL ) { // if t is the NULL type , merge ( u , t ) = u , so there is no change
return false ; } else if ( ( t & ( DIM | BASE_KIND ) ) == ( u & ( DIM | BASE_KIND ) ) ) { // if t and u have the same dimension and same base kind
if ( ( u & BASE_KIND ) == OBJECT ) { // if t is also a reference type , and if u and t have the
// same dimension merge ( u , t ) = dim ( t ) | common parent of the
// element types of u and t
v = ( t & DIM ) | OBJECT | cw . getMergedType ( t & BASE_VALUE , u & BASE_VALUE ) ; } else { // if u and t are array types , but not with the same element
// type , merge ( u , t ) = dim ( u ) - 1 | java / lang / Object
int vdim = ELEMENT_OF + ( u & DIM ) ; v = vdim | OBJECT | cw . addType ( "java/lang/Object" ) ; } } else if ( ( t & BASE_KIND ) == OBJECT || ( t & DIM ) != 0 ) { // if t is any other reference or array type , the merged type
// is min ( udim , tdim ) | java / lang / Object , where udim is the
// array dimension of u , minus 1 if u is an array type with a
// primitive element type ( and similarly for tdim ) .
int tdim = ( ( ( t & DIM ) == 0 || ( t & BASE_KIND ) == OBJECT ) ? 0 : ELEMENT_OF ) + ( t & DIM ) ; int udim = ( ( ( u & DIM ) == 0 || ( u & BASE_KIND ) == OBJECT ) ? 0 : ELEMENT_OF ) + ( u & DIM ) ; v = Math . min ( tdim , udim ) | OBJECT | cw . addType ( "java/lang/Object" ) ; } else { // if t is any other type , merge ( u , t ) = TOP
v = TOP ; } } else if ( u == NULL ) { // if u is the NULL type , merge ( u , t ) = t ,
// or TOP if t is not a reference type
v = ( t & BASE_KIND ) == OBJECT || ( t & DIM ) != 0 ? t : TOP ; } else { // if u is any other type , merge ( u , t ) = TOP whatever t
v = TOP ; } if ( u != v ) { types [ index ] = v ; return true ; } return false ;


signature:
public class ClassVisitor { /** * Visits the source of the class .
 * @ param source
 * the name of the source file from which the class was compiled .
 * May be < tt > null < / tt > .
 * @ param debug
 * additional debug information to compute the correspondance
 * between source and compiled elements of the class . May be
 * < tt > null < / tt > . */
public void visitSource ( String source , String debug ) { } }

implementation: if ( cv != null ) { cv . visitSource ( source , debug ) ; }


signature:
public class ClassVisitor { /** * Visits the enclosing class of the class . This method must be called only
 * if the class has an enclosing class .
 * @ param owner
 * internal name of the enclosing class of the class .
 * @ param name
 * the name of the method that contains the class , or
 * < tt > null < / tt > if the class is not enclosed in a method of its
 * enclosing class .
 * @ param desc
 * the descriptor of the method that contains the class , or
 * < tt > null < / tt > if the class is not enclosed in a method of its
 * enclosing class . */
public void visitOuterClass ( String owner , String name , String desc ) { } }

implementation: if ( cv != null ) { cv . visitOuterClass ( owner , name , desc ) ; }


signature:
public class ClassVisitor { /** * Visits an annotation of the class .
 * @ param desc
 * the class descriptor of the annotation class .
 * @ param visible
 * < tt > true < / tt > if the annotation is visible at runtime .
 * @ return a visitor to visit the annotation values , or < tt > null < / tt > if
 * this visitor is not interested in visiting this annotation . */
public AnnotationVisitor visitAnnotation ( String desc , boolean visible ) { } }

implementation: if ( cv != null ) { return cv . visitAnnotation ( desc , visible ) ; } return null ;


signature:
public class ClassVisitor { /** * Visits an annotation on a type in the class signature .
 * @ param typeRef
 * a reference to the annotated type . The sort of this type
 * reference must be { @ link TypeReference # CLASS _ TYPE _ PARAMETER
 * CLASS _ TYPE _ PARAMETER } ,
 * { @ link TypeReference # CLASS _ TYPE _ PARAMETER _ BOUND
 * CLASS _ TYPE _ PARAMETER _ BOUND } or
 * { @ link TypeReference # CLASS _ EXTENDS CLASS _ EXTENDS } . See
 * { @ link TypeReference } .
 * @ param typePath
 * the path to the annotated type argument , wildcard bound , array
 * element type , or static inner type within ' typeRef ' . May be
 * < tt > null < / tt > if the annotation targets ' typeRef ' as a whole .
 * @ param desc
 * the class descriptor of the annotation class .
 * @ param visible
 * < tt > true < / tt > if the annotation is visible at runtime .
 * @ return a visitor to visit the annotation values , or < tt > null < / tt > if
 * this visitor is not interested in visiting this annotation . */
public AnnotationVisitor visitTypeAnnotation ( int typeRef , TypePath typePath , String desc , boolean visible ) { } }

implementation: if ( api < Opcodes . ASM5 ) { throw new RuntimeException ( ) ; } if ( cv != null ) { return cv . visitTypeAnnotation ( typeRef , typePath , desc , visible ) ; } return null ;


signature:
public class Db2JdbcExpert { /** * TODO not tested ! ! */
public boolean createEntity ( Dao dao , Entity < ? > en ) { } }

implementation:
StringBuilder sb = new StringBuilder ( "CREATE TABLE " + en . getTableName ( ) + "(" ) ; // 创建字段
for ( MappingField mf : en . getMappingFields ( ) ) { if ( mf . isReadonly ( ) ) continue ; sb . append ( '\n' ) . append ( mf . getColumnNameInSql ( ) ) ; sb . append ( ' ' ) . append ( evalFieldType ( mf ) ) ; // 非主键的 @ Name , 应该加入唯一性约束
if ( mf . isName ( ) && en . getPkType ( ) != PkType . NAME ) { sb . append ( " UNIQUE NOT NULL" ) ; } // 普通字段
else { if ( mf . isNotNull ( ) || mf . isPk ( ) ) sb . append ( " NOT NULL" ) ; if ( mf . hasDefaultValue ( ) ) { addDefaultValue ( sb , mf ) ; } if ( mf . isAutoIncreasement ( ) ) sb . append ( " generated by default as identity " ) ; if ( mf . isPk ( ) && en . getPks ( ) . size ( ) == 1 ) { sb . append ( " primary key " ) ; } } sb . append ( ',' ) ; } // 结束表字段设置
sb . setCharAt ( sb . length ( ) - 1 , ')' ) ; // 指定表空间
if ( en . hasMeta ( META_TABLESPACE ) ) { sb . append ( String . format ( " IN %s" , en . getMeta ( META_TABLESPACE ) ) ) ; } // 执行创建语句
dao . execute ( Sqls . create ( sb . toString ( ) ) ) ; // 创建联合主键
if ( en . getPks ( ) . size ( ) > 1 ) { sb = new StringBuilder ( ) ; sb . append ( "ALTER TABLE " ) . append ( en . getTableName ( ) ) . append ( " ADD CONSTRAINT PK_" ) ; sb . append ( makePksName ( en ) ) ; sb . append ( " PRIMARY KEY (" ) ; for ( MappingField mf : en . getPks ( ) ) { sb . append ( mf . getColumnNameInSql ( ) ) . append ( "," ) ; } sb . setCharAt ( sb . length ( ) - 1 , ')' ) ; dao . execute ( Sqls . create ( sb . toString ( ) ) ) ; } // 创建关联表
createRelation ( dao , en ) ; // 创建索引
dao . execute ( createIndexs ( en ) . toArray ( new Sql [ 0 ] ) ) ; // 添加注释 ( 表注释与字段注释 )
addComment ( dao , en ) ; return true ;


signature:
public class Maths { /** * 返回最大的一个
 * @ param nums
 * 需要比较的数组
 * @ return 最大值 */
public static int max ( int ... nums ) { } }

implementation: return takeOne ( new CompareSomeThing ( ) { @ Override public boolean compare ( int arg0 , int arg1 ) { return arg0 > arg1 ; } } , nums ) ;


signature:
public class Maths { /** * 返回最小的一个
 * @ param nums
 * 需要比较的数组
 * @ return 最小值 */
public static int min ( int ... nums ) { } }

implementation: return takeOne ( new CompareSomeThing ( ) { @ Override public boolean compare ( int arg0 , int arg1 ) { return arg0 < arg1 ; } } , nums ) ;


signature:
public class Maths { /** * Get part of one integer as a new integer
 * @ param bs
 * original integer
 * @ param low
 * the low bit position ( inclusive ) , 0 base
 * @ param high
 * the high bit position ( exclusive ) , 0 base
 * @ return new integer */
public static int extract ( int bs , int low , int high ) { } }

implementation: bs = bs >> low ; int mask = 0 ; for ( int i = 0 ; i < ( high - low ) ; i ++ ) { mask += 1 << i ; } return bs & mask ;


signature:
public class Maths { /** * 按照指定长度 , 获得字符数组的全排列
 * @ param arr
 * 字符数组
 * @ return 全排列 */
public static String [ ] permutation ( int length , char ... arr ) { } }

implementation:
if ( arr == null || arr . length == 0 || length <= 0 || length > arr . length ) { return null ; } List < String > slist = new ArrayList < String > ( ) ; char [ ] b = new char [ length ] ; // 辅助空间 , 保存待输出组合数
getCombination ( slist , arr , length , 0 , b , 0 ) ; return slist . toArray ( new String [ ] { } ) ;


signature:
public class Maths { /** * 坐标点旋转计算方法 。
 * 坐标点 ( x1 , y1 ) 绕另一个坐标点 ( x2 , y2 ) 旋转角度 ( a ) 后的新坐标
 * @ param x1
 * 被计算点横坐标
 * @ param y1
 * 被计算点纵坐标
 * @ param x2
 * 圆心横坐标
 * @ param y2
 * 圆心纵坐标
 * @ param a
 * 角度
 * @ return ( x3 , y3) */
public static int [ ] rotateXY ( int x1 , int y1 , int x2 , int y2 , double a ) { } }

implementation: double l = ( a * Math . PI ) / 180 ; double cosv = Math . cos ( l ) ; double sinv = Math . sin ( l ) ; int newX = ( int ) ( ( x1 - x2 ) * cosv - ( y1 - y2 ) * sinv + x2 ) ; int newY = ( int ) ( ( x1 - x2 ) * sinv + ( y1 - y2 ) * cosv + y2 ) ; return new int [ ] { newX , newY } ;


signature:
public class Maths { /** * - - - - - 以下为几个辅助方法 */
private static void getCombination ( List < String > slist , char [ ] a , int n , int begin , char [ ] b , int index ) { } }

implementation:
if ( n == 0 ) { // 如果够n个数了 , 输出b数组
getAllPermutation ( slist , b , 0 ) ; // 得到b的全排列
return ; } for ( int i = begin ; i < a . length ; i ++ ) { b [ index ] = a [ i ] ; getCombination ( slist , a , n - 1 , i + 1 , b , index + 1 ) ; }


signature:
public class MappingNode { /** * 增加一个映射 , 将 obj 映射到 path 上 , 或 path 上的 [ ? , * ] */
public void add ( String path , T obj ) { } }

implementation: try { String [ ] ss = Strings . splitIgnoreBlank ( path , "/" ) ; add ( obj , ss , 0 ) ; } catch ( Exception e ) { throw Lang . wrapThrow ( e , "Wrong Url path format '%s'" , path ) ; }


signature:
public class FieldFilter { /** * 创建一个过滤器
 * @ param type
 * POJO 类型
 * @ param locked
 * 正则表达式 , 哪些字段会被忽略 , 语法请参看 Pattern 类的 JavaDoc
 * @ return 字段过滤器 */
public static FieldFilter locked ( Class < ? > type , String locked ) { } }

implementation: return create ( type , null , locked , true ) ;


signature:
public class FieldFilter { /** * 创建一个过滤器
 * @ param type
 * POJO 类型
 * @ param ignoreNull
 * 是否忽略 NULL 值字段
 * @ return 字段过滤器 */
public static FieldFilter create ( Class < ? > type , boolean ignoreNull ) { } }

implementation: return create ( type , null , null , ignoreNull ) ;


signature:
public class FieldFilter { /** * 创建一个默认不忽略 NULL 值字段的过滤器
 * @ param type
 * POJO 类型
 * @ param actived
 * 正则表达式 , 哪些字段会被操作 , 语法请参看 Pattern 类的 JavaDoc
 * @ return 字段过滤器
 * @ see java . util . regex . Pattern */
public static FieldFilter create ( Class < ? > type , String actived ) { } }

implementation: return create ( type , actived , null , false ) ;


signature:
public class FieldFilter { /** * 创建一个过滤器
 * @ param type
 * POJO 类型
 * @ param actived
 * 正则表达式 , 哪些字段会被操作 , 语法请参看 Pattern 类的 JavaDoc
 * @ param ignoreNull
 * 是否忽略 NULL 值字段
 * @ return 字段过滤器
 * @ see java . util . regex . Pattern */
public static FieldFilter create ( Class < ? > type , String actived , boolean ignoreNull ) { } }

implementation: return create ( type , actived , null , ignoreNull ) ;


signature:
public class FieldFilter { /** * 创建一个过滤器
 * @ param type
 * POJO 类型
 * @ param actived
 * 正则表达式 , 哪些字段会被操作 , 语法请参看 Pattern 类的 JavaDoc
 * @ param locked
 * 正则表达式 , 哪些字段会被忽略 , 语法请参看 Pattern 类的 JavaDoc
 * @ param ignoreNull
 * 是否忽略 NULL 值字段
 * @ return 字段过滤器
 * @ see java . util . regex . Pattern */
public static FieldFilter create ( Class < ? > type , String actived , String locked , boolean ignoreNull ) { } }

implementation: return create ( type , FieldMatcher . make ( actived , locked , ignoreNull ) ) ;


signature:
public class FieldFilter { /** * 创建一个过滤器
 * @ param type
 * POJO 类型
 * @ param mathcer
 * 字段匹配器
 * @ return 字段过滤器 */
public static FieldFilter create ( Class < ? > type , FieldMatcher mathcer ) { } }

implementation: FieldFilter ff = new FieldFilter ( ) ; ff . set ( type , mathcer ) ; return ff ;


signature:
public class FieldFilter { /** * 为自身增加一个 POJO 的字段过滤设置
 * @ param type
 * POJO 类型
 * @ param actived
 * 正则表达式 , 哪些字段会被操作 , 语法请参看 Pattern 类的 JavaDoc
 * @ param locked
 * 正则表达式 , 哪些字段会被忽略 , 语法请参看 Pattern 类的 JavaDoc
 * @ param ignoreNull
 * 是否忽略 NULL 值字段
 * @ return 自身 */
public FieldFilter set ( Class < ? > type , String actived , String locked , boolean ignoreNull ) { } }

implementation: map . put ( type , FieldMatcher . make ( actived , locked , ignoreNull ) ) ; return this ;


signature:
public class FieldFilter { /** * 为自身增加一个 POJO 的字段过滤设置
 * @ param type
 * POJO 类型
 * @ param matcher
 * 字段匹配器
 * @ return 自身 */
public FieldFilter set ( Class < ? > type , FieldMatcher matcher ) { } }

implementation: map . put ( type , matcher ) ; return this ;


signature:
public class FieldFilter { /** * 根据 POJO 的类型 , 从 ThreadLocal 中获取字段过滤器
 * @ param type
 * POJO 的类型
 * @ return 字段过滤器 */
public static FieldMatcher get ( Class < ? > type ) { } }

implementation: FieldFilter ff = FF . get ( ) ; if ( null == ff ) return null ; return ff . map . get ( type ) ;


signature:
public class FieldFilter { /** * 运行模板函数
 * @ param atom
 * 运行原子 */
public void run ( Atom atom ) { } }

implementation: FF . set ( this ) ; try { atom . run ( ) ; } catch ( Exception e ) { throw Lang . wrapThrow ( e ) ; } finally { FF . remove ( ) ; }


signature:
public class Scans { /** * 在Web环境中使用Nutz的任何功能 , 都应该先调用这个方法 , 以初始化资源扫描器
 * 调用一次就可以了 */
public Scans init ( final ServletContext sc ) { } }

implementation:
Stopwatch sw = Stopwatch . begin ( ) ; // 获取classes文件夹的路径 , 优先级为125
String classesPath = sc . getRealPath ( "/WEB-INF/classes" ) ; if ( classesPath == null ) addResourceLocation ( new WebClassesResourceLocation ( sc ) ) ; else { ResourceLocation rc = ResourceLocation . file ( new File ( classesPath ) ) ; if ( rc instanceof FileSystemResourceLocation ) ( ( FileSystemResourceLocation ) rc ) . priority = 125 ; addResourceLocation ( rc ) ; } // 获取lib文件夹中的全部jar , 优先级是50
Set < String > jars = sc . getResourcePaths ( "/WEB-INF/lib/" ) ; if ( jars != null ) { // 这个文件夹不一定存在 , 尤其是Maven的WebApp项目
for ( String path : jars ) { if ( ! path . endsWith ( ".jar" ) ) continue ; try { addResourceLocation ( new JarResourceLocation ( sc . getResource ( path ) ) ) ; } catch ( Exception e ) { log . debug ( "parse jar fail >> " + e . getMessage ( ) ) ; } } } sw . stop ( ) ; printLocations ( sw ) ; return this ;


signature:
public class Scans { /** * 在磁盘目录或者 CLASSPATH ( 包括 jar ) 中搜索资源
 * < b > 核心方法 < / b >
 * @ param src
 * 起始路径
 * @ param regex
 * 资源名需要匹配的正则表达式
 * @ return 资源列表 */
public List < NutResource > scan ( String src , String regex ) { } }

implementation:
if ( src . isEmpty ( ) ) throw new RuntimeException ( "emtry src is NOT allow" ) ; if ( "/" . equals ( src ) ) throw new RuntimeException ( "root path is NOT allow" ) ; List < NutResource > list = new ArrayList < NutResource > ( ) ; Pattern pattern = regex == null ? null : Pattern . compile ( regex ) ; // 先看看是不是文件系统上一个具体的文件
if ( src . startsWith ( "~/" ) ) src = Disks . normalize ( src ) ; File srcFile = new File ( src ) ; if ( srcFile . exists ( ) ) { if ( srcFile . isDirectory ( ) ) { Disks . visitFile ( srcFile , new ResourceFileVisitor ( list , src , 250 ) , new ResourceFileFilter ( pattern ) ) ; } else { list . add ( new FileResource ( src , srcFile ) . setPriority ( 250 ) ) ; } } for ( ResourceLocation location : locations . values ( ) ) { location . scan ( src , pattern , list ) ; } // 如果啥都没找到 , 那么 , 用增强扫描
if ( list . isEmpty ( ) ) { try { Enumeration < URL > enu = ClassTools . getClassLoader ( ) . getResources ( src ) ; if ( enu != null && enu . hasMoreElements ( ) ) { while ( enu . hasMoreElements ( ) ) { try { URL url = enu . nextElement ( ) ; ResourceLocation loc = makeResourceLocation ( url ) ; if ( url . toString ( ) . contains ( "jar!" ) ) loc . scan ( src , pattern , list ) ; else loc . scan ( "" , pattern , list ) ; } catch ( Throwable e ) { if ( log . isTraceEnabled ( ) ) log . trace ( "" , e ) ; } } } } catch ( Throwable e ) { if ( log . isDebugEnabled ( ) ) log . debug ( "Fail to run deep scan!" , e ) ; } // 依然是空 ?
if ( list . isEmpty ( ) && ! src . endsWith ( "/" ) ) { try { ClassLoader classLoader = getClass ( ) . getClassLoader ( ) ; InputStream tmp = classLoader . getResourceAsStream ( src + "/" ) ; if ( tmp != null ) { tmp . close ( ) ; } else { InputStream ins = classLoader . getResourceAsStream ( src ) ; if ( ins != null ) { list . add ( new SimpleResource ( src , src , ins ) ) ; } } } catch ( Exception e ) { } } } List < NutResource > _list = new ArrayList < NutResource > ( ) ; OUT : for ( NutResource nr : list ) { Iterator < NutResource > it = _list . iterator ( ) ; while ( it . hasNext ( ) ) { NutResource nr2 = it . next ( ) ; if ( nr . equals ( nr2 ) ) { if ( nr . priority > nr2 . priority ) { it . remove ( ) ; } else { continue OUT ; } } } _list . add ( nr ) ; } list = _list ; Collections . sort ( list ) ; if ( log . isDebugEnabled ( ) ) log . debugf ( "Found %s resource by src( %s ) , regex( %s )" , list . size ( ) , src , regex ) ; return list ;


signature:
public class Scans { /** * 搜索给定包下所有的类 ( 递归 ) , 并返回所有符合正则式描述的类
 * @ param pkg
 * 包名或者包路径
 * @ param regex
 * 正则表达式 , 请注意你需要匹配的名称为 ' xxxx . class ' 而不仅仅是类名 , 从而保证选出的对象都是类文件 */
public List < Class < ? > > scanPackage ( String pkg , String regex ) { } }

implementation: String packagePath = pkg . replace ( '.' , '/' ) . replace ( '\\' , '/' ) ; if ( ! packagePath . endsWith ( "/" ) ) packagePath += "/" ; return rs2class ( pkg , scan ( packagePath , regex ) ) ;


signature:
public class Scans { /** * 将一组 NutResource 转换成 class 对象
 * @ param packagePath
 * 包前缀
 * @ param list
 * 列表
 * @ return 类对象列表 */
private static List < Class < ? > > rs2class ( String pkg , List < NutResource > list ) { } }

implementation:
Set < Class < ? > > re = new LinkedHashSet < Class < ? > > ( list . size ( ) ) ; if ( ! list . isEmpty ( ) ) { for ( NutResource nr : list ) { if ( ! nr . getName ( ) . endsWith ( ".class" ) || nr . getName ( ) . endsWith ( "package-info.class" ) ) { continue ; } // Class快速载入
String className = pkg + "." + nr . getName ( ) . substring ( 0 , nr . getName ( ) . length ( ) - 6 ) . replaceAll ( "[/\\\\]" , "." ) ; try { Class < ? > klass = Lang . loadClass ( className ) ; re . add ( klass ) ; continue ; } catch ( Throwable e ) { } // 失败了 ? 尝试终极方法 , 当然了 , 慢多了
InputStream in = null ; try { in = nr . getInputStream ( ) ; className = ClassTools . getClassName ( in ) ; if ( className == null ) { if ( log . isInfoEnabled ( ) ) log . infof ( "Resource can't map to Class, Resource %s" , nr ) ; continue ; } Class < ? > klass = Lang . loadClass ( className ) ; re . add ( klass ) ; } catch ( Throwable e ) { if ( log . isInfoEnabled ( ) ) log . info ( "Resource can't map to Class, Resource " + nr . getName ( ) ) ; } finally { Streams . safeClose ( in ) ; } } } return new ArrayList < Class < ? > > ( re ) ;


signature:
public class ShuntingYard { /** * 转换操作符 .
 * 根据 ShuntingYard 算法进行操作
 * @ param current */
private void parseOperator ( Operator current ) { } }

implementation:
// 空 , 直接添加进操作符队列
if ( opts . isEmpty ( ) ) { opts . addFirst ( current ) ; return ; } // 左括号
if ( current instanceof LBracketOpt ) { opts . addFirst ( current ) ; return ; } // 遇到右括号
if ( current instanceof RBracketOpt ) { while ( ! opts . isEmpty ( ) && ! ( opts . peek ( ) instanceof LBracketOpt ) ) { rpn . add ( opts . poll ( ) ) ; } opts . poll ( ) ; return ; } // 符号队列top元素优先级大于当前 , 则直接添加到
if ( ! opts . isEmpty ( ) && opts . peek ( ) . fetchPriority ( ) > current . fetchPriority ( ) ) { opts . addFirst ( current ) ; return ; } // 一般情况 , 即优先级小于栈顶 , 那么直接弹出来 , 添加到逆波兰表达式中
while ( ! opts . isEmpty ( ) && opts . peek ( ) . fetchPriority ( ) <= current . fetchPriority ( ) ) { // 三元表达式嵌套的特殊处理
if ( opts . peek ( ) instanceof QuestionOpt && current instanceof QuestionOpt ) { break ; } if ( opts . peek ( ) instanceof QuestionOpt && current instanceof QuestionSelectOpt ) { rpn . add ( opts . poll ( ) ) ; break ; } rpn . add ( opts . poll ( ) ) ; } opts . addFirst ( current ) ;


signature:
public class ShuntingYard { /** * 转换成 逆波兰表示法 ( Reverse Polish notation , RPN , 或逆波兰记法 )
 * @ param val
 * @ throws IOException */
public Queue < Object > parseToRPN ( String val ) { } }

implementation: rpn = new LinkedList < Object > ( ) ; opts = new LinkedList < Operator > ( ) ; Converter converter = new Converter ( val ) ; converter . initItems ( ) ; while ( ! converter . isEnd ( ) ) { Object item = converter . fetchItem ( ) ; if ( item instanceof Operator ) { parseOperator ( ( Operator ) item ) ; continue ; } rpn . add ( item ) ; } while ( ! opts . isEmpty ( ) ) { rpn . add ( opts . poll ( ) ) ; } return rpn ;


signature:
public class ActionInvoker { /** * 增加 ActionChain
 * @ param httpMethod
 * HTTP 的请求方法 ( GET | POST | PUT | DELETE ) , 如果为空 , 则会抛错
 * @ param chain
 * 动作链 */
public void addChain ( String httpMethod , ActionChain chain ) { } }

implementation: if ( Strings . isBlank ( httpMethod ) ) throw Lang . makeThrow ( "chain need a valid HTTP Method, but is is '%s'" , httpMethod ) ; ActionChain old = chainMap . put ( httpMethod . toUpperCase ( ) , chain ) ; if ( old != null ) { log . warnf ( "Duplicate @At mapping with same HttpMethod" ) ; }


signature:
public class ActionInvoker { /** * 根据动作链上下文对象 , 调用一个相应的动作链
 * @ param ac
 * 动作链上下文
 * @ return true - 成功的找到一个动作链并执行 。 false - 没有找到动作链 */
public boolean invoke ( ActionContext ac ) { } }

implementation: ActionChain chain = getActionChain ( ac ) ; if ( chain == null ) { if ( log . isDebugEnabled ( ) ) log . debugf ( "Not chain for req (path=%s, method=%s)" , ac . getPath ( ) , ac . getRequest ( ) . getMethod ( ) ) ; return false ; } chain . doChain ( ac ) ; return ac . getBoolean ( ActionContext . AC_DONE , true ) ;


signature:
public class Streams { /** * 将一段文本全部写入一个writer 。
 * < b style = color : red > 注意 < / b > , 它并不会关闭输出流
 * @ param writer
 * @ param cs
 * 文本
 * @ throws IOException */
public static void write ( Writer writer , CharSequence cs ) throws IOException { } }

implementation: if ( null != cs && null != writer ) { writer . write ( cs . toString ( ) ) ; writer . flush ( ) ; }


signature:
public class Streams { /** * 将一段文本全部写入一个writer 。
 * < b style = color : red > 注意 < / b > , 它会关闭输出流
 * @ param writer
 * 输出流
 * @ param cs
 * 文本 */
public static void writeAndClose ( Writer writer , CharSequence cs ) { } }

implementation: try { write ( writer , cs ) ; } catch ( IOException e ) { throw Lang . wrapThrow ( e ) ; } finally { safeClose ( writer ) ; }


signature:
public class Streams { /** * 将输入流写入一个输出流 。 块大小为 8192
 * < b style = color : red > 注意 < / b > , 它并不会关闭输入 / 出流
 * @ param ops
 * 输出流
 * @ param ins
 * 输入流
 * @ return 写入的字节数
 * @ throws IOException */
public static long write ( OutputStream ops , InputStream ins ) throws IOException { } }

implementation: return write ( ops , ins , BUF_SIZE ) ;


signature:
public class Streams { /** * 将输入流写入一个输出流 。
 * < b style = color : red > 注意 < / b > , 它并不会关闭输入 / 出流
 * @ param ops
 * 输出流
 * @ param ins
 * 输入流
 * @ param bufferSize
 * 缓冲块大小
 * @ return 写入的字节数
 * @ throws IOException */
public static long write ( OutputStream ops , InputStream ins , int bufferSize ) throws IOException { } }

implementation:
if ( null == ops || null == ins ) return 0 ; byte [ ] buf = new byte [ bufferSize ] ; int len ; long bytesCount = 0 ; while ( - 1 != ( len = ins . read ( buf ) ) ) { bytesCount += len ; ops . write ( buf , 0 , len ) ; } // 啥都没写 , 强制触发一下写
// 这是考虑到 walnut 的输出流实现 , 比如你写一个空文件
// 那么输入流就是空的 , 但是 walnut 的包裹输出流并不知道你写过了
// 它人你就是打开一个输出流 , 然后再关上 , 所以自然不会对内容做改动
// 所以这里触发一个写 , 它就知道 , 喔你要写个空喔 。
if ( 0 == bytesCount ) { ops . write ( buf , 0 , 0 ) ; } ops . flush ( ) ; return bytesCount ;


signature:
public class Streams { /** * 将输入流写入一个输出流 。 块大小为 8192
 * < b style = color : red > 注意 < / b > , 它会关闭输入 / 出流
 * @ param ops
 * 输出流
 * @ param ins
 * 输入流
 * @ return 写入的字节数 */
public static long writeAndClose ( OutputStream ops , InputStream ins ) { } }

implementation: try { return write ( ops , ins ) ; } catch ( IOException e ) { throw Lang . wrapThrow ( e ) ; } finally { safeClose ( ops ) ; safeClose ( ins ) ; }


signature:
public class Streams { /** * 将文本输入流写入一个文本输出流 。 块大小为 8192
 * < b style = color : red > 注意 < / b > , 它并不会关闭输入 / 出流
 * @ param writer
 * 输出流
 * @ param reader
 * 输入流
 * @ throws IOException */
public static long write ( Writer writer , Reader reader ) throws IOException { } }

implementation: if ( null == writer || null == reader ) return 0 ; char [ ] cbuf = new char [ BUF_SIZE ] ; int len , count = 0 ; while ( true ) { len = reader . read ( cbuf ) ; if ( len == - 1 ) break ; writer . write ( cbuf , 0 , len ) ; count += len ; } return count ;


signature:
public class Streams { /** * 将文本输入流写入一个文本输出流 。 块大小为 8192
 * < b style = color : red > 注意 < / b > , 它会关闭输入 / 出流
 * @ param writer
 * 输出流
 * @ param reader
 * 输入流 */
public static long writeAndClose ( Writer writer , Reader reader ) { } }

implementation: try { return write ( writer , reader ) ; } catch ( IOException e ) { throw Lang . wrapThrow ( e ) ; } finally { safeClose ( writer ) ; safeClose ( reader ) ; }


signature:
public class Streams { /** * 将一个字节数组写入一个输出流 。
 * < b style = color : red > 注意 < / b > , 它并不会关闭输出流
 * @ param ops
 * 输出流
 * @ param bytes
 * 字节数组
 * @ throws IOException */
public static void write ( OutputStream ops , byte [ ] bytes ) throws IOException { } }

implementation: if ( null == ops || null == bytes || bytes . length == 0 ) return ; ops . write ( bytes ) ;


signature:
public class Streams { /** * 将一个字节数组写入一个输出流 。
 * < b style = color : red > 注意 < / b > , 它会关闭输出流
 * @ param ops
 * 输出流
 * @ param bytes
 * 字节数组 */
public static void writeAndClose ( OutputStream ops , byte [ ] bytes ) { } }

implementation: try { write ( ops , bytes ) ; } catch ( IOException e ) { throw Lang . wrapThrow ( e ) ; } finally { safeClose ( ops ) ; }


signature:
public class Streams { /** * 从一个文本流中读取全部内容并返回
 * < b style = color : red > 注意 < / b > , 它并不会关闭输出流
 * @ param reader
 * 文本输出流
 * @ return 文本内容
 * @ throws IOException */
public static StringBuilder read ( Reader reader ) throws IOException { } }

implementation: StringBuilder sb = new StringBuilder ( ) ; read ( reader , sb ) ; return sb ;


signature:
public class Streams { /** * 从一个文本流中读取全部内容并返回
 * < b style = color : red > 注意 < / b > , 它会关闭输入流
 * @ param reader
 * 文本输入流
 * @ return 文本内容
 * @ throws IOException */
public static String readAndClose ( Reader reader ) { } }

implementation: try { return read ( reader ) . toString ( ) ; } catch ( IOException e ) { throw Lang . wrapThrow ( e ) ; } finally { safeClose ( reader ) ; }


signature:
public class Streams { /** * 从一个文本流中读取全部内容并写入缓冲
 * < b style = color : red > 注意 < / b > , 它并不会关闭输出流
 * @ param reader
 * 文本输出流
 * @ param sb
 * 输出的文本缓冲
 * @ return 读取的字符数量
 * @ throws IOException */
public static int read ( Reader reader , StringBuilder sb ) throws IOException { } }

implementation: char [ ] cbuf = new char [ BUF_SIZE ] ; int count = 0 ; int len ; while ( - 1 != ( len = reader . read ( cbuf ) ) ) { sb . append ( cbuf , 0 , len ) ; count += len ; } return count ;


signature:
public class Streams { /** * 从一个文本流中读取全部内容并写入缓冲
 * < b style = color : red > 注意 < / b > , 它会关闭输出流
 * @ param reader
 * 文本输出流
 * @ param sb
 * 输出的文本缓冲
 * @ return 读取的字符数量 */
public static int readAndClose ( InputStreamReader reader , StringBuilder sb ) { } }

implementation: try { return read ( reader , sb ) ; } catch ( IOException e ) { throw Lang . wrapThrow ( e ) ; } finally { safeClose ( reader ) ; }


signature:
public class Streams { /** * 读取一个输入流中所有的字节
 * @ param ins
 * 输入流 , 必须支持 available ( )
 * @ return 一个字节数组
 * @ throws IOException */
public static byte [ ] readBytes ( InputStream ins ) throws IOException { } }

implementation: ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; write ( out , ins ) ; return out . toByteArray ( ) ;


signature:
public class Streams { /** * 读取一个输入流中所有的字节 , 并关闭输入流
 * @ param ins
 * 输入流 , 必须支持 available ( )
 * @ return 一个字节数组
 * @ throws IOException */
public static byte [ ] readBytesAndClose ( InputStream ins ) { } }

implementation: byte [ ] bytes = null ; try { bytes = readBytes ( ins ) ; } catch ( IOException e ) { throw Lang . wrapThrow ( e ) ; } finally { Streams . safeClose ( ins ) ; } return bytes ;


signature:
public class Streams { /** * 关闭一个可关闭对象 , 可以接受 null 。 如果成功关闭 , 返回 true , 发生异常 返回 false
 * @ param cb
 * 可关闭对象
 * @ return 是否成功关闭 */
public static boolean safeClose ( Closeable cb ) { } }

implementation: if ( null != cb ) try { cb . close ( ) ; } catch ( IOException e ) { return false ; } return true ;


signature:
public class Streams { /** * 为一个输入流包裹一个缓冲流 。 如果这个输入流本身就是缓冲流 , 则直接返回
 * @ param ins
 * 输入流 。
 * @ return 缓冲输入流 */
public static BufferedInputStream buff ( InputStream ins ) { } }

implementation:
if ( ins == null ) throw new NullPointerException ( "ins is null!" ) ; if ( ins instanceof BufferedInputStream ) return ( BufferedInputStream ) ins ; // BufferedInputStream的构造方法 , 竟然是允许null参数的 ! ! 我 & $ # ^ $ & %
return new BufferedInputStream ( ins ) ;


signature:
public class Streams { /** * 为一个输出流包裹一个缓冲流 。 如果这个输出流本身就是缓冲流 , 则直接返回
 * @ param ops
 * 输出流 。
 * @ return 缓冲输出流 */
public static BufferedOutputStream buff ( OutputStream ops ) { } }

implementation: if ( ops == null ) throw new NullPointerException ( "ops is null!" ) ; if ( ops instanceof BufferedOutputStream ) return ( BufferedOutputStream ) ops ; return new BufferedOutputStream ( ops ) ;


signature:
public class Streams { /** * 为一个文本输入流包裹一个缓冲流 。 如果这个输入流本身就是缓冲流 , 则直接返回
 * @ param reader
 * 文本输入流 。
 * @ return 缓冲文本输入流 */
public static BufferedReader buffr ( Reader reader ) { } }

implementation: if ( reader instanceof BufferedReader ) return ( BufferedReader ) reader ; return new BufferedReader ( reader ) ;


signature:
public class Streams { /** * 为一个文本输出流包裹一个缓冲流 。 如果这个文本输出流本身就是缓冲流 , 则直接返回
 * @ param ops
 * 文本输出流 。
 * @ return 缓冲文本输出流 */
public static BufferedWriter buffw ( Writer ops ) { } }

implementation: if ( ops instanceof BufferedWriter ) return ( BufferedWriter ) ops ; return new BufferedWriter ( ops ) ;


signature:
public class Streams { /** * 根据一个文件路径建立一个输入流
 * @ param path
 * 文件路径
 * @ return 输入流 */
public static InputStream fileIn ( String path ) { } }

implementation:
InputStream ins = Files . findFileAsStream ( path ) ; if ( null == ins ) { File f = Files . findFile ( path ) ; if ( null != f ) try { ins = Streams . _input ( f ) ; } catch ( IOException e ) { } } if ( null == ins ) { // TODO 考虑一下 , 应该抛异常呢 ? 还是返回null呢 ?
throw new RuntimeException ( new FileNotFoundException ( path ) ) ; // return null ;
} return buff ( ins ) ;


signature:
public class Streams { /** * 根据一个文件路径建立一个输入流
 * @ param file
 * 文件
 * @ return 输入流 */
public static InputStream fileIn ( File file ) { } }

implementation: try { return buff ( Streams . _input ( file ) ) ; } catch ( IOException e ) { throw Lang . wrapThrow ( e ) ; }


signature:
public class Streams { /** * 判断并移除UTF - 8的BOM头 */
public static InputStream utf8filte ( InputStream in ) { } }

implementation: try { if ( in . available ( ) == - 1 ) return in ; PushbackInputStream pis = new PushbackInputStream ( in , 3 ) ; byte [ ] header = new byte [ 3 ] ; int len = pis . read ( header , 0 , 3 ) ; if ( len < 1 ) return in ; if ( header [ 0 ] != UTF_BOM [ 0 ] || header [ 1 ] != UTF_BOM [ 1 ] || header [ 2 ] != UTF_BOM [ 2 ] ) { pis . unread ( header , 0 , len ) ; } return pis ; } catch ( IOException e ) { throw Lang . wrapThrow ( e ) ; }


signature:
public class Streams { /** * 根据一个文件建立一个输出流
 * @ param file
 * 文件
 * @ return 输出流 */
public static OutputStream fileOut ( File file ) { } }

implementation: try { return buff ( new FileOutputStream ( file ) ) ; } catch ( FileNotFoundException e ) { throw Lang . wrapThrow ( e ) ; }


signature:
public class Streams { /** * 对一个文本输入流迭代每一行 , 并将其关闭
 * @ param r
 * 文本输入流
 * @ param callback
 * 回调
 * @ return 迭代的行数 */
public static int eachLine ( Reader r , Each < String > callback ) { } }

implementation: if ( null == callback || null == r ) return 0 ; BufferedReader br = null ; try { br = Streams . buffr ( r ) ; String line ; int index = 0 ; while ( null != ( line = br . readLine ( ) ) ) { try { callback . invoke ( index ++ , line , - 1 ) ; } catch ( ExitLoop e ) { break ; } catch ( ContinueLoop e ) { continue ; } } return index ; } catch ( IOException e2 ) { throw Lang . wrapThrow ( e2 ) ; } finally { Streams . safeClose ( br ) ; }


signature:
public class Streams { /** * 获取File对象输入流 , 即使在Jar文件中一样工作良好 ! ! < b > 强烈推荐 < / b > */
protected static InputStream _input ( File file ) throws IOException { } }

implementation: if ( file . exists ( ) ) return new FileInputStream ( file ) ; if ( Scans . isInJar ( file ) ) { NutResource nutResource = Scans . makeJarNutResource ( file ) ; if ( nutResource != null ) return nutResource . getInputStream ( ) ; } throw new FileNotFoundException ( file . toString ( ) ) ;


signature:
public class NutDaoExecutor { /** * 执行存储过程 , 简单实现 */
protected void _runExec ( Connection conn , DaoStatement st ) throws SQLException { } }

implementation:
if ( st . getContext ( ) . getPager ( ) != null ) { throw Lang . makeThrow ( DaoException . class , "NOT Pageable : " + st ) ; } // 打印调试信息
String sql = st . toPreparedStatement ( ) ; if ( log . isDebugEnabled ( ) ) log . debug ( sql ) ; Object [ ] [ ] paramMatrix = st . getParamMatrix ( ) ; CallableStatement stmt = null ; ResultSet rs = null ; try { stmt = conn . prepareCall ( sql ) ; ValueAdaptor [ ] adaptors = st . getAdaptors ( ) ; HashMap < Integer , OutParam > outParams = new HashMap < Integer , OutParam > ( ) ; if ( st instanceof Sql ) { VarIndex varIndex = ( ( Sql ) st ) . paramIndex ( ) ; VarSet varSet = ( ( Sql ) st ) . params ( ) ; for ( int i = 0 ; i < varIndex . size ( ) ; i ++ ) { String name = varIndex . getOrderName ( i ) ; if ( name . startsWith ( "OUT" ) && varSet . get ( name ) . getClass ( ) == Integer . class ) { Integer t = ( Integer ) varSet . get ( name ) ; outParams . put ( i , new OutParam ( name , t ) ) ; } } } // 创建语句并设置参数
if ( paramMatrix != null && paramMatrix . length > 0 ) { PreparedStatement pst = ( PreparedStatement ) stmt ; Object [ ] pm = paramMatrix [ 0 ] ; for ( int i = 0 ; i < pm . length ; i ++ ) { OutParam outParam = outParams . get ( i ) ; if ( outParam == null ) adaptors [ i ] . set ( pst , pm [ i ] , i + 1 ) ; else stmt . registerOutParameter ( i + 1 , outParam . jdbcType ) ; } } stmt . execute ( ) ; if ( outParams . size ( ) > 0 ) { Record r = Record . create ( ) ; for ( Entry < Integer , OutParam > en : outParams . entrySet ( ) ) { OutParam outParam = en . getValue ( ) ; int jdbcIndex = en . getKey ( ) + 1 ; Object value ; switch ( outParam . jdbcType ) { case Types . INTEGER : value = stmt . getInt ( jdbcIndex ) ; break ; case Types . TIMESTAMP : value = stmt . getTimestamp ( jdbcIndex ) ; break ; case Types . CLOB : value = stmt . getString ( jdbcIndex ) ; break ; case Types . DATE : value = stmt . getDate ( jdbcIndex ) ; break ; default : value = stmt . getObject ( jdbcIndex ) ; break ; } r . set ( outParam . name . substring ( 3 ) , value ) ; } st . getContext ( ) . attr ( "OUT" , r ) ; } // 先尝试读取第一个 , 并调用一次回调
rs = stmt . getResultSet ( ) ; try { st . onAfter ( conn , rs , null ) ; } finally { if ( rs != null ) rs . close ( ) ; } while ( true ) { if ( stmt . getMoreResults ( ) ) { rs = stmt . getResultSet ( ) ; try { if ( rs != null ) st . onAfter ( conn , rs , null ) ; } finally { if ( rs != null ) rs . close ( ) ; } } break ; } } finally { if ( stmt != null ) stmt . close ( ) ; }


signature:
public class Type { /** * Returns the Java type corresponding to the given internal name .
 * @ param internalName
 * an internal name .
 * @ return the Java type corresponding to the given internal name . */
public static Type getObjectType ( final String internalName ) { } }

implementation: char [ ] buf = internalName . toCharArray ( ) ; return new Type ( buf [ 0 ] == '[' ? ARRAY : OBJECT , buf , 0 , buf . length ) ;


signature:
public class Type { /** * Returns the Java types corresponding to the argument types of the given
 * method descriptor .
 * @ param methodDescriptor
 * a method descriptor .
 * @ return the Java types corresponding to the argument types of the given
 * method descriptor . */
public static Type [ ] getArgumentTypes ( final String methodDescriptor ) { } }

implementation: char [ ] buf = methodDescriptor . toCharArray ( ) ; int off = 1 ; int size = 0 ; while ( true ) { char car = buf [ off ++ ] ; if ( car == ')' ) { break ; } else if ( car == 'L' ) { while ( buf [ off ++ ] != ';' ) { } ++ size ; } else if ( car != '[' ) { ++ size ; } } Type [ ] args = new Type [ size ] ; off = 1 ; size = 0 ; while ( buf [ off ] != ')' ) { args [ size ] = getType ( buf , off ) ; off += args [ size ] . len + ( args [ size ] . sort == OBJECT ? 2 : 0 ) ; size += 1 ; } return args ;


signature:
public class Type { /** * Returns the Java type corresponding to the return type of the given
 * method descriptor .
 * @ param methodDescriptor
 * a method descriptor .
 * @ return the Java type corresponding to the return type of the given
 * method descriptor . */
public static Type getReturnType ( final String methodDescriptor ) { } }

implementation: char [ ] buf = methodDescriptor . toCharArray ( ) ; int off = 1 ; while ( true ) { char car = buf [ off ++ ] ; if ( car == ')' ) { return getType ( buf , off ) ; } else if ( car == 'L' ) { while ( buf [ off ++ ] != ';' ) { } } }


signature:
public class Type { /** * Computes the size of the arguments and of the return value of a method .
 * @ param desc
 * the descriptor of a method .
 * @ return the size of the arguments of the method ( plus one for the
 * implicit this argument ) , argSize , and the size of its return
 * value , retSize , packed into a single int i =
 * < tt > ( argSize & lt ; & lt ; 2 ) | retSize < / tt > ( argSize is therefore equal to
 * < tt > i & gt ; & gt ; 2 < / tt > , and retSize to < tt > i & amp ; 0x03 < / tt > ) . */
public static int getArgumentsAndReturnSizes ( final String desc ) { } }

implementation: int n = 1 ; int c = 1 ; while ( true ) { char car = desc . charAt ( c ++ ) ; if ( car == ')' ) { car = desc . charAt ( c ) ; return n << 2 | ( car == 'V' ? 0 : ( car == 'D' || car == 'J' ? 2 : 1 ) ) ; } else if ( car == 'L' ) { while ( desc . charAt ( c ++ ) != ';' ) { } n += 1 ; } else if ( car == '[' ) { while ( ( car = desc . charAt ( c ) ) == '[' ) { ++ c ; } if ( car == 'D' || car == 'J' ) { n -= 1 ; } } else if ( car == 'D' || car == 'J' ) { n += 2 ; } else { n += 1 ; } }


signature:
public class Type { /** * Returns the Java type corresponding to the given type descriptor . For
 * method descriptors , buf is supposed to contain nothing more than the
 * descriptor itself .
 * @ param buf
 * a buffer containing a type descriptor .
 * @ param off
 * the offset of this descriptor in the previous buffer .
 * @ return the Java type corresponding to the given type descriptor . */
private static Type getType ( final char [ ] buf , final int off ) { } }

implementation:
int len ; switch ( buf [ off ] ) { case 'V' : return VOID_TYPE ; case 'Z' : return BOOLEAN_TYPE ; case 'C' : return CHAR_TYPE ; case 'B' : return BYTE_TYPE ; case 'S' : return SHORT_TYPE ; case 'I' : return INT_TYPE ; case 'F' : return FLOAT_TYPE ; case 'J' : return LONG_TYPE ; case 'D' : return DOUBLE_TYPE ; case '[' : len = 1 ; while ( buf [ off + len ] == '[' ) { ++ len ; } if ( buf [ off + len ] == 'L' ) { ++ len ; while ( buf [ off + len ] != ';' ) { ++ len ; } } return new Type ( ARRAY , buf , off , len + 1 ) ; case 'L' : len = 1 ; while ( buf [ off + len ] != ';' ) { ++ len ; } return new Type ( OBJECT , buf , off + 1 , len - 1 ) ; // case ' ( ' :
default : return new Type ( METHOD , buf , off , buf . length - off ) ; }


signature:
public class Type { /** * Appends the descriptor corresponding to this Java type to the given
 * string buffer .
 * @ param buf
 * the string buffer to which the descriptor must be appended . */
private void getDescriptor ( final StringBuilder buf ) { } }

implementation:
if ( this . buf == null ) { // descriptor is in byte 3 of ' off ' for primitive types ( buf = =
// null )
buf . append ( ( char ) ( ( off & 0xFF000000 ) >>> 24 ) ) ; } else if ( sort == OBJECT ) { buf . append ( 'L' ) ; buf . append ( this . buf , off , len ) ; buf . append ( ';' ) ; } else { // sort = = ARRAY | | sort = = METHOD
buf . append ( this . buf , off , len ) ; }


signature:
public class Type { /** * Returns the descriptor corresponding to the given Java type .
 * @ param c
 * an object class , a primitive class or an array class .
 * @ return the descriptor corresponding to the given class . */
public static String getDescriptor ( final Class < ? > c ) { } }

implementation: StringBuilder buf = new StringBuilder ( ) ; getDescriptor ( buf , c ) ; return buf . toString ( ) ;


signature:
public class Type { /** * Returns a JVM instruction opcode adapted to this Java type . This method
 * must not be used for method types .
 * @ param opcode
 * a JVM instruction opcode . This opcode must be one of ILOAD ,
 * ISTORE , IALOAD , IASTORE , IADD , ISUB , IMUL , IDIV , IREM , INEG ,
 * ISHL , ISHR , IUSHR , IAND , IOR , IXOR and IRETURN .
 * @ return an opcode that is similar to the given opcode , but adapted to
 * this Java type . For example , if this type is < tt > float < / tt > and
 * < tt > opcode < / tt > is IRETURN , this method returns FRETURN . */
public int getOpcode ( final int opcode ) { } }

implementation:
if ( opcode == Opcodes . IALOAD || opcode == Opcodes . IASTORE ) { // the offset for IALOAD or IASTORE is in byte 1 of ' off ' for
// primitive types ( buf = = null )
return opcode + ( buf == null ? ( off & 0xFF00 ) >> 8 : 4 ) ; } else { // the offset for other instructions is in byte 2 of ' off ' for
// primitive types ( buf = = null )
return opcode + ( buf == null ? ( off & 0xFF0000 ) >> 16 : 4 ) ; }


signature:
public class Borns { /** * 根据参数类型数组获取一个对象的构建信息
 * @ param < T >
 * 对象类型信息
 * @ param type
 * 对象类型
 * @ param argTypes
 * 构造参数类型数组
 * @ return 构建信息对象 */
public static < T > BornContext < T > evalByArgTypes ( Class < T > type , Class < ? > ... argTypes ) { } }

implementation: BornContext < T > re ; if ( argTypes . length == 0 ) { re = evalWithoutArgs ( type ) ; } else { re = evalWithArgTypes ( true , type , argTypes , null ) ; } return re ;


signature:
public class Borns { /** * 根据参数类型数组获取一个对象的构建信息
 * @ param < T >
 * 对象类型信息
 * @ param type
 * 对象类型
 * @ param args
 * 构造参数数组
 * @ return 构建信息对象
 * @ throws NullPointerException
 * when args is null */
public static < T > BornContext < T > eval ( Class < T > type , Object ... args ) { } }

implementation: BornContext < T > re ; if ( args . length == 0 ) { re = evalWithoutArgs ( type ) ; } else { re = evalWithArgs ( type , args ) ; } return re ;


signature:
public class Borns { /** * 根据一个调用参数数组 , 获取一个对象的构建信息
 * @ param < T >
 * 对象类型信息
 * @ param type
 * 对象类型
 * @ param args
 * 参考构建参数
 * @ return 构建信息对象 */
private static < T > BornContext < T > evalWithArgs ( Class < T > type , Object [ ] args ) { } }

implementation:
// 准备变参数组
Object dynaArg = Mirror . evalArgToSameTypeRealArray ( args ) ; // 准备好参数类型
Class < ? > [ ] argTypes = Mirror . evalToTypes ( args ) ; BornContext < T > re = evalWithArgTypes ( false , type , argTypes , dynaArg ) ; if ( null == re ) return null ; if ( MatchType . LACK == re . getMatchType ( ) ) { re . setArgs ( Lang . arrayLast ( args , re . getLackArg ( ) ) ) ; } else { re . setArgs ( args ) ; } switch ( re . getMatchType ( ) ) { case LACK : re . setArgs ( Lang . arrayLast ( args , re . getLackArg ( ) ) ) ; break ; case NEED_CAST : re . setArgs ( Lang . array2ObjectArray ( args , re . getCastType ( ) ) ) ; break ; default : re . setArgs ( args ) ; } return re ;


signature:
public class Borns { /** * 根据一个调用参数类型数组 , 获取一个对象的构建信息
 * @ param < T >
 * 对象类型信息
 * @ param accurate
 * 是否需要精确匹配
 * @ param type
 * 对象类型
 * @ param argTypes
 * 参考参数类型数组
 * @ param dynaAry
 * 参考参数类型信息是否是一个变参数组
 * @ return 构建信息对象 */
@ SuppressWarnings ( { } }

implementation:
"rawtypes" , "unchecked" } ) private static < T > BornContext < T > evalWithArgTypes ( boolean accurate , Class < T > type , Class < ? > [ ] argTypes , Object dynaArg ) { // 准备好返回对象
BornContext < T > re = new BornContext < T > ( ) ; // 先看看有没对应的构造函数
Mirror < T > mirror = Mirror . me ( type ) ; for ( Constructor < ? > cc : type . getConstructors ( ) ) { Class < ? > [ ] pts = cc . getParameterTypes ( ) ; MatchType mt = Mirror . matchParamTypes ( pts , argTypes ) ; re . setMatchType ( mt ) ; // 正好合适
if ( MatchType . YES == mt ) { return re . setBorning ( new ConstructorBorning ( cc ) ) ; } // 差一个参数 , 说明这个构造函数有变参数组
else if ( MatchType . LACK == mt ) { re . setLackArg ( Mirror . blankArrayArg ( pts ) ) ; return re . setBorning ( new ConstructorBorning ( cc ) ) ; } // 看看整个输入的参数是不是变参
else if ( null != dynaArg && pts . length == 1 && pts [ 0 ] == dynaArg . getClass ( ) ) { return re . setBorning ( new DynamicConstructorBorning ( cc ) ) ; } } // 看看有没有对应静态工厂函数
Method [ ] sms = mirror . getStaticMethods ( ) ; for ( Method m : sms ) { Class < ? > [ ] pts = m . getParameterTypes ( ) ; MatchType mt = Mirror . matchParamTypes ( pts , argTypes ) ; re . setMatchType ( mt ) ; if ( MatchType . YES == mt ) { return re . setBorning ( new MethodBorning < T > ( m ) ) ; } else if ( MatchType . LACK == mt ) { re . setLackArg ( Mirror . blankArrayArg ( pts ) ) ; return re . setBorning ( new MethodBorning < T > ( m ) ) ; } else if ( null != dynaArg && pts . length == 1 ) { if ( pts [ 0 ] == dynaArg . getClass ( ) ) { return re . setBorning ( new DynaMethodBorning < T > ( m ) ) ; } } } // 如果不是要精确查找的话
if ( ! accurate ) { // 找到一个长度合适的构造函数 , 准备转换
try { for ( Constructor < ? > cc : type . getConstructors ( ) ) { Class < ? > [ ] pts = cc . getParameterTypes ( ) ; if ( canBeCasted ( argTypes , pts ) ) { re . setMatchType ( MatchType . NEED_CAST ) ; re . setCastType ( pts ) ; return re . setBorning ( new ConstructorCastingBorning ( cc ) ) ; } } } catch ( RuntimeException e ) { } // 有没有变参的静态构造方法
try { for ( Method m : sms ) { Class < ? > [ ] pts = m . getParameterTypes ( ) ; if ( canBeCasted ( argTypes , pts ) ) { re . setMatchType ( MatchType . NEED_CAST ) ; re . setCastType ( pts ) ; return re . setBorning ( new MethodCastingBorning < T > ( m ) ) ; } } } catch ( Exception e ) { } } return null ;


signature:
public class Borns { /** * 为一个给定类 , 寻找一个不需要参数的构造方法
 * @ param < T >
 * @ param type
 * 类实例
 * @ return 构造信息 */
@ SuppressWarnings ( { } }

implementation:
"rawtypes" , "unchecked" } ) private static < T > BornContext < T > evalWithoutArgs ( Class < T > type ) { // 准备好返回对象
BornContext < T > re = new BornContext < T > ( ) ; Mirror < T > mirror = Mirror . me ( type ) ; boolean isAbstract = Modifier . isAbstract ( type . getModifiers ( ) ) ; // 先看看有没有默认构造函数
try { if ( ! isAbstract ) { re . setBorning ( new EmptyArgsConstructorBorning < T > ( type . getConstructor ( ) ) ) ; return re . setArgs ( new Object [ 0 ] ) ; } } // 如果没有默认构造函数 . . .
catch ( Exception e ) { } // 看看有没有默认静态工厂函数
Method [ ] stMethods = mirror . getStaticMethods ( ) ; for ( Method m : stMethods ) { if ( m . getReturnType ( ) . equals ( type ) && m . getParameterTypes ( ) . length == 0 ) { return re . setBorning ( new EmptyArgsMethodBorning < T > ( m ) ) . setArgs ( new Object [ 0 ] ) ; } } // 看看有没有带一个动态参数的构造函数
if ( ! isAbstract ) { for ( Constructor < ? > cons : type . getConstructors ( ) ) { Class < ? > [ ] pts = cons . getParameterTypes ( ) ; if ( pts . length == 1 && pts [ 0 ] . isArray ( ) ) { Object [ ] args = new Object [ 1 ] ; args [ 0 ] = Mirror . blankArrayArg ( pts ) ; return re . setBorning ( new ConstructorBorning ( cons ) ) . setArgs ( args ) ; } } } // 看看有没有带一个动态参数的静态工厂函数
for ( Method m : stMethods ) { Class < ? > [ ] pts = m . getParameterTypes ( ) ; if ( m . getReturnType ( ) == type && m . getParameterTypes ( ) . length == 1 && pts [ 0 ] . isArray ( ) ) { Object [ ] args = new Object [ 1 ] ; args [ 0 ] = Mirror . blankArrayArg ( pts ) ; return re . setBorning ( new MethodBorning < T > ( m ) ) . setArgs ( args ) ; } } return null ;


signature:
public class Sqls { /** * 改变 Sql 接口的实现类 , 如果你调用了这个方法 , 以后你再调用本类其他帮助函数创建的 SQL 就是你提供的这个实现类
 * 默认的 , 将用 org . nutz . dao . sql . impl . sql . NutSql 作为实现类
 * 你给出的 Sql 实现类必须有一个可访问的构造函数 , 接受一个字符串型参数
 * @ param type
 * 你的 Sql 接口实现类 */
public static < T extends Sql > void setSqlBorning ( Class < T > type ) { } }

implementation: sqlBorning = Mirror . me ( type ) . getBorningByArgTypes ( String . class ) ;


signature:
public class Sqls { /** * 创建了一个 Sql 对象 。
 * 传入的 Sql 语句支持变量和参数占位符 :
 * < ul >
 * < li > 变量 : 格式为 < b > $ XXXX < / b > , 在执行前 , 会被预先替换
 * < li > 参数 : 格式为 < b > @ XXXX < / b > , 在执行前 , 会替换为 ' ? ' , 用以构建 PreparedStatement
 * < / ul >
 * @ param fmt
 * 格式字符 , 格式参看 String . format 函数
 * @ param args
 * 格式字符串的参数
 * @ return Sql 对象 */
public static Sql createf ( String fmt , Object ... args ) { } }

implementation: return create ( String . format ( fmt , args ) ) ;


signature:
public class Sqls { /** * 格式化值 , 根据值的类型 , 生成 SQL 字段值的部分 , 它会考虑 SQL 注入
 * @ param v
 * 字段值
 * @ return 格式化后的 Sql 字段值 , 可以直接拼装在 SQL 里面 */
public static CharSequence formatFieldValue ( Object v ) { } }

implementation: if ( null == v ) return "NULL" ; else if ( Sqls . isNotNeedQuote ( v . getClass ( ) ) ) return Sqls . escapeFieldValue ( v . toString ( ) ) ; else return new StringBuilder ( "'" ) . append ( Sqls . escapeFieldValue ( Castors . me ( ) . castToString ( v ) ) ) . append ( '\'' ) ;


signature:
public class Sqls { /** * 格式化值 , 根据值的类型 , 生成 SQL 字段值的部分 , 它会考虑 SQL 注入 , 以及 SQL 的 ' $ ' 和 ' @ ' 转义
 * @ param v
 * 字段值
 * @ return 格式化后的 Sql 字段值 , 可以直接拼装在 SQL 里面 */
public static CharSequence formatSqlFieldValue ( Object v ) { } }

implementation: if ( null == v ) return "NULL" ; else if ( Sqls . isNotNeedQuote ( v . getClass ( ) ) ) return Sqls . escapeSqlFieldValue ( v . toString ( ) ) ; else return new StringBuilder ( "'" ) . append ( Sqls . escapeSqlFieldValue ( v . toString ( ) ) ) . append ( '\'' ) ;


signature:
public class Sqls { /** * 将 SQL 的字段值进行转意 , 可以用来防止 SQL 注入攻击
 * @ param s
 * 字段值
 * @ return 格式化后的 Sql 字段值 , 可以直接拼装在 SQL 里面 */
public static CharSequence escapeFieldValue ( CharSequence s ) { } }

implementation: if ( null == s ) return null ; return ES_FLD_VAL . escape ( s ) ;


signature:
public class Sqls { /** * 将 SQL 的字段值进行转意 , 可以用来防止 SQL 注入攻击 , < br >
 * 同时 , 它也会将 Sql 的特殊标记 ' $ ' 和 ' @ ' 进行转译
 * @ param s
 * 字段值
 * @ return 格式化后的 Sql 字段值 , 可以直接拼装在 SQL 里面 */
public static CharSequence escapeSqlFieldValue ( CharSequence s ) { } }

implementation: if ( null == s ) return null ; return ES_SQL_FLD . escape ( s ) ;


signature:
public class Sqls { /** * 将 SQL 的 WHERE 条件值进行转意 , 可以用来防止 SQL 注入攻击
 * @ param s
 * 字段值
 * @ return 格式化后的 Sql 字段值 , 可以直接拼装在 SQL 里面 */
public static CharSequence escapteConditionValue ( CharSequence s ) { } }

implementation: if ( null == s ) return null ; return ES_CND_VAL . escape ( s ) ;


signature:
public class Sqls { /** * 判断一个值 , 在 SQL 中是否需要单引号
 * @ param type
 * 类型
 * @ return 是否需要加上单引号 */
public static boolean isNotNeedQuote ( Class < ? > type ) { } }

implementation: Mirror < ? > me = Mirror . me ( type ) ; return me . isBoolean ( ) || me . isPrimitiveNumber ( ) ;


signature:
public class ByteVector { /** * Puts a byte into this byte vector . The byte vector is automatically
 * enlarged if necessary .
 * @ param b
 * a byte .
 * @ return this byte vector . */
public ByteVector putByte ( final int b ) { } }

implementation: int length = this . length ; if ( length + 1 > data . length ) { enlarge ( 1 ) ; } data [ length ++ ] = ( byte ) b ; this . length = length ; return this ;


signature:
public class ByteVector { /** * Puts two bytes into this byte vector . The byte vector is automatically
 * enlarged if necessary .
 * @ param b1
 * a byte .
 * @ param b2
 * another byte .
 * @ return this byte vector . */
ByteVector put11 ( final int b1 , final int b2 ) { } }

implementation: int length = this . length ; if ( length + 2 > data . length ) { enlarge ( 2 ) ; } byte [ ] data = this . data ; data [ length ++ ] = ( byte ) b1 ; data [ length ++ ] = ( byte ) b2 ; this . length = length ; return this ;


signature:
public class ByteVector { /** * Puts a short into this byte vector . The byte vector is automatically
 * enlarged if necessary .
 * @ param s
 * a short .
 * @ return this byte vector . */
public ByteVector putShort ( final int s ) { } }

implementation: int length = this . length ; if ( length + 2 > data . length ) { enlarge ( 2 ) ; } byte [ ] data = this . data ; data [ length ++ ] = ( byte ) ( s >>> 8 ) ; data [ length ++ ] = ( byte ) s ; this . length = length ; return this ;


signature:
public class ByteVector { /** * Puts a byte and a short into this byte vector . The byte vector is
 * automatically enlarged if necessary .
 * @ param b
 * a byte .
 * @ param s
 * a short .
 * @ return this byte vector . */
ByteVector put12 ( final int b , final int s ) { } }

implementation: int length = this . length ; if ( length + 3 > data . length ) { enlarge ( 3 ) ; } byte [ ] data = this . data ; data [ length ++ ] = ( byte ) b ; data [ length ++ ] = ( byte ) ( s >>> 8 ) ; data [ length ++ ] = ( byte ) s ; this . length = length ; return this ;


signature:
public class ByteVector { /** * Puts an int into this byte vector . The byte vector is automatically
 * enlarged if necessary .
 * @ param i
 * an int .
 * @ return this byte vector . */
public ByteVector putInt ( final int i ) { } }

implementation: int length = this . length ; if ( length + 4 > data . length ) { enlarge ( 4 ) ; } byte [ ] data = this . data ; data [ length ++ ] = ( byte ) ( i >>> 24 ) ; data [ length ++ ] = ( byte ) ( i >>> 16 ) ; data [ length ++ ] = ( byte ) ( i >>> 8 ) ; data [ length ++ ] = ( byte ) i ; this . length = length ; return this ;


signature:
public class ByteVector { /** * Puts a long into this byte vector . The byte vector is automatically
 * enlarged if necessary .
 * @ param l
 * a long .
 * @ return this byte vector . */
public ByteVector putLong ( final long l ) { } }

implementation: int length = this . length ; if ( length + 8 > data . length ) { enlarge ( 8 ) ; } byte [ ] data = this . data ; int i = ( int ) ( l >>> 32 ) ; data [ length ++ ] = ( byte ) ( i >>> 24 ) ; data [ length ++ ] = ( byte ) ( i >>> 16 ) ; data [ length ++ ] = ( byte ) ( i >>> 8 ) ; data [ length ++ ] = ( byte ) i ; i = ( int ) l ; data [ length ++ ] = ( byte ) ( i >>> 24 ) ; data [ length ++ ] = ( byte ) ( i >>> 16 ) ; data [ length ++ ] = ( byte ) ( i >>> 8 ) ; data [ length ++ ] = ( byte ) i ; this . length = length ; return this ;


signature:
public class ByteVector { /** * Puts an UTF8 string into this byte vector . The byte vector is
 * automatically enlarged if necessary .
 * @ param s
 * a String whose UTF8 encoded length must be less than 65536.
 * @ return this byte vector . */
public ByteVector putUTF8 ( final String s ) { } }

implementation:
int charLength = s . length ( ) ; if ( charLength > 65535 ) { throw new IllegalArgumentException ( ) ; } int len = length ; if ( len + 2 + charLength > data . length ) { enlarge ( 2 + charLength ) ; } byte [ ] data = this . data ; // optimistic algorithm : instead of computing the byte length and then
// serializing the string ( which requires two loops ) , we assume the byte
// length is equal to char length ( which is the most frequent case ) , and
// we start serializing the string right away . During the serialization ,
// if we find that this assumption is wrong , we continue with the
// general method .
data [ len ++ ] = ( byte ) ( charLength >>> 8 ) ; data [ len ++ ] = ( byte ) charLength ; for ( int i = 0 ; i < charLength ; ++ i ) { char c = s . charAt ( i ) ; if ( c >= '\001' && c <= '\177' ) { data [ len ++ ] = ( byte ) c ; } else { length = len ; return encodeUTF8 ( s , i , 65535 ) ; } } length = len ; return this ;


signature:
public class ByteVector { /** * Puts an UTF8 string into this byte vector . The byte vector is
 * automatically enlarged if necessary . The string length is encoded in two
 * bytes before the encoded characters , if there is space for that ( i . e . if
 * this . length - i - 2 > = 0 ) .
 * @ param s
 * the String to encode .
 * @ param i
 * the index of the first character to encode . The previous
 * characters are supposed to have already been encoded , using
 * only one byte per character .
 * @ param maxByteLength
 * the maximum byte length of the encoded string , including the
 * already encoded characters .
 * @ return this byte vector . */
ByteVector encodeUTF8 ( final String s , int i , int maxByteLength ) { } }

implementation: int charLength = s . length ( ) ; int byteLength = i ; char c ; for ( int j = i ; j < charLength ; ++ j ) { c = s . charAt ( j ) ; if ( c >= '\001' && c <= '\177' ) { byteLength ++ ; } else if ( c > '\u07FF' ) { byteLength += 3 ; } else { byteLength += 2 ; } } if ( byteLength > maxByteLength ) { throw new IllegalArgumentException ( ) ; } int start = length - i - 2 ; if ( start >= 0 ) { data [ start ] = ( byte ) ( byteLength >>> 8 ) ; data [ start + 1 ] = ( byte ) byteLength ; } if ( length + byteLength - i > data . length ) { enlarge ( byteLength - i ) ; } int len = length ; for ( int j = i ; j < charLength ; ++ j ) { c = s . charAt ( j ) ; if ( c >= '\001' && c <= '\177' ) { data [ len ++ ] = ( byte ) c ; } else if ( c > '\u07FF' ) { data [ len ++ ] = ( byte ) ( 0xE0 | c >> 12 & 0xF ) ; data [ len ++ ] = ( byte ) ( 0x80 | c >> 6 & 0x3F ) ; data [ len ++ ] = ( byte ) ( 0x80 | c & 0x3F ) ; } else { data [ len ++ ] = ( byte ) ( 0xC0 | c >> 6 & 0x1F ) ; data [ len ++ ] = ( byte ) ( 0x80 | c & 0x3F ) ; } } length = len ; return this ;


signature:
public class ByteVector { /** * Puts an array of bytes into this byte vector . The byte vector is
 * automatically enlarged if necessary .
 * @ param b
 * an array of bytes . May be < tt > null < / tt > to put < tt > len < / tt >
 * null bytes into this byte vector .
 * @ param off
 * index of the fist byte of b that must be copied .
 * @ param len
 * number of bytes of b that must be copied .
 * @ return this byte vector . */
public ByteVector putByteArray ( final byte [ ] b , final int off , final int len ) { } }

implementation: if ( length + len > data . length ) { enlarge ( len ) ; } if ( b != null ) { System . arraycopy ( b , off , data , length , len ) ; } length += len ; return this ;


signature:
public class ByteVector { /** * Enlarge this byte vector so that it can receive n more bytes .
 * @ param size
 * number of additional bytes that this byte vector should be
 * able to receive . */
private void enlarge ( final int size ) { } }

implementation: int length1 = 2 * data . length ; int length2 = length + size ; byte [ ] newData = new byte [ length1 > length2 ? length1 : length2 ] ; System . arraycopy ( data , 0 , newData , 0 , length ) ; data = newData ;


signature:
public class NutTransaction { /** * 提交事务 */
protected void commit ( ) { } }

implementation:
ComboException ce = new ComboException ( ) ; for ( ConnInfo cInfo : list ) { try { // 提交事务
cInfo . conn . commit ( ) ; // 恢复旧的事务级别
if ( cInfo . conn . getTransactionIsolation ( ) != cInfo . oldLevel ) cInfo . conn . setTransactionIsolation ( cInfo . oldLevel ) ; } catch ( SQLException e ) { ce . add ( e ) ; } } // 如果有一个数据源提交时发生异常 , 抛出
if ( null != ce . getCause ( ) ) { throw ce ; }


signature:
public class NutTransaction { /** * 从数据源获取连接 */
@ Override public Connection getConnection ( DataSource dataSource ) throws SQLException { } }

implementation:
for ( ConnInfo p : list ) if ( p . ds == dataSource ) return p . conn ; Connection conn = dataSource . getConnection ( ) ; // System . out . printf ( " = > % s \ n " , conn . toString ( ) ) ;
boolean restoreAutoCommit = false ; if ( conn . getAutoCommit ( ) ) { conn . setAutoCommit ( false ) ; restoreAutoCommit = true ; } // Store conn , it will set the trans level
list . add ( new ConnInfo ( dataSource , conn , getLevel ( ) , restoreAutoCommit ) ) ; return conn ;


signature:
public class NutTransaction { /** * 关闭事务 , 清理现场 */
@ Override public void close ( ) { } }

implementation:
ComboException ce = new ComboException ( ) ; for ( ConnInfo cInfo : list ) { try { // 试图恢复旧的事务级别
if ( ! cInfo . conn . isClosed ( ) ) { if ( cInfo . restoreIsoLevel ) cInfo . conn . setTransactionIsolation ( cInfo . oldLevel ) ; if ( cInfo . restoreAutoCommit ) cInfo . conn . setAutoCommit ( true ) ; } } catch ( Throwable e ) { } finally { try { cInfo . conn . close ( ) ; } catch ( Exception e ) { ce . add ( e ) ; } } } // 清除数据源记录
list . clear ( ) ;


signature:
public class NutTransaction { /** * 执行回滚操作 */
@ Override protected void rollback ( ) { } }

implementation: for ( ConnInfo cInfo : list ) { try { cInfo . conn . rollback ( ) ; } catch ( Throwable e ) { } }


signature:
public class NutRunner { /** * 主逻辑 , 用户代码不应该覆盖 . */
public void run ( ) { } }

implementation: if ( log == null ) { log = Logs . get ( ) . setTag ( rnm ) ; } myThread = Thread . currentThread ( ) ; beforeStart ( this ) ; doIt ( ) ; afterStop ( this ) ;


signature:
public class NutRunner { /** * 做一些需要定期执行的操作 */
protected void doIt ( ) { } }

implementation:
while ( ! lock . isStop ( ) ) { synchronized ( lock ) { try { // 修改一下本线程的时间
upAt = Times . now ( ) ; downAt = null ; if ( debug && log . isDebugEnabled ( ) ) log . debugf ( "%s [%d] : up" , rnm , ++ count ) ; // 执行业务
interval = exec ( ) ; if ( interval < 1 ) interval = 1 ; // 不能间隔0或者负数 , 会死线程的
// 等待一个周期
downAt = Times . now ( ) ; if ( debug && log . isDebugEnabled ( ) ) log . debugf ( "%s [%d] : wait %ds(%dms)" , rnm , count , interval / 1000 , interval ) ; lock . wait ( interval ) ; } catch ( InterruptedException e ) { log . warn ( String . format ( "%s has been interrupted" , rnm ) , e ) ; break ; } catch ( Throwable e ) { log . warn ( String . format ( "%s has some error" , rnm ) , e ) ; try { lock . wait ( sleepAfterError * 1000 ) ; } catch ( Throwable e1 ) { log . warn ( String . format ( "%s has some error again" , rnm ) , e ) ; break ; } } } }


signature:
public class SqlTemplate { /** * 执行一个SQL更新操作 ( 如插入 , 更新或删除语句 ) 。
 * @ param sql
 * 包含变量占位符的SQL
 * @ param params
 * 参数map , 无参数时 , 可为null
 * @ return SQL 语句所影响的行数 */
public int update ( String sql , Map < String , Object > params ) { } }

implementation: return update ( sql , null , params ) ;


signature:
public class SqlTemplate { /** * 执行一个SQL更新操作 ( 如插入 , 更新或删除语句 ) 。
 * @ param sql
 * 包含变量占位符的SQL
 * @ param vars
 * 变量map , 无参数时 , 可为null
 * @ param params
 * 参数map , 无参数时 , 可为null
 * @ return SQL 语句所影响的行数 */
public int update ( String sql , Map < String , Object > vars , Map < String , Object > params ) { } }

implementation: Sql sqlObj = createSqlObj ( sql , params ) ; execute ( sqlObj , vars , params ) ; return sqlObj . getUpdateCount ( ) ;


signature:
public class SqlTemplate { /** * 执行SQL批量更新操作 ( 如插入 , 更新或删除语句 ) 。
 * @ param sql
 * 包含变量占位符的SQL
 * @ param batchValues
 * 批量更新参数集合
 * @ return SQL 语句所影响的行数 */
public int batchUpdate ( String sql , List < Map < String , Object > > batchValues ) { } }

implementation: return batchUpdate ( sql , null , batchValues ) ;


signature:
public class SqlTemplate { /** * 执行SQL批量更新操作 ( 如插入 , 更新或删除语句 ) 。
 * @ param sql
 * 包含变量占位符的SQL
 * @ param vars
 * 变量map , 无参数时 , 可为null
 * @ param batchValues
 * 批量更新参数集合
 * @ return SQL 语句所影响的行数 */
public int batchUpdate ( String sql , Map < String , Object > vars , List < Map < String , Object > > batchValues ) { } }

implementation: Sql sqlObj = null ; if ( batchValues != null && batchValues . size ( ) > 0 ) { sqlObj = createSqlObj ( sql , batchValues . get ( 0 ) ) ; for ( Map < String , Object > params : batchValues ) { Map < String , Object > newParams = paramProcess ( params ) ; sqlObj . params ( ) . putAll ( newParams ) ; sqlObj . addBatch ( ) ; } dao . execute ( sqlObj ) ; } else { sqlObj = createSqlObj ( sql , null ) ; execute ( sqlObj , vars , null ) ; } return sqlObj . getUpdateCount ( ) ;


signature:
public class SqlTemplate { /** * 执行一个SQL查询操作 , 结果为一个int形数值 。
 * @ param sql
 * 包含变量占位符的SQL
 * @ param params
 * 参数map , 无参数时 , 可为null
 * @ return int数值 , 当查询为null时返回0 */
public int queryForInt ( String sql , Map < String , Object > params ) { } }

implementation: return queryForInt ( sql , null , params ) ;


signature:
public class SqlTemplate { /** * 执行一个SQL查询操作 , 结果为一个int形数值 。
 * @ param sql
 * 包含变量占位符的SQL
 * @ param vars
 * 变量map , 无参数时 , 可为null
 * @ param params
 * 参数map , 无参数时 , 可为null
 * @ return int数值 , 当查询为null时返回0 */
public int queryForInt ( String sql , Map < String , Object > vars , Map < String , Object > params ) { } }

implementation: Sql sqlObj = createSqlObj ( sql , params ) ; sqlObj . setCallback ( Sqls . callback . integer ( ) ) ; execute ( sqlObj , vars , params ) ; return sqlObj . getInt ( ) ;


signature:
public class SqlTemplate { /** * 执行一个SQL查询操作 , 结果为一个long形数值 。
 * @ param sql
 * 包含变量占位符的SQL
 * @ param params
 * 参数map , 无参数时 , 可为null
 * @ return long数值 , 当查询为null时返回0 */
public long queryForLong ( String sql , Map < String , Object > params ) { } }

implementation: return queryForLong ( sql , null , params ) ;


signature:
public class SqlTemplate { /** * 执行一个SQL查询操作 , 结果为一个long形数值 。
 * @ param sql
 * 包含变量占位符的SQL
 * @ param vars
 * 变量map , 无参数时 , 可为null
 * @ param params
 * 参数map , 无参数时 , 可为null
 * @ return long数值 , 当查询为null时返回0 */
public long queryForLong ( String sql , Map < String , Object > vars , Map < String , Object > params ) { } }

implementation: Sql sqlObj = createSqlObj ( sql , params ) ; sqlObj . setCallback ( Sqls . callback . longValue ( ) ) ; execute ( sqlObj , vars , params ) ; Long result = sqlObj . getObject ( Long . class ) ; return result == null ? 0 : result ;


signature:
public class SqlTemplate { /** * 执行一个SQL查询操作 , 结果为给定对象类型的对象 , 适用于明确SQL查询结果的类型 。
 * @ param sql
 * 包含变量占位符的SQL
 * @ param params
 * 参数map 无参数时 , 可为null
 * @ param classOfT
 * 对象类型 , SQL查询结果所对应的类型 , 如Date . class等
 * @ return 对象 , 无查询结果时返回null */
public < T > T queryForObject ( String sql , Map < String , Object > params , Class < T > classOfT ) { } }

implementation: return queryForObject ( sql , null , params , classOfT ) ;


signature:
public class SqlTemplate { /** * 执行一个SQL查询操作 , 结果为给定对象类型的对象 , 适用于明确SQL查询结果的类型 。
 * @ param sql
 * 包含变量占位符的SQL
 * @ param vars
 * 变量map , 无参数时 , 可为null
 * @ param params
 * 参数map , 无参数时 , 可为null
 * @ param classOfT
 * 对象类型 , SQL查询结果所对应的类型 , 如Date . class等
 * @ return 对象 , 无查询结果时返回null */
public < T > T queryForObject ( String sql , Map < String , Object > vars , Map < String , Object > params , Class < T > classOfT ) { } }

implementation: Sql sqlObj = createSqlObj ( sql , params ) ; sqlObj . setCallback ( new SqlCallback ( ) { public Object invoke ( Connection conn , ResultSet rs , Sql sql ) throws SQLException { if ( null != rs && rs . next ( ) ) return rs . getObject ( 1 ) ; return null ; } } ) ; execute ( sqlObj , vars , params ) ; return sqlObj . getObject ( classOfT ) ;


signature:
public class SqlTemplate { /** * 执行一个SQL查询操作 , 结果为给定实体的对象 。
 * @ param sql
 * 包含变量占位符的SQL
 * @ param params
 * 参数map , 无参数时 , 可为null
 * @ param entity
 * 实体类型 , 无参数时 , 可为null
 * @ return 对象 , 无查询结果时返回null */
public < T > T queryForObject ( String sql , Map < String , Object > params , Entity < T > entity ) { } }

implementation: return queryForObject ( sql , null , params , entity ) ;


signature:
public class SqlTemplate { /** * 执行一个SQL查询操作 , 结果为给定实体的对象 。
 * @ param sql
 * 包含变量占位符的SQL
 * @ param vars
 * 变量map , 无参数时 , 可为null
 * @ param params
 * 参数map , 无参数时 , 可为null
 * @ param entity
 * 实体类型
 * @ return 对象 , 无查询结果时返回null */
public < T > T queryForObject ( String sql , Map < String , Object > vars , Map < String , Object > params , Entity < T > entity ) { } }

implementation: Sql sqlObj = createSqlObj ( sql , params ) ; sqlObj . setCallback ( Sqls . callback . entity ( ) ) ; sqlObj . setEntity ( entity ) ; execute ( sqlObj , vars , params ) ; return sqlObj . getObject ( entity . getType ( ) ) ;


signature:
public class SqlTemplate { /** * 执行一个SQL查询操作 , 结果为Record的对象 。
 * @ param sql
 * 包含变量占位符的SQL
 * @ param params
 * 参数map , 无参数时 , 可为null
 * @ return Record对象 , 无查询结果时返回null */
public Record queryForRecord ( String sql , Map < String , Object > params ) { } }

implementation: return queryForRecord ( sql , null , params ) ;


signature:
public class SqlTemplate { /** * 执行一个SQL查询操作 , 结果为Record的对象 。
 * @ param sql
 * 包含变量占位符的SQL
 * @ param vars
 * 变量map , 无参数时 , 可为null
 * @ param params
 * 参数map , 无参数时 , 可为null
 * @ return Record对象 , 无查询结果时返回null */
public Record queryForRecord ( String sql , Map < String , Object > vars , Map < String , Object > params ) { } }

implementation: Sql sqlObj = createSqlObj ( sql , params ) ; sqlObj . setCallback ( Sqls . callback . record ( ) ) ; execute ( sqlObj , vars , params ) ; return sqlObj . getObject ( Record . class ) ;


signature:
public class SqlTemplate { /** * 执行一个SQL查询操作 , 结果为一组对象 。
 * @ param sql
 * 包含变量占位符的SQL
 * @ param params
 * 参数map , 无参数时 , 可为null
 * @ param entity
 * 对象类型 , 无参数时 , 可为null
 * @ return 对象列表 , 无查询结果时返回长度为0的List对象 */
public < T > List < T > query ( String sql , Map < String , Object > params , Entity < T > entity ) { } }

implementation: return query ( sql , null , params , entity ) ;


signature:
public class SqlTemplate { /** * 执行一个SQL查询操作 , 结果为一组对象 。
 * @ param sql
 * 包含变量占位符的SQL
 * @ param params
 * 参数map , 无参数时 , 可为null
 * @ param classOfT
 * 对象类类
 * @ return 对象列表 , 无查询结果时返回长度为0的List对象 */
public < T > List < T > query ( String sql , Map < String , Object > params , Class < T > classOfT ) { } }

implementation: return query ( sql , null , params , dao . getEntity ( classOfT ) ) ;