signature:
public class Cnd { /** * Cnd . where ( . . . ) . or ( " age " , " < " , 40)
 * @ param name Java属性或字段名称 , 推荐用Java属性 , 如果有的话
 * @ param op 操作符 , 可以是 = like等
 * @ param value 参数值 , 如果是between的话需要传入new Object [ ] { 19,28}
 * @ return 当前对象 , 用于链式调用 */
public Cnd or ( String name , String op , Object value ) { } }

implementation: return or ( Cnd . exp ( name , op , value ) ) ;


signature:
public class Cnd { /** * and一个条件表达式并且取非
 * @ param exp 条件表达式
 * @ return 当前对象 , 用于链式调用 */
public Cnd andNot ( SqlExpression exp ) { } }

implementation: cri . where ( ) . and ( exp . setNot ( true ) ) ; return this ;


signature:
public class Cnd { /** * and一个条件 , 并且取非
 * @ param name Java属性或字段名称 , 推荐用Java属性 , 如果有的话
 * @ param op 操作符 , 可以是 = like等
 * @ param value 参数值 , 如果是between的话需要传入new Object [ ] { 19,28}
 * @ return 当前对象 , 用于链式调用 */
public Cnd andNot ( String name , String op , Object value ) { } }

implementation: return andNot ( Cnd . exp ( name , op , value ) ) ;


signature:
public class Cnd { /** * 用默认规则 ( 忽略零值和空值 ) 生成Cnd实例
 * @ param dao Dao实例 , 不能为null
 * @ param obj 对象 , 若为null , 则返回值为null , 不可以是Class / 字符串 / 数值 / 布尔类型
 * @ return Cnd实例 */
public static Cnd from ( Dao dao , Object obj ) { } }

implementation: return from ( dao , obj , dftFromFieldMatcher ) ;


signature:
public class Cnd { /** * 根据一个对象生成Cnd条件 , FieldMatcher详细控制 . < p / >
 * < code > assertEquals ( " WHERE name = ' wendal ' AND age = 0 " , Cnd . from ( dao , pet , FieldMatcher . make ( " age | name " , null , true ) . setIgnoreDate ( true ) ) . toString ( ) ) ; < / code >
 * @ param dao Dao实例
 * @ param obj 基对象 , 不可以是Class , 字符串 , 数值和Boolean
 * @ param matcher 过滤字段属性 , 可配置哪些字段可用 / 不可用 / 是否忽略空值 / 是否忽略0值 / 是否忽略java . util . Date类及其子类的对象 / 是否忽略 @ Id所标注的主键属性 / 是否忽略 \ @ Name 所标注的主键属性 / 是否忽略 \ @ Pk 所引用的复合主键
 * @ return Cnd条件 */
public static Cnd from ( Dao dao , Object obj , FieldMatcher matcher ) { } }

implementation: final SqlExpressionGroup exps = new SqlExpressionGroup ( ) ; boolean re = Daos . filterFields ( obj , matcher , dao , new Callback2 < MappingField , Object > ( ) { public void invoke ( MappingField mf , Object val ) { exps . and ( mf . getName ( ) , "=" , val ) ; } } ) ; if ( re ) return Cnd . where ( exps ) ; return null ;


signature:
public class Cnd { /** * 若value为null / 空白字符串 / 空集合 / 空数组 , 则本条件不添加 .
 * @ see Cnd # and ( String , String , Object ) */
public Cnd andEX ( String name , String op , Object value ) { } }

implementation: return and ( Cnd . expEX ( name , op , value ) ) ;


signature:
public class Cnd { /** * 若value为null / 空白字符串 / 空集合 / 空数组 , 则本条件不添加 .
 * @ see Cnd # or ( String , String , Object ) */
public Cnd orEX ( String name , String op , Object value ) { } }

implementation: return or ( Cnd . expEX ( name , op , value ) ) ;


signature:
public class Colors { /** * 将字符串变成颜色值
 * @ param str
 * 颜色字符串 , 详细 , 请参看本类的总体描述 , 如果为空 , 则表示黑色
 * @ return 颜色对象 */
public static Color as ( String str ) { } }

implementation:
if ( null == str ) return Color . BLACK ; // 整理一下字符串以便后面匹配分析
str = Strings . trim ( str . toUpperCase ( ) ) ; if ( str . startsWith ( "#" ) ) { str = str . substring ( 1 ) ; } if ( str . endsWith ( ";" ) ) str = str . substring ( 0 , str . length ( ) - 1 ) ; // RGB : # FFF
Pattern p = Pattern . compile ( "^([0-9A-F])([0-9A-F])([0-9A-F])$" ) ; Matcher m = p . matcher ( str ) ; if ( m . find ( ) ) { return new Color ( parseInt ( dup ( m . group ( 1 ) , 2 ) , 16 ) , parseInt ( dup ( m . group ( 2 ) , 2 ) , 16 ) , parseInt ( dup ( m . group ( 3 ) , 2 ) , 16 ) ) ; } // RRGGBB : # F0F0F0
p = Pattern . compile ( "^([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$" ) ; m = p . matcher ( str ) ; if ( m . find ( ) ) { return new Color ( parseInt ( m . group ( 1 ) , 16 ) , parseInt ( m . group ( 2 ) , 16 ) , parseInt ( m . group ( 3 ) , 16 ) ) ; } // ARGB : # 9FE5
p = Pattern . compile ( "^([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])$" ) ; m = p . matcher ( str ) ; if ( m . find ( ) ) { return new Color ( parseInt ( dup ( m . group ( 2 ) , 2 ) , 16 ) , parseInt ( dup ( m . group ( 3 ) , 2 ) , 16 ) , parseInt ( dup ( m . group ( 4 ) , 2 ) , 16 ) , parseInt ( dup ( m . group ( 1 ) , 2 ) , 16 ) ) ; } // AARRGGBB : # 88FF8899
p = Pattern . compile ( "^([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$" ) ; m = p . matcher ( str ) ; if ( m . find ( ) ) { return new Color ( parseInt ( m . group ( 2 ) , 16 ) , parseInt ( m . group ( 3 ) , 16 ) , parseInt ( m . group ( 4 ) , 16 ) , parseInt ( m . group ( 1 ) , 16 ) ) ; } // RGB值 : rgb ( 255,33,89)
p = Pattern . compile ( "^RGB\\s*[(]\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*[)]$" ) ; m = p . matcher ( str ) ; if ( m . find ( ) ) { return new Color ( parseInt ( m . group ( 1 ) , 10 ) , parseInt ( m . group ( 2 ) , 10 ) , parseInt ( m . group ( 3 ) , 10 ) ) ; } // / / RGBA值 : rgba ( 6,6,6,255)
// Pattern . compile ( " ^ RGBA \ \ s * [ ( ] \ \ s * ( \ \ d + ) \ \ s * , \ \ s * ( \ \ d + ) \ \ s * , \ \ s * ( \ \ d + ) \ \ s * , \ \ s * ( \ \ d + ) \ \ s * [ ) ] $ " ) ;
// m = p . matcher ( str ) ;
// if ( m . find ( ) ) {
// return new Color ( parseInt ( m . group ( 1 ) , 10 ) ,
// parseInt ( m . group ( 2 ) , 10 ) ,
// parseInt ( m . group ( 3 ) , 10 ) ,
// parseInt ( m . group ( 4 ) , 10 ) ) ;
// RGBA值 : rgba ( 6,6,6,0.9)
p = Pattern . compile ( "^RGBA\\s*[(]\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*((\\d[.])?\\d+)\\s*[)]$" ) ; m = p . matcher ( str ) ; if ( m . find ( ) ) { float alpha = Float . parseFloat ( m . group ( 4 ) ) ; return new Color ( parseInt ( m . group ( 1 ) , 10 ) , parseInt ( m . group ( 2 ) , 10 ) , parseInt ( m . group ( 3 ) , 10 ) , ( int ) ( 255.0f * alpha ) ) ; } // 全都匹配不上 , 返回黑色
return Color . BLACK ;


signature:
public class Colors { /** * Color转换为 “ rgb ( 12 , 25 , 33 ) ” 格式字符串
 * @ param color
 * 颜色
 * @ return 文字格式 */
public static String toRGB ( Color color ) { } }

implementation: return String . format ( "rgb(%d, %d, %d)" , color . getRed ( ) , color . getGreen ( ) , color . getBlue ( ) ) ;


signature:
public class Colors { /** * 获取一个制定范围内的颜色
 * @ param min
 * 最小取值 , 范围0-255
 * @ param max
 * 最大取值 , 范围0-255
 * @ return 颜色 */
public static Color randomColor ( int min , int max ) { } }

implementation: if ( min > 255 ) { min = 255 ; } if ( min < 0 ) { min = 0 ; } if ( max > 255 ) { max = 255 ; } if ( max < 0 ) { max = 0 ; } return new Color ( min + R . random ( 0 , max - min ) , min + R . random ( 0 , max - min ) , min + R . random ( 0 , max - min ) ) ;


signature:
public class Colors { /** * 获取图片指定像素点的RGB值
 * @ param srcIm
 * 源图片
 * @ param x
 * 横坐标
 * @ param y
 * 纵坐标
 * @ return RGB值数组 */
public static int [ ] getRGB ( BufferedImage srcIm , int x , int y ) { } }

implementation: int pixel = srcIm . getRGB ( x , y ) ; return getRGB ( pixel ) ;


signature:
public class Colors { /** * 获取像素点的RGB值 ( 三元素数组 ) )
 * @ param pixel
 * 像素RGB值
 * @ return RGB值数组 */
public static int [ ] getRGB ( int pixel ) { } }

implementation: int r = ( pixel >> 16 ) & 0xff ; int g = ( pixel >> 8 ) & 0xff ; int b = pixel & 0xff ; return new int [ ] { r , g , b } ;


signature:
public class Colors { /** * 获取图片指定像素点的亮度值 ( YUV中的Y )
 * @ param srcIm
 * 源图片
 * @ param x
 * 横坐标
 * @ param y
 * 纵坐标
 * @ return 亮度值 */
public static int getLuminance ( BufferedImage srcIm , int x , int y ) { } }

implementation: int [ ] rgb = getRGB ( srcIm , x , y ) ; return ( int ) ( 0.3 * rgb [ 0 ] + 0.59 * rgb [ 1 ] + 0.11 * rgb [ 2 ] ) ; // 加权法


signature:
public class Colors { /** * 获取图片指定像素点的亮度值 ( YUV中的Y ) 类型为double
 * @ param srcIm
 * 源图片
 * @ param x
 * 横坐标
 * @ param y
 * 纵坐标
 * @ return 亮度值 */
public static double getLuminanceDouble ( BufferedImage srcIm , int x , int y ) { } }

implementation: int [ ] rgb = getRGB ( srcIm , x , y ) ; return 0.3 * rgb [ 0 ] + 0.59 * rgb [ 1 ] + 0.11 * rgb [ 2 ] ; // 加权法


signature:
public class Colors { /** * 获取图片指定像素点的灰度值
 * @ param srcIm
 * 源图片
 * @ param x
 * 横坐标
 * @ param y
 * 纵坐标
 * @ return 灰度值 */
public static int getGray ( BufferedImage srcIm , int x , int y ) { } }

implementation: int grayValue = getLuminance ( srcIm , x , y ) ; int newPixel = 0 ; newPixel = ( grayValue << 16 ) & 0x00ff0000 | ( newPixel & 0xff00ffff ) ; newPixel = ( grayValue << 8 ) & 0x0000ff00 | ( newPixel & 0xffff00ff ) ; newPixel = ( grayValue ) & 0x000000ff | ( newPixel & 0xffffff00 ) ; return newPixel ;


signature:
public class Colors { /** * 获取两个像素点正片叠底后的像素值
 * @ param pixel1
 * 像素点1
 * @ param pixel2
 * 像素点1
 * @ return 新像素点值 */
public static int getMultiply ( int pixel1 , int pixel2 ) { } }

implementation: int [ ] rgb1 = getRGB ( pixel1 ) ; int [ ] rgb2 = getRGB ( pixel2 ) ; int r = rgb1 [ 0 ] * rgb2 [ 0 ] / 255 ; int g = rgb1 [ 1 ] * rgb2 [ 1 ] / 255 ; int b = rgb1 [ 2 ] * rgb2 [ 2 ] / 255 ; return new Color ( r , g , b ) . getRGB ( ) ;


signature:
public class SimpleDataSource { /** * 这是唯一会被NutDao调用的方法 */
public Connection getConnection ( ) throws SQLException { } }

implementation: Connection conn ; if ( username != null ) conn = DriverManager . getConnection ( jdbcUrl , username , password ) ; else conn = DriverManager . getConnection ( jdbcUrl ) ; return conn ;


signature:
public class AbstractOpt { /** * 计算子项 */
protected Object calculateItem ( Object obj ) { } }

implementation: if ( obj == null ) { return null ; } if ( obj instanceof Number ) { return obj ; } if ( obj instanceof Boolean ) { return obj ; } if ( obj instanceof String ) { return obj ; } if ( obj instanceof Elobj ) { return ( ( Elobj ) obj ) . fetchVal ( ) ; } if ( obj instanceof Operator ) { return ( ( Operator ) obj ) . calculate ( ) ; } throw new ElException ( "未知计算类型!" + obj ) ;


signature:
public class MethodParamNamesScaner { /** * 获取Method的形参名称列表
 * @ param method 需要解析的方法
 * @ return 形参名称列表 , 如果没有调试信息 , 将返回null */
public static List < String > getParamNames ( Method method ) { } }

implementation: try { int size = method . getParameterTypes ( ) . length ; if ( size == 0 ) return new ArrayList < String > ( 0 ) ; List < String > list = ClassMetaReader . getParamNames ( method . getDeclaringClass ( ) ) . get ( ClassMetaReader . getKey ( method ) ) ; if ( list == null ) return null ; if ( list . size ( ) == size ) return list ; if ( list . size ( ) > size ) return list . subList ( 0 , size ) ; return null ; } catch ( Throwable e ) { throw new RuntimeException ( e ) ; }


signature:
public class MethodParamNamesScaner { /** * 获取Constructor的形参名称列表
 * @ param constructor 需要解析的构造函数
 * @ return 形参名称列表 , 如果没有调试信息 , 将返回null */
public static List < String > getParamNames ( Constructor < ? > constructor ) { } }

implementation: try { int size = constructor . getParameterTypes ( ) . length ; if ( size == 0 ) return new ArrayList < String > ( 0 ) ; List < String > list = ClassMetaReader . getParamNames ( constructor . getDeclaringClass ( ) ) . get ( ClassMetaReader . getKey ( constructor ) ) ; if ( list != null && list . size ( ) != size ) return list . subList ( 0 , size ) ; return list ; } catch ( Throwable e ) { throw new RuntimeException ( e ) ; }


signature:
public class QueueInputStream { /** * 读取一项数据
 * @ param ends 结束符 , 默认 ' ' , ' \ r ' , ' \ n '
 * @ return 数据
 * @ throws IOException */
public String readItem ( char ... ends ) throws IOException { } }

implementation: StringBuilder sb = new StringBuilder ( ) ; while ( true ) { switch ( peek ( ) ) { case ' ' : case '\r' : case '\n' : case - 1 : return sb . toString ( ) ; default : for ( Character c : ends ) { if ( c . charValue ( ) == peek ( ) ) { return sb . toString ( ) ; } } sb . append ( ( char ) poll ( ) ) ; } }


signature:
public class QueueInputStream { /** * 读取一行
 * @ return 一行数据
 * @ throws IOException */
public String readLine ( ) throws IOException { } }

implementation: StringBuilder sb = new StringBuilder ( ) ; for ( ; ; ) { int v = peek ( ) ; if ( v == '\r' || v == '\n' ) { poll ( ) ; v = peekNext ( ) ; if ( v == '\r' || v == '\n' ) { poll ( ) ; } break ; } sb . append ( ( char ) poll ( ) ) ; } return sb . toString ( ) ;


signature:
public class QueueInputStream { /** * 读取头部字节 , 并删除
 * @ return 头部字节
 * @ throws IOException */
public int poll ( ) throws IOException { } }

implementation: peekindex = 0 ; int v = - 1 ; if ( cache . size ( ) <= 0 ) { v = is . read ( ) ; } else { v = cache . poll ( ) ; } if ( v == - 1 ) { end = true ; } if ( v == '\n' ) { col = 0 ; row ++ ; } else { col ++ ; } return v ;


signature:
public class QueueInputStream { /** * 访问头部开始第几个字节 , 不删除
 * @ param index
 * @ return 头部的第N个字节
 * @ throws IOException */
public int peek ( int index ) throws IOException { } }

implementation: while ( cache . size ( ) <= index ) { cache . add ( is . read ( ) ) ; } return cache . get ( index ) ;


signature:
public class QueueInputStream { /** * 访问头部字节 , 不删除
 * @ return 头部字节
 * @ throws IOException */
public int peek ( ) throws IOException { } }

implementation: peekindex = 0 ; int v = peek ( peekindex ++ ) ; if ( v == - 1 ) { end = true ; } return v ;


signature:
public class QueueInputStream { /** * 跳过和丢弃输入流中的数据 */
public long skip ( long n ) throws IOException { } }

implementation: int s = cache . size ( ) ; if ( s > 0 ) { if ( s < n ) { n = n - s ; } else { for ( int i = 0 ; i < n ; i ++ ) { cache . poll ( ) ; } return n ; } } return super . skip ( n ) + s ;


signature:
public class QueueInputStream { /** * 是否以 start 开始
 * @ param start
 * @ return true , 如果的确以指定字符串开始
 * @ throws IOException */
public boolean startWith ( String start ) throws IOException { } }

implementation: char [ ] cs = start . toCharArray ( ) ; int i = 0 ; for ( ; i < cs . length ; i ++ ) { if ( peek ( i ) != cs [ i ] ) { return false ; } } return true ;


signature:
public class NutFilter { /** * 过滤请求 . 过滤顺序 ( ignorePtn , exclusionsSuffix , exclusionsPrefix , exclusionPaths )
 * @ param matchUrl 待匹配URL
 * @ return 需要排除则返回true
 * @ throws IOException 不太可能抛出
 * @ throws ServletException 不太可能抛出 */
protected boolean isExclusion ( String matchUrl ) throws IOException , ServletException { } }

implementation: if ( ignorePtn != null && ignorePtn . matcher ( matchUrl ) . find ( ) ) { return true ; } if ( exclusionsSuffix != null ) { if ( exclusionsSuffix . matcher ( matchUrl ) . find ( ) ) { return true ; } } if ( exclusionsPrefix != null ) { if ( exclusionsPrefix . matcher ( matchUrl ) . find ( ) ) { return true ; } } if ( exclusionPaths != null && exclusionPaths . contains ( matchUrl ) ) { return true ; } return false ;


signature:
public class Fonts { /** * 获得随机字体
 * @ param style
 * 字体样式 支持 : Font . PLAIN Font . BOLD Font . ITALIC
 * @ param size
 * 字体大小
 * @ return 字体 */
public static Font random ( int style , int size ) { } }

implementation: Font font = null ; while ( font == null ) { try { int index = R . random ( 0 , commonFonts . length - 1 ) ; font = get ( commonFonts [ index ] , style , size ) ; } catch ( Exception e ) { } } return font ;


signature:
public class Fonts { /** * 获得指定字体
 * @ param name
 * 字体名称
 * @ param style
 * 字体样式 支持 : Font . PLAIN Font . BOLD Font . ITALIC
 * @ param size
 * 字体大小
 * @ return 字体 */
public static Font get ( String name , int style , int size ) { } }

implementation:
if ( Strings . isBlank ( name ) ) { // 尝试微软雅黑 , 黑体 , 宋体等常见字体
Font ff = find ( commonFonts , style , size ) ; if ( ff == null ) { throw new RuntimeException ( "Please manually set the font, or add some common fonts in the system" ) ; } return ff ; } return new Font ( name , style , size ) ;


signature:
public class MethodOpt { /** * 取得方法执行的参数
 * @ return */
@ SuppressWarnings ( "unchecked" ) private List < Object > fetchParam ( ) { } }

implementation: List < Object > rvals = new ArrayList < Object > ( ) ; if ( right != null ) { if ( right instanceof CommaOpt ) { rvals = ( List < Object > ) ( ( CommaOpt ) right ) . calculate ( ) ; } else { rvals . add ( calculateItem ( right ) ) ; } } if ( ! rvals . isEmpty ( ) ) { for ( int i = 0 ; i < rvals . size ( ) ; i ++ ) { if ( rvals . get ( i ) instanceof Operator ) { rvals . set ( i , ( ( Operator ) rvals . get ( i ) ) . calculate ( ) ) ; } } } return rvals ;


signature:
public class NutConf { /** * 加载资源 */
@ SuppressWarnings ( { } }

implementation: "unchecked" , "rawtypes" } ) private void loadResource ( String ... paths ) { for ( String path : paths ) { List < NutResource > resources = Scans . me ( ) . scan ( path , "\\.(js|json)$" ) ; for ( NutResource nr : resources ) { try { Object obj = Json . fromJson ( nr . getReader ( ) ) ; if ( obj instanceof Map ) { Map m = ( Map ) obj ; map = ( Map ) Mapl . merge ( map , m ) ; for ( Object key : m . keySet ( ) ) { if ( key . equals ( "include" ) ) { map . remove ( "include" ) ; List < String > include = ( List ) m . get ( "include" ) ; loadResource ( include . toArray ( new String [ include . size ( ) ] ) ) ; } } } } catch ( Throwable e ) { if ( log . isWarnEnabled ( ) ) log . warn ( "Fail to load config?! for " + nr . getName ( ) , e ) ; } } }


signature:
public class NutConf { /** * 读取一个配置项 , 并转换成相应的类型 . */
public static Object get ( String key , Type type ) { } }

implementation: return me ( ) . getItem ( key , type ) ;


signature:
public class NutConf { /** * 读取一个配置项 , 并转换成相应的类型 .
 * @ param key
 * @ param type
 * @ return */
private Object getItem ( String key , Type type ) { } }

implementation: if ( null == map ) { return null ; } if ( null == type ) { return map . get ( key ) ; } return Mapl . maplistToObj ( map . get ( key ) , type ) ;


signature:
public class CustomMake { /** * 加载插件 */
@ SuppressWarnings ( { } }

implementation: "unchecked" , "rawtypes" } ) public CustomMake init ( ) { List < String > plug = ( List < String > ) ( ( Map ) NutConf . get ( "EL" ) ) . get ( "custom" ) ; String [ ] t = plug . toArray ( new String [ 0 ] ) ; PluginManager < RunMethod > rm = new SimplePluginManager < RunMethod > ( t ) ; for ( RunMethod r : rm . gets ( ) ) { me ( ) . runms . put ( r . fetchSelf ( ) , r ) ; } return this ;


signature:
public class SqlLiteral { /** * [ @ | $ ] [ a - zA - Z0-9 _ - . ] +
 * < pre >
 * 48-57 0-9
 * 65-90 A - Z
 * 97-122 a - z
 * 95 _
 * 45 -
 * 46 .
 * < / pre >
 * @ param str
 * @ return SqlLiteral */
SqlLiteral valueOf ( String str ) { } }

implementation:
reset ( ) ; // int statementIndex = 1;
source = str ; if ( null == source ) return this ; char [ ] cs = Strings . trim ( source ) . toCharArray ( ) ; StringBuilder sb ; for ( int i = 0 ; i < cs . length ; i ++ ) { char c = cs [ i ] ; if ( c == paramChar ) { if ( cs [ i + 1 ] == c ) { stack . push ( c ) ; i ++ ; continue ; } sb = new StringBuilder ( ) ; i = readTokenName ( cs , i , sb ) ; // Fail to read token name
if ( sb . length ( ) == 0 ) { stack . push ( c ) ; } else { paramIndexes . add ( sb . toString ( ) , stack . markToken ( ) ) ; // paramIndexes . add ( name , stack . markToken ( ) ) ;
// statementIndexes . add ( name , statementIndex + + ) ;
} } else if ( c == varChar ) { if ( cs [ i + 1 ] == varChar ) { stack . push ( c ) ; i ++ ; continue ; } sb = new StringBuilder ( ) ; i = readTokenName ( cs , i , sb ) ; // Fail to read token name
if ( sb . length ( ) == 0 ) { stack . push ( c ) ; } else { // varIndexes . add ( sb . toString ( ) , stack . markToken ( ) ) ;
varIndexes . add ( sb . toString ( ) , stack . markToken ( ) ) ; } } else { stack . push ( c ) ; } } stack . finish ( ) ; // eval SqlType . . .
if ( stack . firstEquals ( "SELECT" ) || stack . firstEquals ( "WITH" ) ) type = SqlType . SELECT ; else if ( stack . firstEquals ( "UPDATE" ) ) type = SqlType . UPDATE ; else if ( stack . firstEquals ( "INSERT" ) ) type = SqlType . INSERT ; else if ( stack . firstEquals ( "DELETE" ) ) type = SqlType . DELETE ; else if ( stack . firstEquals ( "CREATE" ) ) type = SqlType . CREATE ; else if ( stack . firstEquals ( "DROP" ) ) type = SqlType . DROP ; else if ( stack . firstEquals ( "TRUNCATE" ) ) type = SqlType . TRUNCATE ; else if ( stack . firstEquals ( "ALTER" ) ) type = SqlType . ALTER ; else if ( stack . firstEquals ( "EXEC" ) ) type = SqlType . EXEC ; else if ( stack . firstEquals ( "CALL" ) ) type = SqlType . CALL ; else if ( stack . firstEquals ( "{CALL" ) ) type = SqlType . CALL ; else type = SqlType . OTHER ; return this ;


signature:
public class AbstractLog { /** * 产生一个LogInfo对象 , 以支持以下调用方式 :
 * < code > log . warn ( e ) < / code >
 * < code > log . warnf ( " User ( name = % s ) login fail " , username , e ) < / code > */
private LogInfo makeInfo ( Object obj , Object ... args ) { } }

implementation:
if ( obj == null ) return LOGINFO_NULL ; try { LogInfo info = new LogInfo ( ) ; if ( obj instanceof Throwable ) { info . e = ( Throwable ) obj ; info . message = info . e . getMessage ( ) ; } else if ( args == null || args . length == 0 ) { info . message = obj . toString ( ) ; } // / / map to another mehtod
// else if ( args . length = = 1 & & args [ 0 ] instanceof Throwable ) {
// info . message = obj . toString ( ) ;
// info . e = ( Throwable ) args [ 0 ] ;
else { info . message = String . format ( obj . toString ( ) , args ) ; if ( args [ args . length - 1 ] instanceof Throwable ) info . e = ( Throwable ) args [ args . length - 1 ] ; } return info ; } catch ( Throwable e ) { // 即使格式错误也继续log
if ( isWarnEnabled ( ) ) warn ( "String format fail in log , fmt = " + obj + " , args = " + Arrays . toString ( args ) , e ) ; return LOGINFO_ERROR ; }


signature:
public class Uploads { /** * 根据请求对象创建参数 MAP , 同时根据 QueryString , 为 MAP 设置初始值
 * @ param req
 * 请求对象
 * @ return 参数 MAP */
public static NutMap createParamsMap ( HttpServletRequest req ) { } }

implementation:
NutMap params = new NutMap ( ) ; // parse query strings
Enumeration < ? > en = req . getParameterNames ( ) ; while ( en . hasMoreElements ( ) ) { String key = en . nextElement ( ) . toString ( ) ; params . put ( key , req . getParameter ( key ) ) ; } return params ;


signature:
public class Uploads { /** * 从当前会话中移除进度对象
 * @ param req
 * 请求对象 */
public static void removeInfo ( HttpServletRequest req ) { } }

implementation: try { HttpSession sess = req . getSession ( false ) ; if ( null != sess ) { sess . removeAttribute ( UploadInfo . SESSION_NAME ) ; } } catch ( Throwable e ) { }


signature:
public class CronSequenceGenerator { /** * Get the next { @ link Date } in the sequence matching the Cron pattern and
 * after the value provided . The return value will have a whole number of
 * seconds , and will be after the input value .
 * @ param date a seed value
 * @ return the next value matching the pattern */
public Date next ( Date date ) { } }

implementation:
/* The plan :
 1 Round up to the next whole second
 2 If seconds match move on , otherwise find the next match :
 2.1 If next match is in the next minute then roll forwards
 3 If minute matches move on , otherwise find the next match
 3.1 If next match is in the next hour then roll forwards
 3.2 Reset the seconds and go to 2
 4 If hour matches move on , otherwise find the next match
 4.1 If next match is in the next day then roll forwards ,
 4.2 Reset the minutes and seconds and go to 2 */
Calendar calendar = new GregorianCalendar ( ) ; calendar . setTimeZone ( this . timeZone ) ; calendar . setTime ( date ) ; // First , just reset the milliseconds and try to calculate from there . . .
calendar . set ( Calendar . MILLISECOND , 0 ) ; long originalTimestamp = calendar . getTimeInMillis ( ) ; doNext ( calendar , calendar . get ( Calendar . YEAR ) ) ; if ( calendar . getTimeInMillis ( ) == originalTimestamp ) { // We arrived at the original timestamp - round up to the next whole second and try again . . .
calendar . add ( Calendar . SECOND , 1 ) ; doNext ( calendar , calendar . get ( Calendar . YEAR ) ) ; } return calendar . getTime ( ) ;


signature:
public class CronSequenceGenerator { /** * Search the bits provided for the next set bit after the value provided ,
 * and reset the calendar .
 * @ param bits a { @ link BitSet } representing the allowed values of the field
 * @ param value the current value of the field
 * @ param calendar the calendar to increment as we move through the bits
 * @ param field the field to increment in the calendar ( @ see
 * { @ link Calendar } for the static constants defining valid fields )
 * @ param lowerOrders the Calendar field ids that should be reset ( i . e . the
 * ones of lower significance than the field of interest )
 * @ return the value of the calendar field that is next in the sequence */
private int findNext ( BitSet bits , int value , Calendar calendar , int field , int nextField , List < Integer > lowerOrders ) { } }

implementation:
int nextValue = bits . nextSetBit ( value ) ; // roll over if needed
if ( nextValue == - 1 ) { calendar . add ( nextField , 1 ) ; reset ( calendar , Arrays . asList ( field ) ) ; nextValue = bits . nextSetBit ( 0 ) ; } if ( nextValue != value ) { calendar . set ( field , nextValue ) ; reset ( calendar , lowerOrders ) ; } return nextValue ;


signature:
public class CronSequenceGenerator { /** * Reset the calendar setting all the fields provided to zero . */
private void reset ( Calendar calendar , List < Integer > fields ) { } }

implementation: for ( int field : fields ) { calendar . set ( field , field == Calendar . DAY_OF_MONTH ? 1 : 0 ) ; }


signature:
public class CronSequenceGenerator { /** * Parse the given pattern expression . */
private void parse ( String expression ) throws IllegalArgumentException { } }

implementation:
String [ ] fields = Strings . splitIgnoreBlank ( expression , " " ) ; if ( fields . length != 6 ) { throw new IllegalArgumentException ( String . format ( "Cron expression must consist of 6 fields (found %d in \"%s\")" , fields . length , expression ) ) ; } setNumberHits ( this . seconds , fields [ 0 ] , 0 , 60 ) ; setNumberHits ( this . minutes , fields [ 1 ] , 0 , 60 ) ; setNumberHits ( this . hours , fields [ 2 ] , 0 , 24 ) ; setDaysOfMonth ( this . daysOfMonth , fields [ 3 ] ) ; setMonths ( this . months , fields [ 4 ] ) ; setDays ( this . daysOfWeek , replaceOrdinals ( fields [ 5 ] , "SUN,MON,TUE,WED,THU,FRI,SAT" ) , 8 ) ; if ( this . daysOfWeek . get ( 7 ) ) { // Sunday can be represented as 0 or 7
this . daysOfWeek . set ( 0 ) ; this . daysOfWeek . clear ( 7 ) ; }


signature:
public class CronSequenceGenerator { /** * Replace the values in the comma - separated list ( case insensitive )
 * with their index in the list .
 * @ return a new String with the values from the list replaced */
private String replaceOrdinals ( String value , String commaSeparatedList ) { } }

implementation: String [ ] list = Strings . splitIgnoreBlank ( commaSeparatedList ) ; for ( int i = 0 ; i < list . length ; i ++ ) { String item = list [ i ] . toUpperCase ( ) ; value = value . toUpperCase ( ) . replaceAll ( item , "" + i ) ; } return value ;


signature:
public class AccessOpt { /** * 取得变得的值 */
public Object fetchVar ( ) { } }

implementation: if ( left instanceof Operator ) { return ( ( Operator ) left ) . calculate ( ) ; } if ( left instanceof Elobj ) { return ( ( Elobj ) left ) . fetchVal ( ) ; } return left ;


signature:
public class NutValidate { /** * 根据一个描述的表增加自身的检查项 ,
 * @ param map
 * 描述检查项的 Map
 * @ return 自身以便链式赋值 */
public NutValidate addAll ( Map < String , Object > map ) { } }

implementation:
NutMap m2 = NutMap . WRAP ( map ) ; for ( String key : m2 . keySet ( ) ) { // 针对字符串型的值 , 检查前是否要预先去掉左右空白
if ( "trim" . equals ( key ) ) { this . items . add ( new TrimValidator ( ) ) ; } // 数字区间
else if ( "intRange" . equals ( key ) ) { String str = m2 . getString ( key ) ; this . items . add ( new IntRangeValidator ( str ) ) ; } // 日期范围的区间
else if ( "dateRange" . equals ( key ) ) { String str = m2 . getString ( key ) ; this . items . add ( new DateRangeValidator ( str ) ) ; } // 验证值的字符串形式 , 支持 " ! " 开头
else if ( "regex" . equals ( key ) ) { String str = m2 . getString ( key ) ; this . items . add ( new RegexValidator ( str ) ) ; } // 确保值非 null
else if ( "notNull" . equals ( key ) ) { this . items . add ( new NotNullValidator ( ) ) ; } // 针对字符串的值 , 最大长度不超过多少
else if ( "maxLength" . equals ( key ) ) { int len = m2 . getInt ( key ) ; this . items . add ( new MaxLengthValidator ( len ) ) ; } // 针对字符串的值 , 最小长度不能低于多少
else if ( "minLength" . equals ( key ) ) { int len = m2 . getInt ( key ) ; this . items . add ( new MinLengthValidator ( len ) ) ; } // 其他的无视
} return this ;


signature:
public class NutValidate { /** * 根据检查器的优先顺序 , 重新调整检查列表
 * @ return 自身以便链式赋值 */
public NutValidate ready ( ) { } }

implementation: Collections . sort ( items , new Comparator < NutValidator > ( ) { public int compare ( NutValidator v1 , NutValidator v2 ) { return v1 . order ( ) - v2 . order ( ) ; } } ) ; return this ;


signature:
public class NutValidate { /** * 执行检查
 * @ param val
 * @ return 检查后的结果 , 可能会被修改 , 譬如 ` trim ` 操作
 * @ throws NutValidateException
 * - 如果任何一个检查器除了错误 , 就会抛出本错误 , 并中断后续的检查 */
public Object check ( Object val ) throws NutValidateException { } }

implementation: Object re = val ; for ( NutValidator nv : items ) { re = nv . check ( re ) ; } return re ;


signature:
public class Stopwatch { /** * 秒表开始计时 , 计时时间的最小单位是毫微秒
 * @ return 开始计时的秒表对象 */
public static Stopwatch beginNano ( ) { } }

implementation: Stopwatch sw = new Stopwatch ( ) ; sw . nano = true ; sw . start ( ) ; return sw ;


signature:
public class EntityOperator { /** * 批量执行准备好的 Dao 语句
 * @ return 自身 */
public EntityOperator exec ( ) { } }

implementation:
/* * 为每个语句检查一遍参数状态 */
if ( null != entity ) { for ( Pojo pojo : pojoList ) { if ( null == pojo . getOperatingObject ( ) ) pojo . setOperatingObject ( myObj ) ; if ( pojo . params ( ) . isEmpty ( ) ) pojo . addParamsBy ( pojo . getOperatingObject ( ) ) ; } updateCount = dao . _exec ( pojoList . toArray ( new DaoStatement [ pojoList . size ( ) ] ) ) ; } return this ;


signature:
public class JsonRPC { /** * 服务端 */
public static NutMap invoke ( final Object obj , Reader r ) { } }

implementation:
final NutMap resp = new NutMap ( ) ; resp . setv ( "jsonrpc" , Version ) ; Object req ; try { req = Json . fromJson ( r ) ; } catch ( Exception e ) { return resp . setv ( "error" , error ( ParseError , "Parse error" , E ( e ) ) ) ; } if ( req == null ) { return resp . setv ( "error" , error ( InvalidRequest , "Invalid Request" , "json is null" ) ) ; } if ( req instanceof Iterable ) { // rpc批量调用
final List < NutMap > results = new ArrayList < NutMap > ( ) ; Lang . each ( req , new Each < Object > ( ) { public void invoke ( int index , Object ele , int length ) { if ( ele instanceof Map ) { results . add ( JsonRPC . invoke ( obj , new NutMap ( ( Map < String , Object > ) ele ) ) ) ; } else { NutMap _resp = new NutMap ( ) ; _resp . setv ( "jsonrpc" , Version ) . setv ( "error" , error ( InvalidRequest , "Invalid Request" , "not map or list" ) ) ; results . add ( _resp ) ; } } } ) ; return resp . setv ( "result" , results ) ; } else if ( req instanceof Map ) { // 单一调用
return invoke ( obj , new NutMap ( ( Map < String , Object > ) req ) ) ; } else { // 传的是什么鸟 , 拒绝
return resp . setv ( "error" , error ( InvalidRequest , "Invalid Request" , "not map or list" ) ) ; }


signature:
public class JsonRPC { /** * 客户端 . 用于生成一个代理接口的实例 , 透明访问json - rpc服务
 * @ param klass 需要代理的接口
 * @ param endpoint jsonrpc URL入口
 * @ param namespace 命名空间 , 非json - rpc标准 , 扩展用 , 不需要就传null
 * @ param timeout 超时设置 , 若永不超时 , 设置为 - 1
 * @ return 代理实例 */
public static < T > T mapper ( Class < T > klass , final String endpoint , final String namespace , final int timeout ) { } }

implementation: return ( T ) Proxy . newProxyInstance ( klass . getClassLoader ( ) , new Class < ? > [ ] { klass } , new InvocationHandler ( ) { public Object invoke ( Object proxy , Method method , Object [ ] args ) throws Throwable { NutMap jreq = new NutMap ( ) ; jreq . setv ( "jsonrpc" , "2.0" ) . setv ( "id" , R . UU32 ( ) ) . setv ( "method" , method . getName ( ) ) ; if ( ! Strings . isBlank ( namespace ) ) { jreq . put ( "namespace" , namespace ) ; } jreq . setv ( "params" , args ) ; Request req = Request . create ( endpoint , METHOD . POST ) ; req . setData ( Json . toJson ( jreq ) ) ; Response resp = Sender . create ( req ) . setTimeout ( timeout ) . send ( ) ; if ( resp . isOK ( ) ) { if ( method . getReturnType ( ) == Void . class ) return null ; return Json . fromJson ( method . getGenericReturnType ( ) , resp . getReader ( ) ) ; } throw new RuntimeException ( "resp code=" + resp . getStatus ( ) ) ; } } ) ;


signature:
public class PropertiesProxy { /** * 加载指定文件 / 文件夹的Properties文件 , 合并成一个Properties对象
 * < b style = color : red > 如果有重复的key , 请务必注意加载的顺序 ! ! < b / >
 * @ param paths
 * 需要加载的Properties文件路径 */
public void setPaths ( String ... paths ) { } }

implementation:
clear ( ) ; try { List < NutResource > list = getResources ( paths ) ; if ( utf8 ) for ( NutResource nr : list ) { if ( log . isDebugEnabled ( ) ) log . debug ( "load properties from " + nr ) ; Reader r = nr . getReader ( ) ; try { load ( nr . getReader ( ) , false ) ; } finally { Streams . safeClose ( r ) ; } } else { Properties p = new Properties ( ) ; for ( NutResource nr : list ) { // 用字符流来读取文件
BufferedReader bf = new BufferedReader ( new InputStreamReader ( nr . getInputStream ( ) ) ) ; try { p . load ( bf ) ; } finally { Streams . safeClose ( bf ) ; } } putAll ( p ) ; } } catch ( IOException e ) { throw Lang . wrapThrow ( e ) ; }


signature:
public class PropertiesProxy { /** * 加载指定文件 / 文件夹的Properties文件
 * @ param paths
 * 需要加载的Properties文件路径
 * @ return 加载到的Properties文件Resource列表 */
private List < NutResource > getResources ( String ... paths ) { } }

implementation: List < NutResource > list = new ArrayList < NutResource > ( ) ; if ( null != keyIndex ) { try { String vmJsonStr = "" ; Properties p = System . getProperties ( ) ; for ( Object key : p . keySet ( ) ) { if ( ( ( String ) key ) . startsWith ( VM_NUTZ_CONF_PATH + keyIndex ) ) vmJsonStr = p . getProperty ( ( String ) key ) . trim ( ) ; } if ( Strings . isNotBlank ( vmJsonStr ) ) { paths = vmJsonStr . split ( "\\," ) ; } } catch ( Exception e ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "-D" + VM_NUTZ_CONF_PATH + keyIndex + " value is invalid:  " + e . getMessage ( ) ) ; } } } for ( String path : paths ) { try { List < NutResource > resources = Scans . me ( ) . loadResource ( "^.+[.]properties$" , path ) ; list . addAll ( resources ) ; } catch ( Exception e ) { if ( ignoreResourceNotFound ) { if ( log . isWarnEnabled ( ) ) { log . warn ( "Could not load resource from " + path + ": " + e . getMessage ( ) ) ; } } else { throw Lang . wrapThrow ( e ) ; } } } return list ;


signature:
public class PropertiesProxy { /** * 根据自身的一个键对应的值扩展自身的属性 。
 * 本函数假设你可能有下面的键值 :
 * < pre >
 * files :
 * path / to _ a . properties
 * path / to _ b . properties
 * # End files
 * < / pre >
 * 那么如果你调用 < code > joinByKey ( " files " ) ; < / code > < br >
 * 则会将其值的两个属性文件展开 , 加入到自身 。
 * 属性文件的路径可以是磁盘全路径 , 或者在 CLASSPATH 里的路径
 * @ param key
 * @ return 自身 */
public PropertiesProxy joinByKey ( String key ) { } }

implementation:
String str = get ( key ) ; final PropertiesProxy me = this ; if ( ! Strings . isBlank ( str ) ) { String [ ] ss = Strings . splitIgnoreBlank ( str , "\n" ) ; for ( String s : ss ) { File f = Files . findFile ( s ) ; if ( null == f ) { throw Lang . makeThrow ( "Fail to found path '%s' in CLASSPATH or File System!" , s ) ; } // 如果是一个包 , 引用全部 Files
if ( f . isDirectory ( ) ) { Disks . visitFile ( f , new FileVisitor ( ) { public void visit ( File f ) { me . joinAndClose ( Streams . fileInr ( f ) ) ; } } , new FileFilter ( ) { public boolean accept ( File f ) { if ( f . isDirectory ( ) ) return ! f . isHidden ( ) && ! f . getName ( ) . startsWith ( "." ) ; return f . getName ( ) . endsWith ( ".properties" ) ; } } ) ; } // 否则引用单个文件
else if ( f . isFile ( ) ) { this . joinAndClose ( Streams . fileInr ( f ) ) ; } } } return this ;


signature:
public class PropertiesProxy { /** * 将另外一个 Properties 文本加入本散列表
 * @ param r
 * 文本输入流
 * @ return 自身 */
public PropertiesProxy joinAndClose ( Reader r ) { } }

implementation: MultiLineProperties mp = new MultiLineProperties ( ) ; try { mp . load ( r ) ; } catch ( IOException e ) { throw Lang . wrapThrow ( e ) ; } finally { Streams . safeClose ( r ) ; } this . putAll ( mp ) ; return this ;


signature:
public class MaplRebuild { /** * 添加属性
 * @ param path
 * 路径
 * @ param obj */
public void put ( String path , Object obj ) { } }

implementation: init ( path , obj ) ; inject ( newobj , 0 ) ;


signature:
public class MaplRebuild { /** * 添加属性
 * @ param path
 * 路径
 * @ param obj
 * @ param arrayIndex
 * 索引队列 */
public void put ( String path , Object obj , LinkedList < Integer > arrayIndex ) { } }

implementation: this . arrayIndex = arrayIndex ; put ( path , obj ) ;


signature:
public class MaplRebuild { /** * 删除结点
 * @ param path */
public void remove ( String path ) { } }

implementation: model = Model . del ; init ( path , null ) ; inject ( newobj , 0 ) ;


signature:
public class MaplRebuild { /** * 访问结点
 * @ param path
 * 路径 */
public Object cell ( String path ) { } }

implementation: model = Model . cell ; init ( path , null ) ; inject ( newobj , 0 ) ; return cellObj ;


signature:
public class MaplRebuild { /** * 注入
 * @ param obj
 * @ param i */
@ SuppressWarnings ( "unchecked" ) private Object inject ( Object obj , int i ) { } }

implementation:
String key = keys [ i ] ; // 根数组
if ( key . indexOf ( '[' ) == 0 ) { List < Object > list = new ArrayList < Object > ( ) ; if ( obj != null ) { list = ( List < Object > ) obj ; } injectList ( list , i , fetchIndex ( key ) ) ; return list ; } // 数组
// if ( key . endsWith ( " [ ] " ) ) {
int pos = key . indexOf ( '[' ) ; if ( pos > 0 ) { Map < String , Object > map = new LinkedHashMap < String , Object > ( ) ; if ( obj != null ) { map = ( Map < String , Object > ) obj ; } // 有Key的list
String k = key . substring ( 0 , pos ) ; if ( ! map . containsKey ( k ) ) { map . put ( k , new ArrayList < Object > ( ) ) ; } int [ ] index = fetchIndex ( key . substring ( key . indexOf ( '[' ) , key . length ( ) ) ) ; injectList ( ( List < Object > ) map . get ( k ) , i , index ) ; return map ; } // 键值 : 这里有个特殊考虑 , 如果当前对象是个列表 , 那么键值必然是一个下标
if ( obj instanceof List ) { try { int index = Integer . parseInt ( keys [ i ] ) ; injectList ( ( List < Object > ) obj , i , Nums . array ( index ) ) ; return obj ; } catch ( Exception e ) { throw new RuntimeException ( "路径格式不正确!" ) ; } } // 当做普通的 map 好了
return injectMap ( obj , i ) ;


signature:
public class MaplRebuild { /** * 注入MAP
 * @ param obj
 * @ param i */
@ SuppressWarnings ( "unchecked" ) private Object injectMap ( Object obj , int i ) { } }

implementation: Map < String , Object > map ; String key = keys [ i ] ; if ( obj == null ) { map = new LinkedHashMap < String , Object > ( ) ; } else { map = ( Map < String , Object > ) obj ; } if ( model == Model . add ) { if ( i == keys . length - 1 ) { map . put ( key , val ) ; return map ; } if ( ! map . containsKey ( key ) || map . get ( key ) == null ) { map . put ( key , inject ( null , i + 1 ) ) ; return map ; } } else if ( model == Model . del ) { if ( i == keys . length - 1 ) { map . remove ( key ) ; return map ; } if ( ! map . containsKey ( key ) || map . get ( key ) == null ) { return map ; } } else if ( model == Model . cell ) { if ( i == keys . length - 1 ) { cellObj = map . get ( key ) ; return map ; } if ( ! map . containsKey ( key ) || map . get ( key ) == null ) { return map ; } } if ( map . containsKey ( key ) && map . get ( key ) != null ) { inject ( map . get ( key ) , i + 1 ) ; } return map ;


signature:
public class MaplRebuild { /** * 注入List
 * @ param list
 * 列表
 * @ param keyIndex
 * 当前 Key 路径的列表
 * @ param eleIndexes
 * 注入的元素下标列表 */
@ SuppressWarnings ( "unchecked" ) private void injectList ( List < Object > list , int keyIndex , int [ ] eleIndexes ) { } }

implementation:
// 下标列表如果是多个 , 那么预先处理一下列表
int i_last = eleIndexes . length - 1 ; for ( int i = 0 ; i < i_last ; i ++ ) { int index = eleIndexes [ i ] ; Object ele = list . get ( index ) ; // 是列表 ? 嗯很好很好
if ( ele instanceof List ) { list = ( List < Object > ) ele ; } // 不是列表啊 , 不能忍
else { throw Lang . makeThrow ( "invalid keyPath '%s' in key:%d eleIndex:%d" , Strings . join ( "." , keys ) , keyIndex , i ) ; } } // 得到要处理的下标
int eleIndex = eleIndexes [ i_last ] ; // 添加模式
if ( model == Model . add ) { if ( keyIndex == keys . length - 1 ) { if ( val instanceof Collection ) { list . addAll ( ( Collection < ? extends Object > ) val ) ; } else { list . add ( eleIndex , val ) ; } return ; } if ( list . size ( ) <= eleIndex ) { list . add ( eleIndex , new LinkedHashMap < String , Object > ( ) ) ; } } else if ( model == Model . del ) { if ( keyIndex == keys . length - 1 ) { if ( list . size ( ) > eleIndex ) { list . remove ( eleIndex ) ; } return ; } if ( list . size ( ) <= eleIndex ) { return ; } } else if ( model == Model . cell ) { if ( keyIndex == keys . length - 1 ) { if ( list . size ( ) > eleIndex ) { cellObj = list . get ( eleIndex ) ; } return ; } if ( list . size ( ) <= eleIndex ) { return ; } } inject ( ( Map < String , Object > ) list . get ( eleIndex ) , keyIndex + 1 ) ;


signature:
public class Avatar { /** * 根据名字生成头像 , 英文采用第一个字母 , 中文2个字使用2个字 , 超过2个字采用第一个字
 * @ param name
 * 名字
 * @ param size
 * 图片大小 , 默认256
 * @ param fontColor
 * 文字颜色 默认白色
 * @ param bgColor
 * 背景颜色 默认黑色
 * @ param fontName
 * 字体名称 需运行环境中已有该字体名称
 * @ param fontSize
 * 字体大小
 * @ param fontStyle
 * 字体样式 Font . PLAIN | | Font . BOLD | | Font . ITALIC
 * @ return 头像 */
public static BufferedImage createAvatar ( String name , int size , String fontColor , String bgColor , String fontName , int fontSize , int fontStyle ) { } }

implementation: return Images . createAvatar ( name , size , fontColor , bgColor , fontName , fontSize , fontStyle ) ;


signature:
public class Method { /** * Creates a new { @ link Method } .
 * @ param m
 * a java . lang . reflect method descriptor
 * @ return a { @ link Method } corresponding to the given Java method
 * declaration . */
public static Method getMethod ( java . lang . reflect . Method m ) { } }

implementation: return new Method ( m . getName ( ) , Type . getMethodDescriptor ( m ) ) ;


signature:
public class Method { /** * Creates a new { @ link Method } .
 * @ param c
 * a java . lang . reflect constructor descriptor
 * @ return a { @ link Method } corresponding to the given Java constructor
 * declaration . */
public static Method getMethod ( java . lang . reflect . Constructor < ? > c ) { } }

implementation: return new Method ( "<init>" , Type . getConstructorDescriptor ( c ) ) ;


signature:
public class Method { /** * Returns a { @ link Method } corresponding to the given Java method
 * declaration .
 * @ param method
 * a Java method declaration , without argument names , of the form
 * " returnType name ( argumentType1 , . . . argumentTypeN ) " , where
 * the types are in plain Java ( e . g . " int " , " float " ,
 * " java . util . List " , . . . ) . Classes of the java . lang package may
 * be specified by their unqualified name , depending on the
 * defaultPackage argument ; all other classes names must be fully
 * qualified .
 * @ param defaultPackage
 * true if unqualified class names belong to the default package ,
 * or false if they correspond to java . lang classes . For instance
 * " Object " means " Object " if this option is true , or
 * " java . lang . Object " otherwise .
 * @ return a { @ link Method } corresponding to the given Java method
 * declaration .
 * @ throws IllegalArgumentException
 * if < code > method < / code > could not get parsed . */
public static Method getMethod ( final String method , final boolean defaultPackage ) throws IllegalArgumentException { } }

implementation: int space = method . indexOf ( ' ' ) ; int start = method . indexOf ( '(' , space ) + 1 ; int end = method . indexOf ( ')' , start ) ; if ( space == - 1 || start == - 1 || end == - 1 ) { throw new IllegalArgumentException ( ) ; } String returnType = method . substring ( 0 , space ) ; String methodName = method . substring ( space + 1 , start - 1 ) . trim ( ) ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( '(' ) ; int p ; do { String s ; p = method . indexOf ( ',' , start ) ; if ( p == - 1 ) { s = map ( method . substring ( start , end ) . trim ( ) , defaultPackage ) ; } else { s = map ( method . substring ( start , p ) . trim ( ) , defaultPackage ) ; start = p + 1 ; } sb . append ( s ) ; } while ( p != - 1 ) ; sb . append ( ')' ) ; sb . append ( map ( returnType , defaultPackage ) ) ; return new Method ( methodName , sb . toString ( ) ) ;


signature:
public class StructureConvert { /** * 重建新对象 */
protected void DLR ( String path , Object object ) { } }

implementation: if ( relation . containsKey ( path ) ) { List < String > dests = relation . get ( path ) ; for ( String dest : dests ) { if ( dest . equals ( "" ) ) { structure . put ( path , object , arrayIndex ) ; continue ; } structure . put ( dest , object , arrayIndex ) ; } }


signature:
public class StructureConvert { /** * 解析配置信息
 * @ param obj
 * @ param path */
private void loadRelation ( Object obj , String path ) { } }

implementation: if ( obj instanceof Map ) { loadMapRelation ( ( Map < ? , ? > ) obj , path ) ; } else if ( obj instanceof List ) { loadListRelation ( ( List < ? > ) obj , path ) ; } else { throw new RuntimeException ( "无法识别的类型!" ) ; }


signature:
public class StructureConvert { /** * 解析List配置信息
 * @ param obj
 * @ param path */
@ SuppressWarnings ( "unchecked" ) private void loadListRelation ( List < ? > obj , String path ) { } }

implementation: if ( obj . size ( ) <= 0 ) { return ; } if ( obj . get ( 0 ) instanceof String ) { relation . put ( path , ( List < String > ) obj ) ; return ; } loadRelation ( obj . get ( 0 ) , path + "[]" ) ;


signature:
public class StructureConvert { /** * 解析MAP配置信息
 * @ param obj
 * @ param path */
private void loadMapRelation ( Map < ? , ? > obj , String path ) { } }

implementation: for ( Object key : obj . keySet ( ) ) { Object val = obj . get ( key ) ; if ( val instanceof String ) { relation . put ( path + space ( path ) + key . toString ( ) , Lang . list ( val . toString ( ) ) ) ; continue ; } loadRelation ( obj . get ( key ) , path + space ( path ) + key . toString ( ) ) ; }


signature:
public class Daos { /** * 获取colName所在的行数
 * @ param meta
 * 从连接中取出的ResultSetMetaData
 * @ param colName
 * 字段名
 * @ return 所在的索引 , 如果不存在就抛出异常
 * @ throws SQLException
 * 指定的colName找不到 */
public static int getColumnIndex ( ResultSetMetaData meta , String colName ) throws SQLException { } }

implementation:
if ( meta == null ) return 0 ; int columnCount = meta . getColumnCount ( ) ; for ( int i = 1 ; i <= columnCount ; i ++ ) if ( meta . getColumnName ( i ) . equalsIgnoreCase ( colName ) ) return i ; // TODO 尝试一下meta . getColumnLabel ?
log . debugf ( "Can not find @Column(%s) in table/view (%s)" , colName , meta . getTableName ( 1 ) ) ; throw Lang . makeThrow ( SQLException . class , "Can not find @Column(%s)" , colName ) ;


signature:
public class Daos { /** * 是不是数值字段
 * @ param meta
 * 从连接中取出的ResultSetMetaData
 * @ param index
 * 字段索引
 * @ return 如果是就返回true
 * @ throws SQLException
 * 指定的索引不存在 */
public static boolean isIntLikeColumn ( ResultSetMetaData meta , int index ) throws SQLException { } }

implementation: switch ( meta . getColumnType ( index ) ) { case Types . BIGINT : case Types . INTEGER : case Types . SMALLINT : case Types . TINYINT : case Types . NUMERIC : return true ; } return false ;


signature:
public class Daos { /** * 填充记录总数
 * @ param pager
 * 分页对象 , 如果为null就不进行任何操作
 * @ param dao
 * Dao实例
 * @ param entityType
 * 实体类 , 可以通过dao . getEntity获取
 * @ param cnd
 * 查询条件
 * @ return 传入的Pager参数 */
public static Pager updatePagerCount ( Pager pager , Dao dao , Class < ? > entityType , Condition cnd ) { } }

implementation: if ( null != pager ) { pager . setRecordCount ( dao . count ( entityType , cnd ) ) ; } return pager ;


signature:
public class Daos { /** * 填充记录总数
 * @ param pager
 * 分页对象 , 如果为null就不进行任何操作
 * @ param dao
 * Dao实例
 * @ param tableName
 * 表名
 * @ param cnd
 * 查询条件
 * @ return 传入的Pager参数 */
public static Pager updatePagerCount ( Pager pager , Dao dao , String tableName , Condition cnd ) { } }

implementation: if ( null != pager ) { pager . setRecordCount ( dao . count ( tableName , cnd ) ) ; } return pager ;


signature:
public class Daos { /** * 根据sql查询特定的记录 , 并转化为指定的类对象
 * @ param dao
 * Dao实例
 * @ param klass
 * Pojo类
 * @ param sql _ str
 * sql语句
 * @ return 查询结果 */
public static < T > List < T > queryList ( Dao dao , Class < T > klass , String sql_str ) { } }

implementation: Sql sql = Sqls . create ( sql_str ) . setCallback ( Sqls . callback . entities ( ) ) . setEntity ( dao . getEntity ( klass ) ) ; dao . execute ( sql ) ; return sql . getList ( klass ) ;


signature:
public class Daos { /** * 执行sql和callback
 * @ param dao
 * Dao实例
 * @ param sql _ str
 * sql语句
 * @ param callback
 * sql回调
 * @ return 回调的返回值 */
public static Object query ( Dao dao , String sql_str , SqlCallback callback ) { } }

implementation: Sql sql = Sqls . create ( sql_str ) . setCallback ( callback ) ; dao . execute ( sql ) ; return sql . getResult ( ) ;


signature:
public class Daos { /** * 在同一个事务内查询对象及关联对象
 * @ param dao
 * Dao实例
 * @ param classOfT
 * 指定的Pojo类
 * @ param cnd
 * 查询条件
 * @ param pager
 * 分页语句
 * @ param regex
 * 需要查出的关联对象 , 可以参阅dao . fetchLinks
 * @ return 查询结果 */
public static < T > List < T > queryWithLinks ( final Dao dao , final Class < T > classOfT , final Condition cnd , final Pager pager , final String regex ) { } }

implementation: Molecule < List < T > > molecule = new Molecule < List < T > > ( ) { public void run ( ) { List < T > list = dao . query ( classOfT , cnd , pager ) ; dao . fetchLinks ( list , regex ) ; setObj ( list ) ; } } ; return Trans . exec ( molecule ) ;


signature:
public class Daos { /** * 根据Pojo生成数据字典 , zdoc格式 */
public static StringBuilder dataDict ( Dao dao , String ... packages ) { } }

implementation:
StringBuilder sb = new StringBuilder ( ) ; List < Class < ? > > ks = new ArrayList < Class < ? > > ( ) ; for ( String packageName : packages ) { ks . addAll ( Scans . me ( ) . scanPackage ( packageName ) ) ; } Iterator < Class < ? > > it = ks . iterator ( ) ; while ( it . hasNext ( ) ) { Class < ? > klass = it . next ( ) ; if ( Mirror . me ( klass ) . getAnnotation ( Table . class ) == null ) it . remove ( ) ; } // log . infof ( " Found % d table class " , ks . size ( ) ) ;
JdbcExpert exp = dao . getJdbcExpert ( ) ; Entity < ? > entity = null ; String line = "-------------------------------------------------------------------\n" ; sb . append ( "#title:数据字典\n" ) ; sb . append ( "#author:wendal\n" ) ; sb . append ( "#index:0,1\n" ) . append ( line ) ; for ( Class < ? > klass : ks ) { sb . append ( line ) ; entity = dao . getEntity ( klass ) ; sb . append ( "表名 " ) . append ( entity . getTableName ( ) ) . append ( "\n\n" ) ; if ( ! Strings . isBlank ( entity . getTableComment ( ) ) ) sb . append ( "表注释: " ) . append ( entity . getTableComment ( ) ) ; sb . append ( "\t" ) . append ( "Java类名 " ) . append ( klass . getName ( ) ) . append ( "\n\n" ) ; sb . append ( "\t||序号||列名||数据类型||主键||非空||默认值||java属性名||java类型||注释||\n" ) ; int index = 1 ; for ( MappingField field : entity . getMappingFields ( ) ) { String dataType = exp . evalFieldType ( field ) ; sb . append ( "\t||" ) . append ( index ++ ) . append ( "||" ) . append ( field . getColumnName ( ) ) . append ( "||" ) . append ( dataType ) . append ( "||" ) . append ( field . isPk ( ) ) . append ( "||" ) . append ( field . isNotNull ( ) ) . append ( "||" ) . append ( field . getDefaultValue ( null ) == null ? " " : field . getDefaultValue ( null ) ) . append ( "||" ) . append ( field . getName ( ) ) . append ( "||" ) . append ( field . getTypeClass ( ) . getName ( ) ) . append ( "||" ) . append ( field . getColumnComment ( ) == null ? " " : field . getColumnComment ( ) ) . append ( "||\n" ) ; } } return sb ;


signature:
public class Daos { /** * 查询sql并把结果放入传入的class组成的List中 */
public static < T > List < T > query ( Dao dao , Class < T > classOfT , String sql , Condition cnd , Pager pager ) { } }

implementation: Sql sql2 = Sqls . queryEntity ( sql ) ; sql2 . setEntity ( dao . getEntity ( classOfT ) ) ; sql2 . setCondition ( cnd ) ; sql2 . setPager ( pager ) ; dao . execute ( sql2 ) ; return sql2 . getList ( classOfT ) ;


signature:
public class Daos { /** * 查询某sql的结果条数 . 请使用Sql接口的版本 */
@ Deprecated public static long queryCount ( Dao dao , String sql ) { } }

implementation: String tmpTable = "as _nutz_tmp" ; if ( dao . meta ( ) . isDB2 ( ) ) tmpTable = "as nutz_tmp_" + R . UU32 ( ) ; else if ( dao . meta ( ) . isOracle ( ) ) tmpTable = "" ; else tmpTable += "_" + R . UU32 ( ) ; Sql sql2 = Sqls . fetchLong ( "select count(1) from (" + sql + ")" + tmpTable ) ; dao . execute ( sql2 ) ; return sql2 . getLong ( ) ;


signature:
public class Daos { /** * 查询某sql的结果条数
 * @ param dao 用于执行该count方法的dao实例
 * @ param sql 原本的Sql对象 , 将复制其sql语句 , 变量和参数表 . */
public static long queryCount ( Dao dao , Sql sql ) { } }

implementation: String tmpTable = "as _nutz_tmp" ; if ( dao . meta ( ) . isDB2 ( ) ) tmpTable = "as nutz_tmp_" + R . UU32 ( ) ; else if ( dao . meta ( ) . isOracle ( ) ) tmpTable = "" ; else tmpTable += "_" + R . UU32 ( ) ; Sql sql2 = Sqls . fetchLong ( "select count(1) from (" + sql . getSourceSql ( ) + ")" + tmpTable ) ; sql2 . setEntity ( sql . getEntity ( ) ) ; for ( String key : sql . params ( ) . keys ( ) ) { sql2 . setParam ( key , sql . params ( ) . get ( key ) ) ; } for ( String key : sql . vars ( ) . keys ( ) ) { sql2 . setVar ( key , sql . vars ( ) . get ( key ) ) ; } return dao . execute ( sql2 ) . getLong ( ) ;


signature:
public class Daos { /** * 执行一个特殊的Chain ( 事实上普通Chain也能执行 , 但不建议使用 )
 * @ see org . nutz . dao . Chain # addSpecial ( String , Object ) */
@ SuppressWarnings ( { } }

implementation: "rawtypes" } ) public static void insertBySpecialChain ( Dao dao , Entity en , String tableName , Chain chain ) { if ( en != null ) tableName = en . getTableName ( ) ; if ( tableName == null ) throw Lang . makeThrow ( DaoException . class , "tableName and en is NULL !!" ) ; final StringBuilder sql = new StringBuilder ( "INSERT INTO " ) . append ( tableName ) . append ( " (" ) ; StringBuilder _value_places = new StringBuilder ( " VALUES(" ) ; final List < Object > values = new ArrayList < Object > ( ) ; final List < ValueAdaptor > adaptors = new ArrayList < ValueAdaptor > ( ) ; Chain head = chain . head ( ) ; while ( head != null ) { String colName = head . name ( ) ; MappingField mf = null ; if ( en != null ) { mf = en . getField ( colName ) ; if ( mf != null ) colName = mf . getColumnNameInSql ( ) ; } sql . append ( colName ) ; if ( head . special ( ) ) { _value_places . append ( head . value ( ) ) ; } else { if ( en != null ) mf = en . getField ( head . name ( ) ) ; _value_places . append ( "?" ) ; values . add ( head . value ( ) ) ; ValueAdaptor adaptor = head . adaptor ( ) ; if ( adaptor == null ) { if ( mf != null && mf . getAdaptor ( ) != null ) adaptor = mf . getAdaptor ( ) ; else adaptor = Jdbcs . getAdaptorBy ( head . value ( ) ) ; } adaptors . add ( adaptor ) ; } head = head . next ( ) ; if ( head != null ) { sql . append ( ", " ) ; _value_places . append ( ", " ) ; } } sql . append ( ")" ) ; _value_places . append ( ")" ) ; sql . append ( _value_places ) ; if ( log . isDebugEnabled ( ) ) log . debug ( sql ) ; dao . run ( new ConnCallback ( ) { public void invoke ( Connection conn ) throws Exception { PreparedStatement ps = conn . prepareStatement ( sql . toString ( ) ) ; try { for ( int i = 0 ; i < values . size ( ) ; i ++ ) adaptors . get ( i ) . set ( ps , values . get ( i ) , i + 1 ) ; ps . execute ( ) ; } finally { Daos . safeClose ( ps ) ; } } } ) ;


signature:
public class Daos { /** * 为特定package下带 @ Table注解的类调用dao . create ( XXX . class , force ) , 批量建表
 * @ param dao
 * Dao实例
 * @ param oneClzInPackage
 * 使用package中某一个class文件 , 可以防止写错pkgName
 * @ param force
 * 如果表存在 , 是否先删后建 */
public static void createTablesInPackage ( Dao dao , Class < ? > oneClzInPackage , boolean force ) { } }

implementation: createTablesInPackage ( dao , oneClzInPackage . getPackage ( ) . getName ( ) , force ) ;


signature:
public class Daos { /** * 为特定package下带 @ Table注解的类调用dao . create ( XXX . class , force ) ,
 * 批量建表 , 优先建立带 @ ManyMany的表
 * @ param dao
 * Dao实例
 * @ param packageName
 * package名称 , 自动包含子类
 * @ param force
 * 如果表存在 , 是否先删后建
 * @ param filter
 * 定义过滤器排除不需要自动创建的表 */
public static void createTablesInPackage ( final Dao dao , String packageName , boolean force , TablesFilter filter ) { } }

implementation: List < Class < ? > > list = new ArrayList < Class < ? > > ( ) ; for ( Class < ? > klass : Scans . me ( ) . scanPackage ( packageName ) ) { Table table = Mirror . me ( klass ) . getAnnotation ( Table . class ) ; if ( table != null && filter . match ( klass , table ) ) list . add ( klass ) ; } createTables ( dao , list , force ) ;


signature:
public class Daos { /** * 创建一个带FieldFilter的Dao代理实例 . 注意 , 为避免出错 , 生成的Dao对象不应该传递到其他方法去 .
 * @ param dao
 * 原始的Dao实例
 * @ param filter
 * 字段过滤器
 * @ return 带FieldFilter的Dao代理实例 */
public static Dao ext ( Dao dao , FieldFilter filter ) { } }

implementation: return ext ( dao , filter , null ) ;


signature:
public class Daos { /** * 创建一个带TableName的Dao代理实例 . 注意 , 为避免出错 , 生成的Dao对象不应该传递到其他方法去 .
 * @ param dao
 * 原始的Dao实例
 * @ param tableName
 * 动态表名上下文
 * @ return 带TableName的Dao代理实例 */
public static Dao ext ( Dao dao , Object tableName ) { } }

implementation: return ext ( dao , null , tableName ) ;


signature:
public class Daos { /** * 同时进行字段过滤和动态表名封装
 * @ param dao
 * Dao实例
 * @ param filter
 * 字段过滤
 * @ param tableName
 * 动态表名参数
 * @ return 封装好的Dao实例 */
public static Dao ext ( Dao dao , FieldFilter filter , Object tableName ) { } }

implementation: if ( tableName == null && filter == null ) return dao ; ExtDaoInvocationHandler handler = new ExtDaoInvocationHandler ( dao , filter , tableName ) ; return ( Dao ) Proxy . newProxyInstance ( dao . getClass ( ) . getClassLoader ( ) , iz , handler ) ;


signature:
public class Daos { /** * 为数据表自动增减字段
 * @ param dao
 * Dao实例
 * @ param klass
 * 映射Pojo
 * @ param add
 * 是否允许添加字段
 * @ param del
 * 是否允许删除字段
 * @ param checkIndex
 * 是否检查索引 */
public static void migration ( Dao dao , final Class < ? > klass , final boolean add , final boolean del , boolean checkIndex ) { } }

implementation: migration ( dao , klass , add , del , checkIndex , null ) ;


signature:
public class Daos { /** * 为数据表自动增减字段
 * @ param dao
 * Dao实例
 * @ param klass
 * 映射Pojo
 * @ param add
 * 是否允许添加字段
 * @ param del
 * 是否允许删除字段
 * @ param tableName
 * 动态表名上下文 */
public static void migration ( Dao dao , final Class < ? > klass , final boolean add , final boolean del , Object tableName ) { } }

implementation: migration ( dao , klass , add , del , false , tableName ) ;


signature:
public class Daos { /** * 为数据表自动增减字段
 * @ param dao
 * Dao实例
 * @ param klass
 * 映射Pojo
 * @ param add
 * 是否允许添加字段
 * @ param del
 * 是否允许删除字段
 * @ param checkIndex
 * 是否检查索引
 * @ param tableName
 * 动态表名上下文 */
public static void migration ( Dao dao , final Class < ? > klass , final boolean add , final boolean del , final boolean checkIndex , final Object tableName ) { } }

implementation: migration ( dao , dao . getEntity ( klass ) , add , del , checkIndex , tableName ) ;


signature:
public class Daos { /** * 为指定package及旗下package中带 @ Table注解的Pojo执行migration
 * @ param dao
 * Dao实例
 * @ param packageName
 * 指定的package名称
 * @ param add
 * 是否允许添加字段
 * @ param del
 * 是否允许删除字段
 * @ param checkIndex
 * 是否检查索引
 * @ param nameTable
 * 动态表名上下文 */
public static void migration ( Dao dao , String packageName , boolean add , boolean del , boolean checkIndex , Object nameTable ) { } }

implementation: for ( Class < ? > klass : Scans . me ( ) . scanPackage ( packageName ) ) { if ( Mirror . me ( klass ) . getAnnotation ( Table . class ) != null ) { migration ( dao , klass , add , del , checkIndex , nameTable ) ; } }


signature:
public class Daos { /** * 为指定package及旗下package中带 @ Table注解的Pojo执行migration
 * @ param dao
 * Dao实例
 * @ param packageName
 * 指定的package名称
 * @ param add
 * 是否允许添加字段
 * @ param del
 * 是否允许删除字段
 * @ param nameTable
 * 动态表名上下文 */
public static void migration ( Dao dao , String packageName , boolean add , boolean del , Object nameTable ) { } }

implementation: migration ( dao , packageName , add , del , true , nameTable ) ;


signature:
public class Daos { /** * 检查分表中是否有字段变化 提示
 * @ param dao
 * Dao实例
 * @ param tableName
 * 动态表名上下文
 * @ param clsType
 * 映射Pojo */
public static void checkTableColumn ( Dao dao , Object tableName , final Class < ? > clsType ) { } }

implementation: final NutDao d = ( NutDao ) dao ; final JdbcExpert expert = d . getJdbcExpert ( ) ; ext ( d , tableName ) . run ( new ConnCallback ( ) { public void invoke ( Connection conn ) throws Exception { Entity < ? > en = d . getEntity ( clsType ) ; expert . setupEntityField ( conn , en ) ; } } ) ;


signature:
public class Daos { /** * 获取动态表的表名
 * @ param dao
 * Dao实例
 * @ param klass
 * 映射Pojo
 * @ param target
 * 参考对象 */
public static String getTableName ( Dao dao , Class < ? > klass , Object target ) { } }

implementation: return getTableName ( dao , dao . getEntity ( klass ) , target ) ;


signature:
public class Daos { /** * 获取动态表的表名
 * @ param dao
 * Dao实例
 * @ param en
 * Pojo的数据库实体
 * @ param target
 * 参考对象 */
public static String getTableName ( Dao dao , final Entity < ? > en , Object target ) { } }

implementation: if ( target == null ) return en . getTableName ( ) ; final String [ ] name = new String [ 1 ] ; TableName . run ( target , new Runnable ( ) { public void run ( ) { name [ 0 ] = en . getTableName ( ) ; } } ) ; return name [ 0 ] ;


signature:
public class Daos { /** * 获取SQL2003关键字 */
public static Set < String > sql2003Keywords ( ) { } }


signature:
public class SocketActionTable { /** * 根据输入的行 , 得到一个动作执行对象
 * @ param line
 * 输入的行
 * @ return 动作执对象 , null 表示没有动作可以匹配这一行 */
public SocketAction get ( String line ) { } }

implementation:
// 是否有精确匹配
SocketAction sa = map . get ( line ) ; if ( null != sa ) return sa ; // 用正则式匹配
for ( int i = 0 ; i < nots . length ; i ++ ) { if ( ptns [ i ] . matcher ( line ) . find ( ) && ! nots [ i ] ) { return aary [ i ] ; } else if ( nots [ i ] ) { return aary [ i ] ; } } // 啥都没有 - _ - !
return null ;


signature:
public class RawView { /** * 字符数组 */
else if ( obj instanceof char [ ] ) { } }

implementation: Writer writer = resp . getWriter ( ) ; writer . write ( ( char [ ] ) obj ) ; writer . flush ( ) ;


signature:
public class RawView { /** * 二进制流 */
else if ( obj instanceof InputStream ) { } }

implementation: OutputStream out = resp . getOutputStream ( ) ; Streams . writeAndClose ( out , ( InputStream ) obj ) ;


signature:
public class AbstractAdaptor { /** * 这是最后的大招了 , 查一下形参的名字 , 作为 @ Param ( " 形参名 " ) 进行处理 */
protected ParamInjector paramNameInject ( Method method , int index ) { } }

implementation: if ( ! Lang . isAndroid ) { String paramName = getParamRealName ( index ) ; if ( paramName != null ) { Class < ? > type = argTypes [ index ] ; if ( type . isArray ( ) ) { return new ArrayInjector ( paramName , null , type , null , null , true ) ; } if ( Modifier . isInterface ( type . getModifiers ( ) ) ) return new VoidInjector ( ) ; return new NameInjector ( paramName , null , argTypes [ index ] , null , null ) ; } else if ( log . isInfoEnabled ( ) ) log . infof ( "Complie without debug info? can't deduce param name. fail back to PathArgInjector!! index=%d > %s" , index , method ) ; } return new PathArgInjector ( method . getParameterTypes ( ) [ index ] ) ;


signature:
public class El { /** * 解析预编译后的EL表达式 */
public Object eval ( Context context ) { } }

implementation: if ( rc == null ) { throw new ElException ( "没有进行预编译!" ) ; } return rc . calculate ( context ) ;


signature:
public class NutMap { /** * 设置一个字段 , 如果值为 null 则表示移除
 * @ param key
 * @ param v */
@ Override public void setOrRemove ( String key , Object v ) { } }

implementation: if ( null == v ) { this . remove ( key ) ; } else { this . put ( key , v ) ; }


signature:
public class NutMap { /** * 从 Map 里挑选一些键生成一个新的 Map
 * @ param keys
 * @ return 新 Map */
@ Override public NutMap pick ( String ... keys ) { } }

implementation: if ( keys . length == 0 ) return new NutMap ( ) ; NutMap re = new NutMap ( ) ; for ( String key : keys ) { Object val = this . get ( key ) ; if ( null != val ) re . put ( key , val ) ; } return re ;


signature:
public class NutMap { /** * 从 Map 里挑选一些键生成一个新的 Map , 自己同时删除这些键
 * @ param keys
 * @ return 新 Map */
@ Override public NutMap pickAndRemove ( String ... keys ) { } }

implementation: if ( keys . length == 0 ) return new NutMap ( ) ; NutMap re = new NutMap ( ) ; for ( String key : keys ) { Object val = this . remove ( key ) ; re . put ( key , val ) ; } return re ;


signature:
public class NutMap { /** * 从 Map 里挑选一些键生成一个新的 Map
 * @ param regex
 * 匹配键的正则表达式 , " ! " 开头 , 表示取反
 * @ return 新 Map */
@ Override public NutMap pickBy ( String regex ) { } }

implementation: if ( Strings . isBlank ( regex ) ) return this . duplicate ( ) ; boolean isNot = regex . startsWith ( "!" ) ; Pattern p = Regex . getPattern ( isNot ? regex . substring ( 1 ) : regex ) ; return pickBy ( p , isNot ) ;


signature:
public class NutMap { /** * 从 Map 里挑选一些键生成一个新的 Map
 * @ param p
 * 匹配键的正则表达式 , null 不会匹配任何一个键
 * @ param isNot
 * true 表示被匹配上的会被忽略 , false 表示被匹配上的才加入到返回的集合里
 * @ return 新 Map */
@ Override public NutMap pickBy ( Pattern p , boolean isNot ) { } }

implementation:
// 一定不匹配
if ( null == p ) { return isNot ? this . duplicate ( ) : new NutMap ( ) ; } // 挑选
NutMap re = new NutMap ( ) ; for ( Map . Entry < String , Object > en : this . entrySet ( ) ) { String key = en . getKey ( ) ; boolean matched = p . matcher ( key ) . find ( ) ; if ( matched ) { if ( ! isNot ) { re . put ( key , en . getValue ( ) ) ; } } else if ( isNot ) { re . put ( key , en . getValue ( ) ) ; } } // 返回
return re ;


signature:
public class NutMap { /** * 就是 pickAndRemoveBy 的一个便利写法
 * @ param regex
 * 正则表达式 , ! 开头表示取反
 * @ return 新 Map
 * @ see # pickAndRemoveBy ( Pattern , boolean ) */
public NutMap pickAndRemoveBy ( String regex ) { } }

implementation: if ( Strings . isBlank ( regex ) ) return new NutMap ( ) ; boolean isNot = regex . startsWith ( "!" ) ; Pattern p = Pattern . compile ( isNot ? regex . substring ( 1 ) : regex ) ; return pickAndRemoveBy ( p , isNot ) ;


signature:
public class NutMap { /** * 从 Map 里挑选一些键生成一个新的 Map , 自己同时删除这些键
 * @ param p
 * 匹配键的正则表达式 , null 不会匹配任何一个键
 * @ param isNot
 * true 表示被匹配上的会被忽略 , false 表示被匹配上的才加入到返回的集合里
 * @ return 新 Map */
@ Override public NutMap pickAndRemoveBy ( Pattern p , boolean isNot ) { } }

implementation:
// 一定不匹配
if ( null == p ) { if ( isNot ) { NutMap re = this . duplicate ( ) ; this . clear ( ) ; return re ; } else { return new NutMap ( ) ; } } // 挑选
NutMap re = new NutMap ( ) ; List < String > delKeys = new ArrayList < String > ( this . size ( ) ) ; for ( Map . Entry < String , Object > en : this . entrySet ( ) ) { String key = en . getKey ( ) ; boolean matched = p . matcher ( key ) . find ( ) ; if ( matched ) { if ( ! isNot ) { delKeys . add ( key ) ; re . put ( key , en . getValue ( ) ) ; } } else if ( isNot ) { delKeys . add ( key ) ; re . put ( key , en . getValue ( ) ) ; } } // 删除 Key
for ( String key : delKeys ) this . remove ( key ) ; // 返回
return re ;


signature:
public class NutMap { /** * 从 Map 里将指定的键过滤 , 生成一个新的 Map
 * @ param keys
 * @ return 新 Map */
@ Override public NutMap omit ( String ... keys ) { } }

implementation: NutMap re = new NutMap ( ) ; for ( Map . Entry < String , Object > en : this . entrySet ( ) ) { String key = en . getKey ( ) ; if ( ! Lang . contains ( keys , key ) ) { re . put ( key , en . getValue ( ) ) ; } } return re ;


signature:
public class NutMap { /** * 如果一个键的值无效 ( has ( key ) 返回 false ) , 那么为其设置默认值
 * @ param key
 * @ param dft
 * @ return 自身以便链式赋值 */
@ Override public NutMap putDefault ( String key , Object dft ) { } }

implementation: if ( ! this . has ( key ) ) { this . put ( key , dft ) ; } return this ;


signature:
public class NutMap { /** * 为 Map 增加一个名值对 。 如果同名已经有值了 , 那么会将两个值合并成一个列表
 * @ param key
 * @ param value */
@ Override @ SuppressWarnings ( "unchecked" ) public NutMap addv ( String key , Object value ) { } }

implementation: Object obj = get ( key ) ; if ( null == obj ) { put ( key , value ) ; } else if ( obj instanceof List < ? > ) ( ( List < Object > ) obj ) . add ( value ) ; else { List < Object > list = new LinkedList < Object > ( ) ; list . add ( obj ) ; list . add ( value ) ; put ( key , list ) ; } return this ;


signature:
public class NutMap { /** * 为 Map 增加一个名值对 。 强制设置为一个列表 , 如果有同名则合并
 * @ param key
 * @ param value */
@ Override @ SuppressWarnings ( "unchecked" ) public NutMap addv2 ( String key , Object value ) { } }

implementation: List < Object > list = ( List < Object > ) get ( key ) ; if ( null == list ) { list = new LinkedList < Object > ( ) ; put ( key , list ) ; } list . add ( value ) ; return this ;


signature:
public class NutMap { /** * 向某个键增加一组值 , 如果原来就有值 , 是集合的话 , 会被合并 , 否则原来的值用列表包裹后再加入新值
 * @ param key
 * @ param values
 * 值列表
 * @ return 自身 */
@ SuppressWarnings ( { } }

implementation:
"rawtypes" , "unchecked" } ) public < T > NutMap pushTo ( String key , T ... values ) { if ( null != values && values . length > 0 ) { Object v = get ( key ) ; // 不存在的话 , 增加列表
if ( null == v ) { List < Object > list = new LinkedList < Object > ( ) ; for ( Object val : values ) list . add ( val ) ; this . put ( key , list ) ; } // 如果是集合的话 , 就增加
else if ( v instanceof Collection ) { for ( Object val : values ) ( ( Collection ) v ) . add ( val ) ; } // 否则将原来的值变成列表再增加
else { List < Object > list = new LinkedList < Object > ( ) ; list . add ( v ) ; for ( Object val : values ) list . add ( val ) ; this . put ( key , list ) ; } } // 返回自身以便链式赋值
return this ;


signature:
public class NutMap { /** * 是 pushTo 函数的另一个变种 ( 可以接受集合 )
 * @ param key
 * @ param values
 * 值列表
 * @ return 自身
 * @ see # pushTo ( String , Collection ) */
@ SuppressWarnings ( { } }

implementation:
"rawtypes" , "unchecked" } ) public NutMap pushTo ( String key , Collection < ? > values ) { if ( null != values && values . size ( ) > 0 ) { Object v = get ( key ) ; // 不存在的话 , 增加列表
if ( null == v ) { List < Object > list = new LinkedList < Object > ( ) ; list . addAll ( values ) ; this . put ( key , list ) ; } // 如果是集合的话 , 就增加
else if ( v instanceof Collection ) { ( ( Collection ) v ) . addAll ( values ) ; } // 否则将原来的值变成列表再增加
else { List < Object > list = new LinkedList < Object > ( ) ; list . add ( v ) ; list . addAll ( values ) ; this . put ( key , list ) ; } } // 返回自身以便链式赋值
return this ;


signature:
public class NutMap { /** * 相当于 mergeWith ( map , false )
 * @ see # mergeWith ( Map , boolean ) */
@ Override public NutMap mergeWith ( Map < String , Object > map ) { } }

implementation: return this . mergeWith ( map , false ) ;


signature:
public class NutMap { /** * 与一个给定的 Map 融合 , 如果有子 Map 递归
 * @ param map
 * 要合并进来的 Map
 * @ param onlyAbsent
 * true 表示只有没有 key 才设置值
 * @ return 自身以便链式赋值 */
@ Override @ SuppressWarnings ( "unchecked" ) public NutMap mergeWith ( Map < String , Object > map , boolean onlyAbsent ) { } }

implementation:
for ( Map . Entry < String , Object > en : map . entrySet ( ) ) { String key = en . getKey ( ) ; Object val = en . getValue ( ) ; if ( null == key || null == val ) continue ; Object myVal = this . get ( key ) ; // 如果两边都是 Map , 则融合
if ( null != myVal && myVal instanceof Map && val instanceof Map ) { Map < String , Object > m0 = ( Map < String , Object > ) myVal ; Map < String , Object > m1 = ( Map < String , Object > ) val ; NutMap m2 = NutMap . WRAP ( m0 ) . mergeWith ( m1 , onlyAbsent ) ; // 搞出了新 Map , 设置一下
if ( m2 != m0 ) this . put ( key , m2 ) ; } // 只有没有的时候才设置
else if ( onlyAbsent ) { this . setnx ( key , val ) ; } // 否则直接替换
else { this . put ( key , val ) ; } } return this ;


signature:
public class NutMap { /** * 与JDK8 + 的 putIfAbsent ( key , val ) 一致 , 当且仅当值不存在时设置进去 , 但与putIfAbsent返回值有不一样
 * @ param key
 * @ param val
 * @ return 当前的NutMap实例 */
@ Override public NutMap setnx ( String key , Object val ) { } }

implementation: if ( ! containsKey ( key ) ) setv ( key , val ) ; return this ;


signature:
public class NutMap { /** * 将一个集合与自己补充 ( 相当于针对每个 key 调用 setnx )
 * @ param map
 * 集合
 * @ return 自身
 * @ see # setnx ( String , Object ) */
@ Override public NutMap setnxAll ( Map < String , Object > map ) { } }

implementation: if ( null != map && map . size ( ) > 0 ) { for ( Map . Entry < String , Object > en : map . entrySet ( ) ) { this . setnx ( en . getKey ( ) , en . getValue ( ) ) ; } } return this ;


signature:
public class NutMap { /** * 获取对应的值 , 若不存在 , 用factory创建一个 , 然后设置进去 , 返回之
 * @ param key
 * @ param factory
 * 若不存在的话用于生成实例
 * @ return 已存在的值或新的值 */
@ Override @ SuppressWarnings ( "unchecked" ) public < T > T getOrBorn ( String key , Borning < T > factory ) { } }

implementation: T t = ( T ) get ( key ) ; if ( t == null ) { t = factory . born ( key ) ; put ( key , t ) ; } return t ;


signature:
public class NutMap { /** * 将自身作为一个条件 , 看看给定的 Map 是否全部满足这个条件
 * 注意 , 字符串型的值有下列意义
 * < ul >
 * < li > " ^ xxxxx " : 正则表达式
 * < li > " " : 相当于 Blank
 * < / ul >
 * @ param map
 * 给定的 Map
 * @ return 是否匹配 */
@ Override public boolean match ( Map < String , Object > map ) { } }

implementation:
// 空 map 一定是不匹配的
if ( null == map ) return false ; // 本 Map 如果没值 , 表示全匹配
if ( this . size ( ) == 0 ) return true ; // 逐个匹配键
for ( Map . Entry < String , Object > en : this . entrySet ( ) ) { String key = en . getKey ( ) ; Object mtc = en . getValue ( ) ; // null 表示对方不能包括这个键
if ( null == mtc ) { if ( map . containsKey ( key ) ) return false ; } // 其他的值 , 匹配一下
else { Object val = map . get ( key ) ; if ( ! __match_val ( mtc , val ) ) { return false ; } } } // 都检查过了 . . .
return true ;


signature:
public class NutMap { /** * 指定key进行增操作 , 并返回结果
 * @ param key
 * @ param number
 * 数值
 * @ return 增后结果 */
public int intIncrement ( String key , int number ) { } }

implementation: int val = getInt ( key , 0 ) ; val += number ; setv ( key , val ) ; return val ;


signature:
public class NutMap { /** * 指定key进行减操作 , 并返回结果
 * @ param key
 * @ param number
 * 数值
 * @ return 减后结果 */
public int intDecrement ( String key , int number ) { } }

implementation: int val = getInt ( key , 0 ) ; val -= number ; setv ( key , val ) ; return val ;


signature:
public class NutMap { /** * 指定key进行增操作 , 并返回结果
 * @ param key
 * @ param number
 * 数值
 * @ return 增后结果 */
public long longIncrement ( String key , long number ) { } }

implementation: long val = getLong ( key , 0 ) ; val += number ; setv ( key , val ) ; return val ;


signature:
public class NutMap { /** * 指定key进行减操作 , 并返回结果
 * @ param key
 * @ param number
 * 数值
 * @ return 减后结果 */
public long longDecrement ( String key , long number ) { } }

implementation: long val = getLong ( key , 0 ) ; val -= number ; setv ( key , val ) ; return val ;


signature:
public class RingItem { /** * 试图从缓冲开头匹配 , 如果匹配失败 , 移动 ' r ' 并返回 false < br >
 * 如果匹配成功 , 则移动 ' l ' ( 匹配的内容不需要读取 ) 并返回 true
 * 这个函数 , 在 BufferRing 发现当前的环节点返回 ' > 0 ' 时 , 需要调用 next 的这个函数 , 看看是不是可以完整被匹配
 * @ param bs
 * 数组
 * @ param offs
 * 偏移量
 * @ return 本节点开头是否匹配剩余的部分 */
boolean matchHeadingWithRemain ( byte [ ] bs , int offs ) { } }

implementation:
int i = 0 ; for ( ; offs < bs . length ; offs ++ ) { if ( buffer [ i ++ ] != bs [ offs ] ) { r = i ; return false ; } } // Matched , skip it
l = i ; r = i ; nextmark = i ; return true ;


signature:
public class RingItem { /** * 从给定 offs 尽力匹配给出的数组 。
 * 需要注意的是 , 如果返回的是 > 0 的数 , 内部的标志位将被设置到第一个匹配字符 , 以便 DUMP 内容 。 < br >
 * 所以 , 如果下一个节点给出的结论是 - 1 , 但是 ' l ' 并不是0 , 那么说明这个匹配是失败的 , 需要将 本节点的 r 置到 max 处 。
 * 返回值
 * < ul >
 * < li > < b > - 1 < / b > - 全部被匹配
 * < li > < b > 0 < / b > - 未发现匹配
 * < li > < b > 大于 0 < / b > - 在缓冲的末尾发现匹配 , 但是没有匹配全 , 希望下一个节点继续从这个位置匹配
 * < / ul >
 * @ param bs
 * 数组
 * @ return - 1 , 0 或者 + n */
int mark ( byte [ ] bs , int [ ] fails ) { } }

implementation:
if ( ! isLoaded ) throw new MarkUnloadedRingItemException ( ) ; byte start = bs [ 0 ] ; for ( ; r < max ; r ++ ) { // 可能是边界 , 开始匹配
if ( buffer [ r ] == start ) { int re = 0 ; // 已经匹配长度
int j = r ; // 在内容值字节数组中的指针
while ( true ) { re ++ ; j ++ ; // 全部匹配
if ( re == bs . length ) { nextmark = j ; return - 1 ; } // 到达本项目的结尾 , 但是并不确定是否是边界 , 因为还未匹配完
// 因此暂时假设这个不会被匹配
if ( j == max ) { nextmark = max ; if ( isStreamEnd ) { r = max ; return 0 ; } return re ; } // 如果字符不相等 , 那么查看一下回退数组
// 如果回退到 0 , 则退出循环 , 因为这不是边界 , 否则继续循环匹配边界
if ( bs [ re ] != buffer [ j ] ) { re = fails [ re ] ; // 再次判断回退后位置 , 如果还是不相同 , 则退出循环
if ( bs [ re ] != buffer [ j ] ) { break ; } // 如果已经回退到了 0 , 你这么右边界置为 j , 表示从头搜索
else if ( re == 0 ) { r = j ; } // 否则扩大边界 , 并继续循环
else { r += re == 0 ? 1 : re ; } } } // make ' r ' jump to ' j '
r = j ; } } // Fail to found
nextmark = max ; return 0 ;


signature:
public class MapLoader { /** * { @ link ObjectLoadException } */
public IocObject load ( IocLoading loading , String name ) throws ObjectLoadException { } }

implementation:
Map < String , Object > m = getMap ( name ) ; if ( null == m ) throw new ObjectLoadException ( "Object '" + name + "' without define!" ) ; // If has parent
Object p = m . get ( "parent" ) ; if ( null != p ) { checkParents ( name ) ; IocObject parent = load ( loading , p . toString ( ) ) ; // create new map without parent
Map < String , Object > newMap = new HashMap < String , Object > ( ) ; for ( Entry < String , Object > en : m . entrySet ( ) ) { if ( "parent" . equals ( en . getKey ( ) ) ) continue ; newMap . put ( en . getKey ( ) , en . getValue ( ) ) ; } // Create self IocObject
IocObject self = loading . map2iobj ( newMap ) ; // Merge with parent
return Iocs . mergeWith ( self , parent ) ; } return loading . map2iobj ( m ) ;


signature:
public class MapLoader { /** * 检查继承关系 , 如果发现循环继承 , 或其他错误的继承关系 , 则抛出ObjectLoadException
 * @ param name
 * beanId
 * @ throws ObjectLoadException
 * if Inheritance errors or Inheritance cycle founded . */
@ SuppressWarnings ( "unchecked" ) private void checkParents ( String name ) throws ObjectLoadException { } }

implementation: ArrayList < String > list = new ArrayList < String > ( ) ; list . add ( name ) ; String currentParent = map . get ( name ) . get ( "parent" ) . toString ( ) ; while ( true ) { if ( currentParent == null ) break ; if ( list . contains ( currentParent ) ) throw Lang . makeThrow ( ObjectLoadException . class , "!!!Inheritance cycle! id = %s" , name ) ; list . add ( currentParent ) ; Object obj = map . get ( currentParent ) ; if ( obj != null && obj instanceof Map ) currentParent = ( String ) ( ( Map < String , Object > ) obj ) . get ( "parent" ) ; else throw Lang . makeThrow ( ObjectLoadException . class , "!!!Inheritance errors! id = %s" , name ) ; }


signature:
public class FastMethodFactory { /** * 生成两种FastClass实例 : 创建对象 , 和执行普通方法的 . 区分的点就是returnType是否为null . 模式为创建对象 , returnType总是null , 模式为执行方法 , returnType总不是null , 要么Void要么是某个类 .
 * @ param klass 被代理的类
 * @ param mod 方法的modify数据
 * @ param params 参数列表
 * @ param method asm下的方法签名
 * @ param returnType 返回值 . 如果执行的是构造方法 , 那么它是null , 否则肯定不是null .
 * @ param className 目标类名 , FastClass实现类的类名
 * @ param descriptor 类签名 */
public static byte [ ] _make ( Class < ? > klass , int mod , Class < ? > [ ] params , org . nutz . repo . org . objectweb . asm . commons . Method method , Class < ? > returnType , String className , String descriptor ) { } }

implementation:
ClassWriter cw = new ClassWriter ( ClassWriter . COMPUTE_FRAMES ) ; cw . visit ( V1_5 , ACC_PUBLIC , className . replace ( '.' , '/' ) , null , "java/lang/Object" , new String [ ] { FastMethod . class . getName ( ) . replace ( '.' , '/' ) } ) ; Type klassType = Type . getType ( klass ) ; // 首先 , 定义默认构造方法
addConstructor ( cw , Type . getType ( Object . class ) , org . nutz . repo . org . objectweb . asm . commons . Method . getMethod ( "void <init> ()" ) ) ; // 然后定义执行方法 , _ M就是invoke方法的签名
GeneratorAdapter mg = new GeneratorAdapter ( ACC_PUBLIC , _M , null , new Type [ ] { Exception_TYPE } , cw ) ; if ( returnType == null ) { // 没有返回值 , 是代表这里模式是 " 构造方法 "
mg . newInstance ( klassType ) ; // 相当于 new User . 注意 , 没有括号哦 , 因为构造方法参数还没传
mg . dup ( ) ; } else if ( ! Modifier . isStatic ( mod ) ) { // 有返回值 , 那么 , 模式是 " 执行方法 " . 然后呢 , 非静态方法的话 , 需要载入对象
mg . loadThis ( ) ; mg . loadArg ( 0 ) ; // 代表 Object invoke ( Object obj , Object . . . args ) 中的 obj
mg . checkCast ( klassType ) ; // 因为invoke方法的签名中 , obj的类型是Object , 需要cast为目标类型 .
// 相当于执行了 ( ( User ) obj )
} // 准备参数列表 . 根据被执行的方法或构造方法的签名 , 可以推测出参数列表 .
// invoke方法得到的是一个 Object [ ] , 需要一一展开
if ( params . length > 0 ) { for ( int i = 0 ; i < params . length ; i ++ ) { mg . loadArg ( 1 ) ; // 代表 Object invoke ( Object obj , Object . . . args ) 中的 args
mg . push ( i ) ; // 数组下标
mg . arrayLoad ( Type . getType ( Object . class ) ) ; // 读取数组 . 上面三句相当于 args [ i ]
Type paramType = Type . getType ( params [ i ] ) ; // 读取目标方法 / 构造方法的参数的类型
if ( params [ i ] . isPrimitive ( ) ) { mg . unbox ( paramType ) ; // 如果是基本数据类型 , 需要开箱 . Object - - > Integer - - > int . 在Java源文件里面有自动封箱 / 自动开箱 , asm可没这种东西 .
} else { mg . checkCast ( paramType ) ; // 其他类型 ? 直接cast一下就好了
} } // 上面的代码转换为java写法的话 , 就是
// ( ( Integer ) args [ 0 ] , ( String ) args [ 1 ] , . . . . )
// 注意 , 没有 对象在前面 , 因为还没执行
} if ( returnType == null ) { // 模式是
mg . invokeConstructor ( klassType , method ) ; // 跟前面的代码合并在一起 new User ( ( Integer ) args [ 0 ] , ( String ) args [ 1 ] , . . . . ) ;
} else { if ( Modifier . isStatic ( mod ) ) { mg . invokeStatic ( klassType , method ) ; // 跟前面的代码合并在一起 , 假设方法名称是create , 静态方法
// User . create ( ( Integer ) args [ 0 ] , ( String ) args [ 1 ] , . . . . ) ;
} else if ( Modifier . isInterface ( klass . getModifiers ( ) ) ) { mg . invokeInterface ( klassType , method ) ; // 跟前面的代码合并在一起 , 假设方法名称是create , User是一个接口
// ( ( User ) obj ) . create ( ( Integer ) args [ 0 ] , ( String ) args [ 1 ] , . . . . ) ;
} else { mg . invokeVirtual ( klassType , method ) ; // 跟前面的代码合并在一起 , 假设方法名称是create , User是一个普通类
// ( ( User ) obj ) . create ( ( Integer ) args [ 0 ] , ( String ) args [ 1 ] , . . . . ) ;
} // 处理方法返回值的特殊情况
if ( Void . class . equals ( returnType ) ) { // 如果method没有返回值 ( void ) , 那么 , 塞入一个null做invoke方法返回值
mg . visitInsn ( ACONST_NULL ) ; } else if ( returnType . isPrimitive ( ) ) { // method有返回值 , 而且是基本数据类型 ? 那么就要封箱了 , 因为invoke方法返回的是Object , 基本数据类型可不是Object .
mg . box ( Type . getType ( returnType ) ) ; } else { // 其余的情况就是没情况 , method的返回值已经在堆栈里面 , 等着返回就行
} } // 伪造一下行号 , 这样eclipse就不会抱怨
Label tmp = new Label ( ) ; mg . visitLabel ( tmp ) ; mg . visitLineNumber ( 1 , tmp ) ; // 把堆栈中的返回值给弹出去 .
mg . returnValue ( ) ; // 完整整个方法
mg . endMethod ( ) ; // 再注册一下源文件名称 , 结合行号 , 日志里面会显示 ( User . java : 1)
cw . visitSource ( klass . getSimpleName ( ) + ".java" , null ) ; // 整个类结束
cw . visitEnd ( ) ; // 字节码生成完成 , 返回byte [ ]
return cw . toByteArray ( ) ;


signature:
public class JdbcExpertConfigFile { /** * 在 fromJson 的时候 , 会被调用 */
public void setExperts ( Map < String , Class < ? extends JdbcExpert > > experts ) { } }

implementation:
this . experts = experts ; this . _experts = new LinkedHashMap < Pattern , Class < ? extends JdbcExpert > > ( ) ; for ( Entry < String , Class < ? extends JdbcExpert > > entry : experts . entrySet ( ) ) { // 忽略大小写 , 并且让换行符与 . 能够匹配
_experts . put ( Pattern . compile ( entry . getKey ( ) , Pattern . DOTALL & Pattern . CASE_INSENSITIVE ) , entry . getValue ( ) ) ; }


signature:
public class JdbcExpertConfigFile { /** * 初始化文件池 , 即使初始化失败 , 也继续执行 */
private void initFilePool ( ) { } }

implementation:
String home = config . get ( "pool-home" ) . toString ( ) ; try { home = Disks . normalize ( home ) ; if ( home == null ) home = config . get ( "pool-home" ) . toString ( ) ; long max = config . containsKey ( "pool-max" ) ? ( ( Number ) config . get ( "pool-max" ) ) . longValue ( ) : 2000 ; if ( home . contains ( "${app.home}" ) ) { try { // 这里引用了Mvcs类 , 不太舒服 , 但应该还是有益处的
home = home . replace ( "${app.home}" , Mvcs . getServletContext ( ) . getRealPath ( "/" ) ) ; } catch ( Throwable e ) { } } try { pool = NutFilePool . getOrCreatePool ( home , max ) ; } catch ( Exception e ) { // 看看是不是Mvc环境 , 尝试在WebContent下创建
if ( ! home . startsWith ( "~/" ) || Mvcs . getServletContext ( ) == null ) throw e ; try { String tmp = Mvcs . getServletContext ( ) . getRealPath ( "/" ) + home . substring ( 2 ) ; pool = NutFilePool . getOrCreatePool ( tmp , max ) ; log . info ( "had created filepool under webapp root path" ) ; } catch ( Exception e1 ) { throw e ; // 抛出原本的异常好了 , 哎 . . .
} } pool = new SynchronizedFilePool ( pool ) ; } catch ( Throwable e ) { if ( log . isWarnEnabled ( ) ) log . warnf ( "NutDao FilePool create fail!! Blob and Clob Support is DISABLE!! Home=" + home , e ) ; } isInit = true ;


signature:
public class AbstractJdbcExpert { /** * 下面为子类默认实现几个接口函数 */
public void setupEntityField ( Connection conn , Entity < ? > en ) { } }

implementation:
List < MappingField > mfs = new ArrayList < MappingField > ( ) ; for ( MappingField mf : en . getMappingFields ( ) ) { if ( mf . getTypeMirror ( ) . isEnum ( ) ) { mfs . add ( mf ) ; } } if ( mfs . isEmpty ( ) ) return ; Statement stat = null ; ResultSet rs = null ; ResultSetMetaData rsmd = null ; try { // 获取数据库元信息
stat = conn . createStatement ( ) ; rs = stat . executeQuery ( createResultSetMetaSql ( en ) ) ; rsmd = rs . getMetaData ( ) ; // 循环字段检查
List < String > columnNames = new ArrayList < String > ( ) ; List < String > columnLabels = new ArrayList < String > ( ) ; int columnCount = rsmd . getColumnCount ( ) ; for ( int i = 1 ; i <= columnCount ; i ++ ) { columnNames . add ( rsmd . getColumnName ( i ) ) ; columnLabels . add ( rsmd . getColumnLabel ( i ) ) ; } for ( MappingField mf : mfs ) { try { int ci = columnNames . indexOf ( mf . getColumnName ( ) ) + 1 ; if ( ci == 0 ) { log . debugf ( "Can not find @Column(%s) in table/view (%s), skip checking" , mf . getColumnName ( ) , rsmd . getTableName ( 1 ) ) ; continue ; } // 枚举类型在数据库中的值
if ( Daos . isIntLikeColumn ( rsmd , ci ) ) { mf . setColumnType ( ColType . INT ) ; } else { mf . setColumnType ( ColType . VARCHAR ) ; } } catch ( Exception e ) { } } } catch ( Exception e ) { if ( log . isDebugEnabled ( ) ) log . debugf ( "Table '%s' doesn't exist! class=%s" , en . getViewName ( ) , en . getType ( ) . getName ( ) ) ; } // Close ResultSet and Statement
finally { Daos . safeClose ( stat , rs ) ; }


signature:
public class IdNameEntityService { /** * 智能获取一个实体 , 如str能转为Long类型 , 则调用fetch ( long id ) , 否则调用fetch ( String name )
 * @ param str 非空的字符串 , 可以是整数或普通字符串
 * @ return 符合条件的记录 , 如不存在则返回null */
public T smartFetch ( String str ) { } }

implementation: try { long id = Long . parseLong ( str ) ; return fetch ( id ) ; } catch ( Exception e ) { } return fetch ( str ) ;


signature:
public class IdNameEntityService { /** * 是否存在符合条件的记录 , 需要实体有 @ Name标注
 * @ param name 属性的值
 * @ return true , 如果存在的话 . */
public boolean exists ( String name ) { } }

implementation: EntityField ef = getEntity ( ) . getNameField ( ) ; if ( null == ef ) return false ; return dao ( ) . count ( getEntityClass ( ) , Cnd . where ( ef . getName ( ) , "=" , name ) ) > 0 ;


signature:
public class Strings { /** * 蛇形转驼峰
 * @ param str
 * 待转换字符串
 * @ return 转换结果 */
public static String line2Hump ( String str ) { } }

implementation: str = str . toLowerCase ( ) ; Matcher matcher = linePattern . matcher ( str ) ; StringBuffer sb = new StringBuffer ( ) ; while ( matcher . find ( ) ) { matcher . appendReplacement ( sb , matcher . group ( 1 ) . toUpperCase ( ) ) ; } matcher . appendTail ( sb ) ; return upperFirst ( sb . toString ( ) ) ;


signature:
public class Strings { /** * 驼峰转蛇形
 * @ param str
 * 待转换字符串
 * @ return 转换结果 */
public static String hump2Line ( String str ) { } }

implementation: str = lowerFirst ( str ) ; Matcher matcher = humpPattern . matcher ( str ) ; StringBuffer sb = new StringBuffer ( ) ; while ( matcher . find ( ) ) { matcher . appendReplacement ( sb , "_" + matcher . group ( 0 ) . toLowerCase ( ) ) ; } matcher . appendTail ( sb ) ; return sb . toString ( ) ;


signature:
public class Strings { /** * 是中文字符吗 ?
 * @ param c
 * 待判定字符
 * @ return 判断结果 */
public static boolean isChineseCharacter ( char c ) { } }

implementation: Character . UnicodeBlock ub = Character . UnicodeBlock . of ( c ) ; if ( ub == Character . UnicodeBlock . CJK_UNIFIED_IDEOGRAPHS || ub == Character . UnicodeBlock . CJK_COMPATIBILITY_IDEOGRAPHS || ub == Character . UnicodeBlock . CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || ub == Character . UnicodeBlock . CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B || ub == Character . UnicodeBlock . CJK_SYMBOLS_AND_PUNCTUATION || ub == Character . UnicodeBlock . HALFWIDTH_AND_FULLWIDTH_FORMS || ub == Character . UnicodeBlock . GENERAL_PUNCTUATION ) { return true ; } return false ;


signature:
public class Strings { /** * 判断字符是否为全角字符
 * @ param c
 * 字符
 * @ return 判断结果 */
public static boolean isFullWidthCharacter ( char c ) { } }

implementation:
// 全角空格为12288 , 半角空格为32
// 其他字符半角 ( 33-126 ) 与全角 ( 65281-65374 ) 的对应关系是 : 均相差65248
// 全角空格 | | 其他全角字符
if ( c == 12288 || ( c > 65280 && c < 65375 ) ) { return true ; } // 中文全部是全角
if ( isChineseCharacter ( c ) ) { return true ; } // 日文判断
// 全角平假名 u3040 - u309F
// 全角片假名 u30A0 - u30FF
if ( c >= '\u3040' && c <= '\u30FF' ) { return true ; } return false ;


signature:
public class Strings { /** * 转换为半角字符串
 * @ param str
 * 待转换字符串
 * @ return 转换后的字符串 */
public static String toHalfWidthString ( CharSequence str ) { } }

implementation: StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { sb . append ( toHalfWidthCharacter ( str . charAt ( i ) ) ) ; } return sb . toString ( ) ;


signature:
public class Strings { /** * 计算字符串的字符长度 ( 全角算2 , 半角算1)
 * @ param str
 * 被计算的字符串
 * @ return 字符串的字符长度 */
public static int charLength ( CharSequence str ) { } }

implementation: int clength = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { clength += isFullWidthCharacter ( str . charAt ( i ) ) ? 2 : 1 ; } return clength ;


signature:
public class Strings { /** * 复制字符串
 * @ param cs
 * 字符串
 * @ param num
 * 数量
 * @ return 新字符串 */
public static String dup ( CharSequence cs , int num ) { } }

implementation: if ( isEmpty ( cs ) || num <= 0 ) return "" ; StringBuilder sb = new StringBuilder ( cs . length ( ) * num ) ; for ( int i = 0 ; i < num ; i ++ ) sb . append ( cs ) ; return sb . toString ( ) ;


signature:
public class Strings { /** * 将字符串首字母小写
 * @ param s
 * 字符串
 * @ return 首字母小写后的新字符串 */
public static String lowerFirst ( CharSequence s ) { } }

implementation: if ( null == s ) return null ; int len = s . length ( ) ; if ( len == 0 ) return "" ; char c = s . charAt ( 0 ) ; if ( Character . isLowerCase ( c ) ) return s . toString ( ) ; return new StringBuilder ( len ) . append ( Character . toLowerCase ( c ) ) . append ( s . subSequence ( 1 , len ) ) . toString ( ) ;


signature:
public class Strings { /** * 将字符串首字母大写
 * @ param s
 * 字符串
 * @ return 首字母大写后的新字符串 */
public static String upperFirst ( CharSequence s ) { } }

implementation: if ( null == s ) return null ; int len = s . length ( ) ; if ( len == 0 ) return "" ; char c = s . charAt ( 0 ) ; if ( Character . isUpperCase ( c ) ) return s . toString ( ) ; return new StringBuilder ( len ) . append ( Character . toUpperCase ( c ) ) . append ( s . subSequence ( 1 , len ) ) . toString ( ) ;


signature:
public class Strings { /** * 去掉字符串前后空白字符 。 空白字符的定义由Character . isWhitespace来判断
 * @ param cs
 * 字符串
 * @ return 去掉了前后空白字符的新字符串 */
public static String trim ( CharSequence cs ) { } }

implementation: if ( null == cs ) return null ; int length = cs . length ( ) ; if ( length == 0 ) return cs . toString ( ) ; int l = 0 ; int last = length - 1 ; int r = last ; for ( ; l < length ; l ++ ) { if ( ! Character . isWhitespace ( cs . charAt ( l ) ) ) break ; } for ( ; r > l ; r -- ) { if ( ! Character . isWhitespace ( cs . charAt ( r ) ) ) break ; } if ( l > r ) return "" ; else if ( l == 0 && r == last ) return cs . toString ( ) ; return cs . subSequence ( l , r + 1 ) . toString ( ) ;


signature:
public class Strings { /** * 将给定字符串 , 变成 " xxx . . . xxx " 形式的字符串
 * @ param str
 * 字符串
 * @ param len
 * 最大长度
 * @ return 紧凑的字符串 */
public static String brief ( String str , int len ) { } }

implementation: if ( Strings . isBlank ( str ) || ( str . length ( ) + 3 ) <= len ) return str ; int w = len / 2 ; int l = str . length ( ) ; return str . substring ( 0 , len - w ) + " ... " + str . substring ( l - w ) ;


signature:
public class Strings { /** * 根据一个正则式 , 将字符串拆分成数组 , 空元素将被忽略
 * @ param s
 * 字符串
 * @ param regex
 * 正则式
 * @ return 字符串数组 */
public static String [ ] splitIgnoreBlank ( String s , String regex ) { } }

implementation: if ( null == s ) return null ; String [ ] ss = s . split ( regex ) ; List < String > list = new LinkedList < String > ( ) ; for ( String st : ss ) { if ( isBlank ( st ) ) continue ; list . add ( trim ( st ) ) ; } return list . toArray ( new String [ list . size ( ) ] ) ;


signature:
public class Strings { /** * 将一个整数转换成最小长度为某一固定数值的十进制形式字符串
 * @ param d
 * 整数
 * @ param width
 * 宽度
 * @ return 新字符串 */
public static String fillDigit ( int d , int width ) { } }

implementation: return Strings . alignRight ( String . valueOf ( d ) , width , '0' ) ;


signature:
public class Strings { /** * 将一个整数转换成最小长度为某一固定数值的十六进制形式字符串
 * @ param d
 * 整数
 * @ param width
 * 宽度
 * @ return 新字符串 */
public static String fillHex ( int d , int width ) { } }

implementation: return Strings . alignRight ( Integer . toHexString ( d ) , width , '0' ) ;


signature:
public class Strings { /** * 将一个整数转换成最小长度为某一固定数值的二进制形式字符串
 * @ param d
 * 整数
 * @ param width
 * 宽度
 * @ return 新字符串 */
public static String fillBinary ( int d , int width ) { } }

implementation: return Strings . alignRight ( Integer . toBinaryString ( d ) , width , '0' ) ;


signature:
public class Strings { /** * 将一个整数转换成固定长度的十进制形式字符串
 * @ param d
 * 整数
 * @ param width
 * 宽度
 * @ return 新字符串 */
public static String toDigit ( int d , int width ) { } }

implementation: return Strings . cutRight ( String . valueOf ( d ) , width , '0' ) ;


signature:
public class Strings { /** * 将一个整数转换成固定长度的十六进制形式字符串
 * @ param d
 * 整数
 * @ param width
 * 宽度
 * @ return 新字符串 */
public static String toHex ( int d , int width ) { } }

implementation: return Strings . cutRight ( Integer . toHexString ( d ) , width , '0' ) ;


signature:
public class Strings { /** * 将一个整数转换成固定长度的二进制形式字符串
 * @ param d
 * 整数
 * @ param width
 * 宽度
 * @ return 新字符串 */
public static String toBinary ( int d , int width ) { } }

implementation: return Strings . cutRight ( Integer . toBinaryString ( d ) , width , '0' ) ;


signature:
public class Strings { /** * 测试此字符串是否被指定的左字符和右字符所包裹 ; 如果该字符串左右两边有空白的时候 , 会首先忽略这些空白
 * @ param cs
 * 字符串
 * @ param lc
 * 左字符
 * @ param rc
 * 右字符
 * @ return 字符串是被左字符和右字符包裹 */
public static boolean isQuoteByIgnoreBlank ( CharSequence cs , char lc , char rc ) { } }

implementation: if ( null == cs ) return false ; int len = cs . length ( ) ; if ( len < 2 ) return false ; int l = 0 ; int last = len - 1 ; int r = last ; for ( ; l < len ; l ++ ) { if ( ! Character . isWhitespace ( cs . charAt ( l ) ) ) break ; } if ( cs . charAt ( l ) != lc ) return false ; for ( ; r > l ; r -- ) { if ( ! Character . isWhitespace ( cs . charAt ( r ) ) ) break ; } return l < r && cs . charAt ( r ) == rc ;


signature:
public class Strings { /** * 测试此字符串是否被指定的左字符和右字符所包裹
 * @ param cs
 * 字符串
 * @ param lc
 * 左字符
 * @ param rc
 * 右字符
 * @ return 字符串是被左字符和右字符包裹 */
public static boolean isQuoteBy ( CharSequence cs , char lc , char rc ) { } }

implementation: if ( null == cs ) return false ; int length = cs . length ( ) ; return length > 1 && cs . charAt ( 0 ) == lc && cs . charAt ( length - 1 ) == rc ;


signature:
public class Strings { /** * 测试此字符串是否被指定的左字符串和右字符串所包裹
 * @ param str
 * 字符串
 * @ param l
 * 左字符串
 * @ param r
 * 右字符串
 * @ return 字符串是被左字符串和右字符串包裹 */
public static boolean isQuoteBy ( String str , String l , String r ) { } }

implementation: if ( null == str || null == l || null == r ) return false ; return str . startsWith ( l ) && str . endsWith ( r ) ;


signature:
public class Strings { /** * 计算一个字符串开头有几个缩进 ,
 * @ param str
 * 给定字符串
 * @ param tabWidth
 * 一个 \ t 相当于几个空格 , 默认 4
 * @ return 返回缩进级别 */
public static int countStrHeadIndent ( String str , int tabWidth ) { } }

implementation: int n = 0 ; if ( ! isEmpty ( str ) ) { for ( int i = 0 ; i < str . length ( ) ; i ++ ) { char c = str . charAt ( i ) ; if ( ' ' == c ) n ++ ; else if ( '\t' == c ) n += tabWidth ; else break ; } } return n / tabWidth ;


signature:
public class Strings { /** * 计算一个字符串开头有几个重复的字符
 * @ param str
 * 给定字符串
 * @ param c
 * 指定重复字符
 * @ return 开头重复字符的个数 */
public static int countStrHeadChar ( String str , char c ) { } }

implementation: int re = 0 ; if ( ! isEmpty ( str ) ) for ( ; re < str . length ( ) ; re ++ ) { if ( str . charAt ( re ) != c ) return re ; } return re ;


signature:
public class Strings { /** * 对字符串反向缩进
 * @ param str
 * 给定字符串
 * @ param indent
 * 反向 indent 几次 , 如果小于等于 0 相当于 1
 * @ param tabWidth
 * 一个 \ t 相当于几个空格 , 默认 4
 * @ return 反向缩进后的字符串 */
public static String shiftIndent ( String str , int indent , int tabWidth ) { } }

implementation: if ( isEmpty ( str ) ) return str ; if ( indent <= 0 ) indent = 1 ; int n = 0 ; int i = 0 ; for ( ; i < str . length ( ) ; i ++ ) { if ( n > 0 && ( n / tabWidth ) >= indent ) break ; char c = str . charAt ( i ) ; if ( ' ' == c ) n ++ ; else if ( '\t' == c ) n += tabWidth ; else break ; } if ( i > 0 ) return str . substring ( i ) ; return str ;


signature:
public class Strings { /** * 获得一个字符串集合中 , 最长串的长度
 * @ param coll
 * 字符串集合
 * @ return 最大长度 */
public static int maxLength ( Collection < ? extends CharSequence > coll ) { } }

implementation: int re = 0 ; if ( null != coll ) for ( CharSequence s : coll ) if ( null != s ) re = Math . max ( re , s . length ( ) ) ; return re ;


signature:
public class Strings { /** * 获得一个字符串数组中 , 最长串的长度
 * @ param array
 * 字符串数组
 * @ return 最大长度 */
public static < T extends CharSequence > int maxLength ( T [ ] array ) { } }

implementation: int re = 0 ; if ( null != array ) for ( CharSequence s : array ) if ( null != s ) re = Math . max ( re , s . length ( ) ) ; return re ;


signature:
public class Strings { /** * 对指定对象进行 toString 操作 ; 如果该对象为 null , 则返回默认值
 * @ param obj
 * 指定的对象
 * @ param def
 * 默认值
 * @ return 对指定对象进行 toString 操作 ; 如果该对象为 null , 则返回默认值 */
public static String sNull ( Object obj , String def ) { } }

implementation: return obj != null ? obj . toString ( ) : def ;


signature:
public class Strings { /** * 对指定对象进行 toString 操作 ; 如果该对象为 null 或者 toString 方法为空串 ( " " ) , 则返回默认值
 * @ param obj
 * 指定的对象
 * @ param def
 * 默认值
 * @ return 对指定对象进行 toString 操作 ; 如果该对象为 null 或者 toString 方法为空串 ( " " ) , 则返回默认值 */
public static String sBlank ( Object obj , String def ) { } }

implementation: if ( null == obj ) return def ; String s = obj . toString ( ) ; return Strings . isBlank ( s ) ? def : s ;


signature:
public class Strings { /** * 截去第一个字符
 * 比如 :
 * < ul >
 * < li > removeFirst ( " 12345 " ) = > 2345
 * < li > removeFirst ( " A " ) = > " "
 * < / ul >
 * @ param str
 * 字符串
 * @ return 新字符串 */
public static String removeFirst ( CharSequence str ) { } }

implementation: if ( str == null ) return null ; if ( str . length ( ) > 1 ) return str . subSequence ( 1 , str . length ( ) ) . toString ( ) ; return "" ;