signature:
public class SerializeHelper { /** * 将对象序列化到文件
 * @ param folder 父目录
 * @ param serializable
 * @ return
 * @ throws java . io . IOException */
public static File writeObjectToFile ( File folder , Serializable serializable ) throws IOException { } }

implementation: Assert . notNull ( folder , "文件夹不能为空" ) ; if ( ! folder . exists ( ) ) { folder . mkdirs ( ) ; } Assert . isTrue ( folder . isDirectory ( ) , folder + "不是文件夹" ) ; File file = new File ( folder , System . currentTimeMillis ( ) + nextIndex ( ) + "" ) ; ObjectOutputStream outputStream = new ObjectOutputStream ( new FileOutputStream ( file ) ) ; outputStream . writeObject ( serializable ) ; outputStream . flush ( ) ; outputStream . close ( ) ; return file ;


signature:
public class SerializeHelper { /** * 返回固定长度的
 * @ return */
private static String nextIndex ( ) { } }

implementation: String rs = "" ; synchronized ( SerializeHelper . class ) { rs += ++ index < 0 ? - index : index ; int least = 3 - rs . length ( ) ; for ( int i = 0 ; i < least ; i ++ ) { rs = "0" + rs ; } return rs ; }


signature:
public class JChardetFacade { /** * ( non - Javadoc )
 * @ see cpdetector . io . ICodepageDetector # detectCodepage ( java . io . InputStream ) */
public synchronized Charset detectCodepage ( InputStream in , int length ) throws IOException { } }

implementation: this . Reset ( ) ; int len ; int read = 0 ; boolean done = false ; boolean isAscii = true ; Charset ret = null ; do { len = in . read ( buf , 0 , Math . min ( buf . length , length - read ) ) ; if ( len > 0 ) { read += len ; } if ( ! done ) done = det . DoIt ( buf , len , false ) ; } while ( len > 0 && ! done ) ; det . DataEnd ( ) ; if ( this . codpage == null ) { if ( this . m_guessing ) { ret = guess ( ) ; } else { ret = UnknownCharset . getInstance ( ) ; } } else { ret = this . codpage ; } return ret ;


signature:
public class SimpleNamespaceContext { /** * Sets the bindings for this namespace context . The supplied map must consist of string key value pairs .
 * @ param bindings the bindings */
public void setBindings ( Map < String , String > bindings ) { } }

implementation: for ( Map . Entry < String , String > entry : bindings . entrySet ( ) ) { bindNamespaceUri ( entry . getKey ( ) , entry . getValue ( ) ) ; }


signature:
public class SimpleNamespaceContext { /** * Binds the given prefix to the given namespace .
 * @ param prefix the namespace prefix
 * @ param namespaceUri the namespace uri */
public void bindNamespaceUri ( String prefix , String namespaceUri ) { } }

implementation: Assert . notNull ( prefix , "No prefix given" ) ; Assert . notNull ( namespaceUri , "No namespaceUri given" ) ; if ( XMLConstants . DEFAULT_NS_PREFIX . equals ( prefix ) ) { defaultNamespaceUri = namespaceUri ; } else { prefixToNamespaceUri . put ( prefix , namespaceUri ) ; getPrefixesInternal ( namespaceUri ) . add ( prefix ) ; }


signature:
public class SimpleNamespaceContext { /** * Removes the given prefix from this context .
 * @ param prefix the prefix to be removed */
public void removeBinding ( String prefix ) { } }

implementation: if ( XMLConstants . DEFAULT_NS_PREFIX . equals ( prefix ) ) { defaultNamespaceUri = "" ; } else { String namespaceUri = prefixToNamespaceUri . remove ( prefix ) ; List < String > prefixes = getPrefixesInternal ( namespaceUri ) ; prefixes . remove ( prefix ) ; }


signature:
public class FileEncode { /** * 使用工具获取文件的编码方式
 * @ param file
 * @ return */
public static synchronized String getEncodeByUtil ( File file ) { } }

implementation:
CodepageDetectorProxy detector = CodepageDetectorProxy . getInstance ( ) ; detector . add ( new ParsingDetector ( false ) ) ; detector . add ( JChardetFacade . getInstance ( ) ) ; // 用到antlr . jar 、 chardet . jar
// ASCIIDetector用于ASCII编码测定
detector . add ( ASCIIDetector . getInstance ( ) ) ; // UnicodeDetector用于Unicode家族编码的测定
// detector . add ( UnicodeDetector . getInstance ( ) ) ;
Charset charset = null ; try { charset = detector . detectCodepage ( file . toURI ( ) . toURL ( ) ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; } if ( charset != null ) return charset . name ( ) ; else return null ;


signature:
public class ClassHelper { /** * 获取加载的所有类
 * @ return */
public static Class [ ] getAllClasses ( ) { } }

implementation: ClassLoader classLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; Class < ? > cla = classLoader . getClass ( ) ; while ( cla != ClassLoader . class ) cla = cla . getSuperclass ( ) ; Field field = null ; try { field = cla . getDeclaredField ( "classes" ) ; field . setAccessible ( true ) ; Vector < Class > v = null ; try { v = ( Vector < Class > ) field . get ( classLoader ) ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } for ( int i = 0 ; i < v . size ( ) ; i ++ ) { System . out . println ( v . get ( i ) ) ; } return v . toArray ( new Class [ ] { } ) ; } catch ( NoSuchFieldException e ) { e . printStackTrace ( ) ; } return null ;


signature:
public class ClassHelper { /** * 检查类是否直接或间接实现接口
 * @ param clazz
 * @ param enterface
 * @ return */
public static boolean isImplementsInterface ( Class clazz , Class enterface ) { } }

implementation: Assert . notNull ( clazz ) ; Assert . notNull ( enterface ) ; Class [ ] interfaces = clazz . getInterfaces ( ) ; Class superclass = clazz . getSuperclass ( ) ; if ( superclass != null ) { boolean implementsInterface = isImplementsInterface ( superclass , enterface ) ; if ( implementsInterface ) { return true ; } } boolean flag = false ; for ( Class anInterface : interfaces ) { if ( enterface == anInterface ) { return true ; } else { flag = isImplementsInterface ( anInterface , enterface ) ; if ( flag ) { return flag ; } } } return flag ;


signature:
public class MimeTypeUtils { /** * Parse the given String into a single { @ code MimeType } .
 * @ param mimeType the string to parse
 * @ return the mime type
 * @ throws InvalidMimeTypeException if the string cannot be parsed */
public static MimeType parseMimeType ( String mimeType ) { } }

implementation:
if ( ! StringUtils . hasLength ( mimeType ) ) { throw new InvalidMimeTypeException ( mimeType , "'mimeType' must not be empty" ) ; } String [ ] parts = StringUtils . tokenizeToStringArray ( mimeType , ";" ) ; String fullType = parts [ 0 ] . trim ( ) ; // java . net . HttpURLConnection returns a * ; q = . 2 Accept header
if ( MimeType . WILDCARD_TYPE . equals ( fullType ) ) { fullType = "*/*" ; } int subIndex = fullType . indexOf ( '/' ) ; if ( subIndex == - 1 ) { throw new InvalidMimeTypeException ( mimeType , "does not contain '/'" ) ; } if ( subIndex == fullType . length ( ) - 1 ) { throw new InvalidMimeTypeException ( mimeType , "does not contain subtype after '/'" ) ; } String type = fullType . substring ( 0 , subIndex ) ; String subtype = fullType . substring ( subIndex + 1 , fullType . length ( ) ) ; if ( MimeType . WILDCARD_TYPE . equals ( type ) && ! MimeType . WILDCARD_TYPE . equals ( subtype ) ) { throw new InvalidMimeTypeException ( mimeType , "wildcard type is legal only in '*/*' (all mime types)" ) ; } Map < String , String > parameters = null ; if ( parts . length > 1 ) { parameters = new LinkedHashMap < String , String > ( parts . length - 1 ) ; for ( int i = 1 ; i < parts . length ; i ++ ) { String parameter = parts [ i ] ; int eqIndex = parameter . indexOf ( '=' ) ; if ( eqIndex != - 1 ) { String attribute = parameter . substring ( 0 , eqIndex ) ; String value = parameter . substring ( eqIndex + 1 , parameter . length ( ) ) ; parameters . put ( attribute , value ) ; } } } try { return new MimeType ( type , subtype , parameters ) ; } catch ( UnsupportedCharsetException ex ) { throw new InvalidMimeTypeException ( mimeType , "unsupported charset '" + ex . getCharsetName ( ) + "'" ) ; } catch ( IllegalArgumentException ex ) { throw new InvalidMimeTypeException ( mimeType , ex . getMessage ( ) ) ; }


signature:
public class MimeTypeUtils { /** * Parse the given , comma - separated string into a list of { @ code MimeType } objects .
 * @ param mimeTypes the string to parse
 * @ return the list of mime types
 * @ throws IllegalArgumentException if the string cannot be parsed */
public static List < MimeType > parseMimeTypes ( String mimeTypes ) { } }

implementation: if ( ! StringUtils . hasLength ( mimeTypes ) ) { return Collections . emptyList ( ) ; } String [ ] tokens = mimeTypes . split ( ",\\s*" ) ; List < MimeType > result = new ArrayList < MimeType > ( tokens . length ) ; for ( String token : tokens ) { result . add ( parseMimeType ( token ) ) ; } return result ;


signature:
public class MimeTypeUtils { /** * Sorts the given list of { @ code MimeType } objects by specificity .
 * < p > Given two mime types :
 * < ol >
 * < li > if either mime type has a { @ linkplain MimeType # isWildcardType ( ) wildcard type } ,
 * then the mime type without the wildcard is ordered before the other . < / li >
 * < li > if the two mime types have different { @ linkplain MimeType # getType ( ) types } ,
 * then they are considered equal and remain their current order . < / li >
 * < li > if either mime type has a { @ linkplain MimeType # isWildcardSubtype ( ) wildcard subtype }
 * , then the mime type without the wildcard is sorted before the other . < / li >
 * < li > if the two mime types have different { @ linkplain MimeType # getSubtype ( ) subtypes } ,
 * then they are considered equal and remain their current order . < / li >
 * < li > if the two mime types have a different amount of
 * { @ linkplain MimeType # getParameter ( String ) parameters } , then the mime type with the most
 * parameters is ordered before the other . < / li >
 * < / ol >
 * < p > For example : < blockquote > audio / basic & lt ; audio / * & lt ; * & # 047 ; * < / blockquote >
 * < blockquote > audio / basic ; level = 1 & lt ; audio / basic < / blockquote >
 * < blockquote > audio / basic = = text / html < / blockquote > < blockquote > audio / basic = =
 * audio / wave < / blockquote >
 * @ param mimeTypes the list of mime types to be sorted
 * @ see < a href = " http : / / tools . ietf . org / html / rfc2616 # section - 14.1 " > HTTP 1.1 , section
 * 14.1 < / a > */
public static void sortBySpecificity ( List < MimeType > mimeTypes ) { } }

implementation: Assert . notNull ( mimeTypes , "'mimeTypes' must not be null" ) ; if ( mimeTypes . size ( ) > 1 ) { Collections . sort ( mimeTypes , SPECIFICITY_COMPARATOR ) ; }


signature:
public class ParsingDetector { /** * ( non - Javadoc )
 * @ see cpdetector . io . ICodepageDetector # detectCodepage ( java . io . InputStream ) */
public Charset detectCodepage ( final InputStream in , final int length ) throws IOException { } }

implementation:
EncodingLexer lexer ; EncodingParser parser ; Charset charset = null ; String csName = null ; InputStream limitedInputStream = new LimitedInputStream ( in , length ) ; if ( this . m_verbose ) { System . out . println ( "  parsing for html-charset/xml-encoding attribute with codepage: US-ASCII" ) ; } try { lexer = new EncodingLexer ( new InputStreamReader ( limitedInputStream , "US-ASCII" ) ) ; parser = new EncodingParser ( lexer ) ; csName = parser . htmlDocument ( ) ; if ( csName != null ) { // TODO : prepare document with illegal value , then test : Decide to catch
// exception and return
// UnsupportedCharset .
try { charset = Charset . forName ( csName ) ; } catch ( UnsupportedCharsetException uce ) { charset = UnsupportedCharset . forName ( csName ) ; } } else { charset = UnknownCharset . getInstance ( ) ; } } catch ( ANTLRException ae ) { if ( this . m_verbose ) { System . out . println ( "  ANTLR parser exception: " + ae . getMessage ( ) ) ; } } catch ( Exception deepdown ) { if ( this . m_verbose ) { System . out . println ( "  Decoding Exception: " + deepdown . getMessage ( ) + " (unsupported java charset)." ) ; } if ( charset == null ) { if ( csName != null ) { charset = UnsupportedCharset . forName ( csName ) ; } else { charset = UnknownCharset . getInstance ( ) ; } } } return charset ;


signature:
public class XmlValidationModeDetector { /** * Detect the validation mode for the XML document in the supplied { @ link java . io . InputStream } .
 * Note that the supplied { @ link java . io . InputStream } is closed by this method before returning .
 * @ param inputStream the InputStream to parse
 * @ throws java . io . IOException in case of I / O failure
 * @ see # VALIDATION _ DTD
 * @ see # VALIDATION _ XSD */
public int detectValidationMode ( InputStream inputStream ) throws IOException { } }

implementation:
// Peek into the file to look for DOCTYPE .
BufferedReader reader = new BufferedReader ( new InputStreamReader ( inputStream ) ) ; try { boolean isDtdValidated = false ; String content ; while ( ( content = reader . readLine ( ) ) != null ) { content = consumeCommentTokens ( content ) ; if ( this . inComment || ! StringUtils . hasText ( content ) ) { continue ; } if ( hasDoctype ( content ) ) { isDtdValidated = true ; break ; } if ( hasOpeningTag ( content ) ) { // End of meaningful data . . .
break ; } } return ( isDtdValidated ? VALIDATION_DTD : VALIDATION_XSD ) ; } catch ( CharConversionException ex ) { // Choked on some character encoding . . .
// Leave the decision up to the caller .
return VALIDATION_AUTO ; } finally { reader . close ( ) ; }


signature:
public class XmlValidationModeDetector { /** * Does the supplied content contain an XML opening tag . If the parse state is currently
 * in an XML comment then this method always returns false . It is expected that all comment
 * tokens will have consumed for the supplied content before passing the remainder to this method . */
private boolean hasOpeningTag ( String content ) { } }

implementation: if ( this . inComment ) { return false ; } int openTagIndex = content . indexOf ( '<' ) ; return ( openTagIndex > - 1 && content . length ( ) > openTagIndex && Character . isLetter ( content . charAt ( openTagIndex + 1 ) ) ) ;


signature:
public class XmlValidationModeDetector { /** * Consumes all the leading comment data in the given String and returns the remaining content , which
 * may be empty since the supplied content might be all comment data . For our purposes it is only important
 * to strip leading comment content on a line since the first piece of non comment content will be either
 * the DOCTYPE declaration or the root element of the document . */
private String consumeCommentTokens ( String line ) { } }

implementation: if ( line . indexOf ( START_COMMENT ) == - 1 && line . indexOf ( END_COMMENT ) == - 1 ) { return line ; } while ( ( line = consume ( line ) ) != null ) { if ( ! this . inComment && ! line . trim ( ) . startsWith ( START_COMMENT ) ) { return line ; } } return line ;


signature:
public class XmlValidationModeDetector { /** * Consume the next comment token , update the " inComment " flag
 * and return the remaining content . */
private String consume ( String line ) { } }

implementation: int index = ( this . inComment ? endComment ( line ) : startComment ( line ) ) ; return ( index == - 1 ? null : line . substring ( index ) ) ;


signature:
public class XmlValidationModeDetector { /** * Try to consume the supplied token against the supplied content and update the
 * in comment parse state to the supplied value . Returns the index into the content
 * which is after the token or - 1 if the token is not found . */
private int commentToken ( String line , String token , boolean inCommentIfPresent ) { } }

implementation: int index = line . indexOf ( token ) ; if ( index > - 1 ) { this . inComment = inCommentIfPresent ; } return ( index == - 1 ? index : index + token . length ( ) ) ;


signature:
public class DateHelper { /** * 计算日期之间相差多少天
 * @ param date1 较前日期
 * @ param date2 较后日期
 * @ return */
public static int diffOfDay ( Date date1 , Date date2 ) { } }

implementation: Calendar calendar = Calendar . getInstance ( ) ; calendar . setTimeInMillis ( date1 . getTime ( ) ) ; int i = calendar . get ( Calendar . DAY_OF_YEAR ) ; Calendar calendar2 = Calendar . getInstance ( ) ; calendar2 . setTimeInMillis ( date2 . getTime ( ) ) ; int i2 = calendar2 . get ( Calendar . DAY_OF_YEAR ) ; return i2 - i ;


signature:
public class DateHelper { /** * 获取现在时间
 * @ return 返回时间类型 yyyy - MM - dd HH : mm : ss */
public static Date getNowDate ( ) { } }

implementation: Date currentTime = new Date ( ) ; String dateString = FORMATTER_LONG . format ( currentTime ) ; ParsePosition pos = new ParsePosition ( 8 ) ; Date currentTime_2 = FORMATTER_LONG . parse ( dateString , pos ) ; return currentTime_2 ;


signature:
public class DateHelper { /** * 获取现在时间
 * @ return 返回短时间格式 yyyy - MM - dd */
public static Date getNowDateShort ( ) { } }

implementation: Date currentTime = new Date ( ) ; String dateString = FORMATTER_SHORT . format ( currentTime ) ; ParsePosition pos = new ParsePosition ( 8 ) ; Date currentTime_2 = FORMATTER_SHORT . parse ( dateString , pos ) ; return currentTime_2 ;


signature:
public class DateHelper { /** * 获取现在时间
 * @ return 返回字符串格式 yyyy - MM - dd HH : mm : ss */
public static String getStringDate ( ) { } }

implementation: Date currentTime = new Date ( ) ; String dateString = FORMATTER_LONG . format ( currentTime ) ; return dateString ;


signature:
public class DateHelper { /** * 获取现在时间
 * @ return 返回短时间字符串格式yyyy - MM - dd */
public static String getStringDateShort ( ) { } }

implementation: Date currentTime = new Date ( ) ; String dateString = FORMATTER_SHORT . format ( currentTime ) ; return dateString ;


signature:
public class DateHelper { /** * 获取时间 小时 : 分 ; 秒 HH : mm : ss
 * @ return */
public static String getTimeShort ( ) { } }

implementation: SimpleDateFormat formatter = new SimpleDateFormat ( "HH:mm:ss" ) ; Date currentTime = new Date ( ) ; String dateString = formatter . format ( currentTime ) ; return dateString ;


signature:
public class DateHelper { /** * 将长时间格式字符串转换为时间 yyyy - MM - dd HH : mm : ss
 * @ param strDate
 * @ return */
public static Date strToDateLong ( String strDate ) { } }

implementation: ParsePosition pos = new ParsePosition ( 0 ) ; Date strtodate = FORMATTER_LONG . parse ( strDate , pos ) ; return strtodate ;


signature:
public class DateHelper { /** * 字符串转换为时间
 * @ param strDate
 * @ param dateFormat
 * @ return */
public static Date strToDate ( String strDate , String dateFormat ) { } }

implementation: return strToDate ( strDate , new SimpleDateFormat ( dateFormat ) ) ;


signature:
public class DateHelper { /** * 字符串转换为时间
 * @ param strDate
 * @ param dateFormat
 * @ return */
public static Date strToDate ( String strDate , DateFormat dateFormat ) { } }

implementation: ParsePosition pos = new ParsePosition ( 0 ) ; Date strtodate = dateFormat . parse ( strDate , pos ) ; return strtodate ;


signature:
public class DateHelper { /** * 将长时间格式时间转换为字符串 yyyy - MM - dd HH : mm : ss
 * @ param dateDate
 * @ return */
public static String dateToStrLong ( Date dateDate ) { } }

implementation: String dateString = FORMATTER_LONG . format ( dateDate ) ; return dateString ;


signature:
public class DateHelper { /** * 将短时间格式时间转换为字符串 yyyy - MM - dd
 * @ param dateDate
 * @ return */
public static String dateToStr ( Date dateDate ) { } }

implementation: String dateString = FORMATTER_SHORT . format ( dateDate ) ; return dateString ;


signature:
public class DateHelper { /** * 将短时间格式字符串转换为时间 yyyy - MM - dd
 * @ param strDate
 * @ return */
public static Date strToDate ( String strDate ) { } }

implementation: ParsePosition pos = new ParsePosition ( 0 ) ; Date strtodate = FORMATTER_SHORT . parse ( strDate , pos ) ; return strtodate ;


signature:
public class DateHelper { /** * 提取一个月中的最后一天
 * @ param day
 * @ return */
public static Date getLastDate ( long day ) { } }

implementation: Date date = new Date ( ) ; long date_3_hm = date . getTime ( ) - 3600000 * 34 * day ; Date date_3_hm_date = new Date ( date_3_hm ) ; return date_3_hm_date ;


signature:
public class DateHelper { /** * 得到现在时间
 * @ return 字符串 yyyyMMdd HHmmss */
public static String getStringToday ( ) { } }

implementation: Date currentTime = new Date ( ) ; SimpleDateFormat formatter = new SimpleDateFormat ( "yyyyMMdd HHmmss" ) ; String dateString = formatter . format ( currentTime ) ; return dateString ;


signature:
public class DateHelper { /** * 得到现在小时 */
public static String getHour ( ) { } }

implementation: Date currentTime = new Date ( ) ; String dateString = FORMATTER_LONG . format ( currentTime ) ; String hour ; hour = dateString . substring ( 11 , 13 ) ; return hour ;


signature:
public class DateHelper { /** * 得到现在分钟
 * @ return */
public static String getTime ( ) { } }

implementation: Date currentTime = new Date ( ) ; String dateString = FORMATTER_LONG . format ( currentTime ) ; String min ; min = dateString . substring ( 14 , 16 ) ; return min ;


signature:
public class DateHelper { /** * 根据用户传入的时间表示格式 , 返回当前时间的格式 如果是yyyyMMdd , 注意字母y不能大写 。
 * @ param sformat yyyyMMddhhmmss
 * @ return */
public static String getUserDate ( String sformat ) { } }

implementation: Date currentTime = new Date ( ) ; SimpleDateFormat formatter = new SimpleDateFormat ( sformat ) ; String dateString = formatter . format ( currentTime ) ; return dateString ;


signature:
public class DateHelper { /** * 二个小时时间间的差值 , 必须保证二个时间都是 " HH : MM " 的格式 , 返回字符型的分钟 */
public static String getTwoHour ( String st1 , String st2 ) { } }

implementation: String [ ] kk = null ; String [ ] jj = null ; kk = st1 . split ( ":" ) ; jj = st2 . split ( ":" ) ; if ( Integer . parseInt ( kk [ 0 ] ) < Integer . parseInt ( jj [ 0 ] ) ) return "0" ; else { double y = Double . parseDouble ( kk [ 0 ] ) + Double . parseDouble ( kk [ 1 ] ) / 60 ; double u = Double . parseDouble ( jj [ 0 ] ) + Double . parseDouble ( jj [ 1 ] ) / 60 ; if ( ( y - u ) > 0 ) return y - u + "" ; else return "0" ; }


signature:
public class DateHelper { /** * 得到二个日期间的间隔天数 */
public static String getTwoDay ( String sj1 , String sj2 ) { } }

implementation: SimpleDateFormat myFormatter = new SimpleDateFormat ( "yyyy-MM-dd" ) ; long day = 0 ; try { Date date = myFormatter . parse ( sj1 ) ; Date mydate = myFormatter . parse ( sj2 ) ; day = ( date . getTime ( ) - mydate . getTime ( ) ) / ( 24 * 60 * 60 * 1000 ) ; } catch ( Exception e ) { return "" ; } return day + "" ;


signature:
public class DateHelper { /** * 时间前推或后推分钟 , 其中JJ表示分钟 . */
public static String getPreTime ( String sj1 , String jj ) { } }

implementation: SimpleDateFormat format = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) ; String mydate1 = "" ; try { Date date1 = format . parse ( sj1 ) ; long Time = ( date1 . getTime ( ) / 1000 ) + Integer . parseInt ( jj ) * 60 ; date1 . setTime ( Time * 1000 ) ; mydate1 = format . format ( date1 ) ; } catch ( Exception e ) { } return mydate1 ;


signature:
public class DateHelper { /** * 得到一个时间延后或前移几天的时间 , nowdate为时间 , delay为前移或后延的天数 */
public static Date getNextDay ( Date nowDate , int delay ) { } }

implementation: long myTime = ( nowDate . getTime ( ) / 1000 ) + delay * 24 * 60 * 60 ; Date date = new Date ( ) ; date . setTime ( myTime * 1000 ) ; return date ;


signature:
public class DateHelper { /** * 得到一个时间延后或前移几天的时间 , nowdate为时间 , delay为前移或后延的天数 */
public static String getNextDay ( String nowDate , int delay ) { } }

implementation: try { SimpleDateFormat format = new SimpleDateFormat ( "yyyy-MM-dd" ) ; String mdate = "" ; Date d = strToDate ( nowDate ) ; long myTime = ( d . getTime ( ) / 1000 ) + delay * 24 * 60 * 60 ; d . setTime ( myTime * 1000 ) ; mdate = format . format ( d ) ; return mdate ; } catch ( Exception e ) { return "" ; }


signature:
public class DateHelper { /** * 返回美国时间格式 26 Apr 2006
 * @ param str
 * @ return */
public static String getEDate ( String str ) { } }

implementation: ParsePosition pos = new ParsePosition ( 0 ) ; Date strtodate = FORMATTER_SHORT . parse ( str , pos ) ; String j = strtodate . toString ( ) ; String [ ] k = j . split ( " " ) ; return k [ 2 ] + k [ 1 ] . toUpperCase ( ) + k [ 5 ] . substring ( 2 , 4 ) ;


signature:
public class DateHelper { /** * 获取一个月的最后一天
 * @ param dat
 * @ return */
public static String getEndDateOfMonth ( String dat ) { } }

implementation:
// yyyy - MM - dd
String str = dat . substring ( 0 , 8 ) ; String month = dat . substring ( 5 , 7 ) ; int mon = Integer . parseInt ( month ) ; if ( mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8 || mon == 10 || mon == 12 ) { str += "31" ; } else if ( mon == 4 || mon == 6 || mon == 9 || mon == 11 ) { str += "30" ; } else { if ( isLeapYear ( dat ) ) { str += "29" ; } else { str += "28" ; } } return str ;


signature:
public class DateHelper { /** * 判断二个时间是否在同一个周
 * @ param date1
 * @ param date2
 * @ return */
public static boolean isSameWeekDates ( Date date1 , Date date2 ) { } }

implementation:
Calendar cal1 = Calendar . getInstance ( ) ; Calendar cal2 = Calendar . getInstance ( ) ; cal1 . setTime ( date1 ) ; cal2 . setTime ( date2 ) ; int subYear = cal1 . get ( Calendar . YEAR ) - cal2 . get ( Calendar . YEAR ) ; if ( 0 == subYear ) { if ( cal1 . get ( Calendar . WEEK_OF_YEAR ) == cal2 . get ( Calendar . WEEK_OF_YEAR ) ) return true ; } else if ( 1 == subYear && 11 == cal2 . get ( Calendar . MONTH ) ) { // 如果12月的最后一周横跨来年第一周的话则最后一周即算做来年的第一周
if ( cal1 . get ( Calendar . WEEK_OF_YEAR ) == cal2 . get ( Calendar . WEEK_OF_YEAR ) ) return true ; } else if ( - 1 == subYear && 11 == cal1 . get ( Calendar . MONTH ) ) { if ( cal1 . get ( Calendar . WEEK_OF_YEAR ) == cal2 . get ( Calendar . WEEK_OF_YEAR ) ) return true ; } return false ;


signature:
public class DateHelper { /** * 产生周序列 , 即得到当前时间所在的年度是第几周
 * @ return */
public static String getSeqWeek ( ) { } }

implementation: Calendar c = Calendar . getInstance ( Locale . CHINA ) ; String week = Integer . toString ( c . get ( Calendar . WEEK_OF_YEAR ) ) ; if ( week . length ( ) == 1 ) week = "0" + week ; String year = Integer . toString ( c . get ( Calendar . YEAR ) ) ; return year + week ;


signature:
public class DateHelper { /** * 获得一个日期所在的周的星期几的日期 , 如要找出2002年2月3日所在周的星期一是几号
 * @ param sdate
 * @ param num
 * @ return */
public static String getWeek ( String sdate , String num ) { } }

implementation:
// 再转换为时间
Date dd = DateHelper . strToDate ( sdate ) ; Calendar c = Calendar . getInstance ( ) ; c . setTime ( dd ) ; if ( num . equals ( "1" ) ) // 返回星期一所在的日期
c . set ( Calendar . DAY_OF_WEEK , Calendar . MONDAY ) ; else if ( num . equals ( "2" ) ) // 返回星期二所在的日期
c . set ( Calendar . DAY_OF_WEEK , Calendar . TUESDAY ) ; else if ( num . equals ( "3" ) ) // 返回星期三所在的日期
c . set ( Calendar . DAY_OF_WEEK , Calendar . WEDNESDAY ) ; else if ( num . equals ( "4" ) ) // 返回星期四所在的日期
c . set ( Calendar . DAY_OF_WEEK , Calendar . THURSDAY ) ; else if ( num . equals ( "5" ) ) // 返回星期五所在的日期
c . set ( Calendar . DAY_OF_WEEK , Calendar . FRIDAY ) ; else if ( num . equals ( "6" ) ) // 返回星期六所在的日期
c . set ( Calendar . DAY_OF_WEEK , Calendar . SATURDAY ) ; else if ( num . equals ( "0" ) ) // 返回星期日所在的日期
c . set ( Calendar . DAY_OF_WEEK , Calendar . SUNDAY ) ; return new SimpleDateFormat ( "yyyy-MM-dd" ) . format ( c . getTime ( ) ) ;


signature:
public class DateHelper { /** * 根据一个日期 , 返回是星期几的字符串
 * @ param sdate
 * @ return */
public static String getWeek ( String sdate ) { } }

implementation:
// 再转换为时间
Date date = DateHelper . strToDate ( sdate ) ; Calendar c = Calendar . getInstance ( ) ; c . setTime ( date ) ; // int hour = c . get ( Calendar . DAY _ OF _ WEEK ) ;
// hour中存的就是星期几了 , 其范围 1 ~ 7
// 1 = 星期日 7 = 星期六 , 其他类推
return new SimpleDateFormat ( "EEEE" ) . format ( c . getTime ( ) ) ;


signature:
public class DateHelper { /** * 两个时间之间的天数
 * @ param date1
 * @ param date2
 * @ return */
public static long getDays ( String date1 , String date2 ) { } }

implementation:
if ( date1 == null || date1 . equals ( "" ) ) return 0 ; if ( date2 == null || date2 . equals ( "" ) ) return 0 ; // 转换为标准时间
SimpleDateFormat myFormatter = new SimpleDateFormat ( "yyyy-MM-dd" ) ; Date date = null ; Date mydate = null ; try { date = myFormatter . parse ( date1 ) ; mydate = myFormatter . parse ( date2 ) ; } catch ( Exception e ) { } long day = ( date . getTime ( ) - mydate . getTime ( ) ) / ( 24 * 60 * 60 * 1000 ) ; return day ;


signature:
public class DateHelper { /** * 形成如下的日历 , 根据传入的一个时间返回一个结构 星期日 星期一 星期二 星期三 星期四 星期五 星期六 下面是当月的各个时间
 * 此函数返回该日历第一行星期日所在的日期
 * @ param sdate
 * @ return */
public static String getNowMonth ( String sdate ) { } }

implementation:
// 取该时间所在月的一号
sdate = sdate . substring ( 0 , 8 ) + "01" ; // 得到这个月的1号是星期几
Date date = DateHelper . strToDate ( sdate ) ; Calendar c = Calendar . getInstance ( ) ; c . setTime ( date ) ; int u = c . get ( Calendar . DAY_OF_WEEK ) ; String newday = DateHelper . getNextDay ( sdate , 1 - u ) ; return newday ;


signature:
public class DateHelper { /** * 返回一个随机数
 * @ param i
 * @ return */
public static String getRandom ( int i ) { } }

implementation:
Random jjj = new Random ( ) ; // int suiJiShu = jjj . nextInt ( 9 ) ;
if ( i == 0 ) return "" ; String jj = "" ; for ( int k = 0 ; k < i ; k ++ ) { jj = jj + jjj . nextInt ( 9 ) ; } return jj ;


signature:
public class DateHelper { /** * 获取时间的日期 ( 转换为0时 )
 * @ param date
 * @ return */
public static Date getDay ( Date date ) { } }

implementation:
// long time = date . getTime ( ) / 1000;
// System . out . println ( time ) ;
// System . out . println ( CalendarHelper . DAY ) ;
// long day = 24 * 60 * 60;
// System . out . println ( time % ( day * 1000 ) ) ;
// System . out . println ( ( time % day ) / CalendarHelper . HOUR ) ;
// time = time - ( time % day ) ;
// Date date1 = new Date ( time * 1000 ) ;
String dateStr = FORMATTER_SHORT . format ( date ) ; Date date1 = strToDate ( dateStr , FORMATTER_SHORT ) ; return date1 ;


signature:
public class Log4jConfigurer { /** * Initialize log4j from the given file location , with no config file refreshing .
 * Assumes an XML file in case of a " . xml " file extension , and a properties file
 * otherwise .
 * @ param location the location of the config file : either a " classpath : " location
 * ( e . g . " classpath : myLog4j . properties " ) , an absolute file URL
 * ( e . g . " file : C : / log4j . properties ) , or a plain absolute path in the file system
 * ( e . g . " C : / log4j . properties " )
 * @ throws java . io . FileNotFoundException if the location specifies an invalid file path */
public static void initLogging ( String location ) throws FileNotFoundException { } }

implementation: String resolvedLocation = SystemPropertyUtils . resolvePlaceholders ( location ) ; URL url = ResourceUtils . getURL ( resolvedLocation ) ; if ( resolvedLocation . toLowerCase ( ) . endsWith ( XML_FILE_EXTENSION ) ) { DOMConfigurator . configure ( url ) ; } else { PropertyConfigurator . configure ( url ) ; }


signature:
public class Log4jConfigurer { /** * Initialize log4j from the given location , with the given refresh interval
 * for the config file . Assumes an XML file in case of a " . xml " file extension ,
 * and a properties file otherwise .
 * < p > Log4j ' s watchdog thread will asynchronously check whether the timestamp
 * of the config file has changed , using the given interval between checks .
 * A refresh interval of 1000 milliseconds ( one second ) , which allows to
 * do on - demand log level changes with immediate effect , is not unfeasible .
 * < p > < b > WARNING : < / b > Log4j ' s watchdog thread does not terminate until VM shutdown ;
 * in particular , it does not terminate on LogManager shutdown . Therefore , it is
 * recommended to < i > not < / i > use config file refreshing in a production J2EE
 * environment ; the watchdog thread would not stop on application shutdown there .
 * @ param location the location of the config file : either a " classpath : " location
 * ( e . g . " classpath : myLog4j . properties " ) , an absolute file URL
 * ( e . g . " file : C : / log4j . properties ) , or a plain absolute path in the file system
 * ( e . g . " C : / log4j . properties " )
 * @ param refreshInterval interval between config file refresh checks , in milliseconds
 * @ throws java . io . FileNotFoundException if the location specifies an invalid file path */
public static void initLogging ( String location , long refreshInterval ) throws FileNotFoundException { } }

implementation: String resolvedLocation = SystemPropertyUtils . resolvePlaceholders ( location ) ; File file = ResourceUtils . getFile ( resolvedLocation ) ; if ( ! file . exists ( ) ) { throw new FileNotFoundException ( "Log4j config file [" + resolvedLocation + "] not found" ) ; } if ( resolvedLocation . toLowerCase ( ) . endsWith ( XML_FILE_EXTENSION ) ) { DOMConfigurator . configureAndWatch ( file . getAbsolutePath ( ) , refreshInterval ) ; } else { PropertyConfigurator . configureAndWatch ( file . getAbsolutePath ( ) , refreshInterval ) ; }


signature:
public class AbstractStaxContentHandler { /** * Binds the given prefix to the given namespaces .
 * @ see SimpleNamespaceContext # bindNamespaceUri ( String , String ) */
@ Override public final void startPrefixMapping ( String prefix , String uri ) { } }

implementation: namespaceContext . bindNamespaceUri ( prefix , uri ) ; namespaceContextChanged = true ;


signature:
public class AbstractStaxContentHandler { /** * Convert a namespace URI and DOM or SAX qualified name to a { @ code QName } . The qualified name can have the form
 * { @ code prefix : localname } or { @ code localName } .
 * @ param namespaceUri the namespace URI
 * @ param qualifiedName the qualified name
 * @ return a QName */
protected QName toQName ( String namespaceUri , String qualifiedName ) { } }

implementation: int idx = qualifiedName . indexOf ( ':' ) ; if ( idx == - 1 ) { return new QName ( namespaceUri , qualifiedName ) ; } else { String prefix = qualifiedName . substring ( 0 , idx ) ; String localPart = qualifiedName . substring ( idx + 1 ) ; return new QName ( namespaceUri , localPart , prefix ) ; }


signature:
public class CompositeIterator { /** * Add given iterator to this composite . */
public void add ( Iterator < E > iterator ) { } }

implementation: Assert . state ( ! inUse , "You can no longer add iterator to a composite iterator that's already in use" ) ; if ( iterators . contains ( iterator ) ) { throw new IllegalArgumentException ( "You cannot add the same iterator twice" ) ; } iterators . add ( iterator ) ;


signature:
public class EmailService { /** * 发送邮件
 * @ param emailVo */
@ Override public void sendEmail ( EmailVo emailVo ) throws MessagingException { } }

implementation:
Assert . notNull ( emailVo . getTo ( ) , "接收人不能为空" ) ; MimeMessage msg = javaMailSenderFactory . createMimeMessage ( ) ; MimeMessageHelper msgHelper = null ; if ( ( emailVo . getInlineImageVos ( ) != null && emailVo . getInlineImageVos ( ) . size ( ) > 0 ) || ( emailVo . getAttachmentVos ( ) != null && emailVo . getAttachmentVos ( ) . size ( ) > 0 ) ) { msgHelper = new MimeMessageHelper ( msg , true , "utf-8" ) ; } else { msgHelper = new MimeMessageHelper ( msg , "utf-8" ) ; } if ( emailVo . getFrom ( ) == null || "" . equals ( emailVo . getFrom ( ) . trim ( ) ) ) { emailVo . setFrom ( javaMailSenderFactory . getSystemEmail ( ) ) ; } if ( ( emailVo . getCc ( ) == null || "" . equals ( emailVo . getCc ( ) . length == 0 ) ) && javaMailSenderFactory . getDefaultCc ( ) != null && ! javaMailSenderFactory . getDefaultCc ( ) . equals ( "" ) ) { emailVo . setCc ( javaMailSenderFactory . getDefaultCc ( ) . split ( "," ) ) ; } if ( ( emailVo . getBcc ( ) == null || "" . equals ( emailVo . getBcc ( ) . length == 0 ) ) && javaMailSenderFactory . getDefaultBcc ( ) != null && ! javaMailSenderFactory . getDefaultBcc ( ) . equals ( "" ) ) { emailVo . setBcc ( javaMailSenderFactory . getDefaultBcc ( ) . split ( "," ) ) ; } if ( emailVo . getMessageDate ( ) == null ) { emailVo . setMessageDate ( new Date ( ) ) ; } if ( emailVo . getCc ( ) != null ) { msgHelper . setCc ( emailVo . getCc ( ) ) ; // 抄送
} if ( emailVo . getBcc ( ) != null ) { msgHelper . setBcc ( emailVo . getBcc ( ) ) ; // 密送
} if ( emailVo . getSubject ( ) != null ) { msgHelper . setSubject ( emailVo . getSubject ( ) ) ; } handlerAttachments ( emailVo , msgHelper ) ; String from = null ; if ( emailVo . getFrom ( ) != null && ! "" . equals ( emailVo . getFrom ( ) ) ) { from = emailVo . getFrom ( ) ; } else { if ( javaMailSenderFactory . getEmailAccount ( ) . getFrom ( ) != null && ! "" . equals ( javaMailSenderFactory . getEmailAccount ( ) . getFrom ( ) ) ) { from = javaMailSenderFactory . getEmailAccount ( ) . getFrom ( ) ; } else { from = javaMailSenderFactory . getEmailAccount ( ) . getUsername ( ) ; } } try { if ( javaMailSenderFactory . getEmailAccount ( ) . getNickName ( ) != null ) { msgHelper . setFrom ( from , javaMailSenderFactory . getEmailAccount ( ) . getNickName ( ) ) ; } else { msgHelper . setFrom ( from ) ; } } catch ( UnsupportedEncodingException e ) { e . printStackTrace ( ) ; msgHelper . setFrom ( from ) ; } msgHelper . setTo ( emailVo . getTo ( ) ) ; // 接收人
Collection < Inline > inlines = handlerInlineImages ( emailVo , msgHelper ) ; if ( emailVo . getHtml ( ) != null ) { msgHelper . setText ( emailVo . getHtml ( ) , emailVo . isHtml ( ) ) ; if ( inlines != null ) { // 添加inline
for ( Inline inline : inlines ) { msgHelper . addInline ( inline . getContentId ( ) , inline . getFile ( ) ) ; } } } javaMailSenderFactory . send ( msg ) ;


signature:
public class EmailService { /** * 处理内嵌对象
 * @ param emailVo
 * @ param msgHelper
 * @ throws javax . mail . MessagingException */
private Collection < Inline > handlerInlineImages ( EmailVo emailVo , MimeMessageHelper msgHelper ) throws MessagingException { } }

implementation:
Collection < Inline > inlines = null ; if ( emailVo . getInlineImageVos ( ) != null && emailVo . getInlineImageVos ( ) . size ( ) > 0 ) { inlines = new HashSet < Inline > ( ) ; String html = emailVo . getHtml ( ) ; if ( html == null || html . trim ( ) . equals ( "" ) ) { // 如果内容空或者不是 html则直接跳过
return inlines ; } // - - - - - 查找带数字的标记 $ { 数字 } - - - - -
Matcher matcherIndexTag = PATTERN_FIND_TAG_AND_INDEX . matcher ( html ) ; int contentIdIndex = 0 ; while ( matcherIndexTag . find ( ) ) { String htmlTag = matcherIndexTag . group ( ) ; // 查找到 < img src = " $ { 1 } " / > 的内容
Matcher matcherDollar = PATTERN_DOLLAR_VARIABLE_INDEX . matcher ( htmlTag ) ; if ( matcherDollar . find ( ) ) { String dollarFind = matcherDollar . group ( ) ; // 查找到 $ { 1 } 内容
String indexStr = dollarFind . replace ( "$" , "" ) . replace ( "{" , "" ) . replace ( "}" , "" ) . trim ( ) ; // 移除外面的 $ 符号和大括号
int index = Integer . parseInt ( indexStr ) ; try { InlineImageVo inlineImageVo = emailVo . getInlineImageVos ( ) . get ( index ) ; File file = inlineImageVo . getFile ( ) ; String contentId = "file" + contentIdIndex ++ ; // 生成contentId
// msgHelper . addInline ( contentId , file ) ; / / 将附件内容传送给MimeMessageHelper
Inline inline = new Inline ( ) ; inline . setFile ( file ) ; inline . setContentId ( contentId ) ; inlines . add ( inline ) ; htmlTag = matcherDollar . replaceAll ( "cid:" + contentId ) ; // System . out . println ( " indexStr = = = = = " + indexStr ) ;
// System . out . println ( " htmlTag = = = = = " + htmlTag ) ;
html = matcherIndexTag . replaceFirst ( htmlTag ) ; matcherIndexTag = PATTERN_FIND_TAG_AND_INDEX . matcher ( html ) ; // System . out . println ( " html = = = = = " + html ) ;
} catch ( Exception e ) { e . printStackTrace ( ) ; } } } // - - - - - 查找带字母变量的标记 $ { variable } - - - - -
Matcher matcherTag = PATTERN_FIND_TAG . matcher ( html ) ; while ( matcherTag . find ( ) ) { String htmlTag = matcherTag . group ( ) ; // 查找到 < img src = " $ { 1 } " / > 的内容
Matcher matcherDollar = PATTERN_DOLLAR_VARIABLE_SELF_DEFINE . matcher ( htmlTag ) ; if ( matcherDollar . find ( ) ) { String dollarFind = matcherDollar . group ( ) ; // 查找到 $ { 1 } 内容
String dollarVariable = dollarFind . replace ( "$" , "" ) . replace ( "{" , "" ) . replace ( "}" , "" ) . trim ( ) ; // 移除外面的 $ 符号和大括号
try { InlineImageVo inlineImageVo = null ; for ( InlineImageVo imageVo : emailVo . getInlineImageVos ( ) ) { if ( imageVo . getContentId ( ) != null && imageVo . getContentId ( ) . equals ( dollarVariable ) ) { inlineImageVo = imageVo ; } } if ( inlineImageVo == null ) { continue ; } File file = inlineImageVo . getFile ( ) ; // String contentId = " file " + contentIdIndex + + ; / / 生成contentId
// msgHelper . addInline ( contentId , file ) ; / / 将附件内容传送给MimeMessageHelper
Inline inline = new Inline ( ) ; inline . setFile ( file ) ; inline . setContentId ( inlineImageVo . getContentId ( ) ) ; inlines . add ( inline ) ; htmlTag = matcherDollar . replaceAll ( "cid:" + inlineImageVo . getContentId ( ) ) ; // System . out . println ( " htmlTag = = = = = " + htmlTag ) ;
html = matcherTag . replaceFirst ( htmlTag ) ; matcherTag = PATTERN_FIND_TAG . matcher ( html ) ; // System . out . println ( " html = = = = = " + html ) ;
} catch ( Exception e ) { e . printStackTrace ( ) ; } } } emailVo . setHtml ( html ) ; if ( inlines != null && inlines . size ( ) > 0 ) { emailVo . setHtml ( true ) ; } } return inlines ;


signature:
public class EmailService { /** * 处理附件
 * @ param emailVo
 * @ param msgHelper
 * @ throws javax . mail . MessagingException */
private void handlerAttachments ( EmailVo emailVo , MimeMessageHelper msgHelper ) throws MessagingException { } }

implementation:
if ( emailVo . getAttachmentVos ( ) != null ) { // 检查附件
for ( AttachmentVo attachmentVo : emailVo . getAttachmentVos ( ) ) { File attachment = attachmentVo . getAttachment ( ) ; if ( attachment == null ) { InputStream inputStream = attachmentVo . getAttachmentInputStream ( ) ; if ( attachmentVo . getAttachmentName ( ) == null ) { attachmentVo . setAttachmentName ( new Date ( ) . toString ( ) ) ; } InputStreamSource inputStreamSource = new InputStreamResource ( inputStream ) ; msgHelper . addAttachment ( attachmentVo . getAttachmentName ( ) , inputStreamSource ) ; } else { if ( attachmentVo . getAttachmentName ( ) == null ) { attachmentVo . setAttachmentName ( attachment . getName ( ) ) ; } try { msgHelper . addAttachment ( MimeUtility . encodeWord ( attachmentVo . getAttachmentName ( ) ) , attachment ) ; } catch ( UnsupportedEncodingException e ) { e . printStackTrace ( ) ; } } } }


signature:
public class CodeBuilder { /** * 设置继承类
 * @ author 瑛琪 < a href = " http : / / xiongyingqi . com " > xiongyingqi . com < / a >
 * @ version 2014/3/20 0020 19:57 */
public CodeBuilder superClass ( Class < ? > clazz ) { } }

implementation:
if ( clazz . isInterface ( ) ) { System . out . println ( clazz + "为接口对象！取消设为继承类。" ) ; return this ; } String simpleName = clazz . getSimpleName ( ) ; Package pkg = clazz . getPackage ( ) ; imports . add ( pkg . getName ( ) + "." + simpleName ) ; // 导入包
this . superClass = simpleName ; // 设置继承的类名
return this ;


signature:
public class CodeBuilder { /** * 增加接口
 * @ param interfaceClass
 * @ return */
public CodeBuilder addInterface ( Class < ? > interfaceClass ) { } }

implementation:
if ( ! interfaceClass . isInterface ( ) ) { System . out . println ( interfaceClass + "不是接口类型！取消设为实现。" ) ; return this ; } String simpleName = interfaceClass . getSimpleName ( ) ; Package pkg = interfaceClass . getPackage ( ) ; imports . add ( pkg . getName ( ) + "." + simpleName ) ; // 导入包
this . interfaces . add ( simpleName ) ; // 添加实现的接口
return this ;


signature:
public class CodeBuilder { /** * 过滤包含规则 */
private void filterInclude ( ) { } }

implementation: if ( include == null || files == null ) { return ; } Set < File > toIncludes = new HashSet < File > ( ) ; for ( File file : files ) { Matcher matcher = include . matcher ( file . getPath ( ) ) ; if ( matcher . find ( ) ) { toIncludes . add ( file ) ; } } this . files = toIncludes ;


signature:
public class CodeBuilder { /** * 过滤排除规则 */
private void filterExclude ( ) { } }

implementation: if ( exclude == null || files == null ) { return ; } Set < File > toExcludes = new HashSet < File > ( ) ; for ( File file : files ) { Matcher matcher = exclude . matcher ( file . getPath ( ) ) ; if ( matcher . find ( ) ) { toExcludes . add ( file ) ; } } files . removeAll ( toExcludes ) ;


signature:
public class CodeBuilder { /** * 开始重写文件 */
public void build ( ) { } }

implementation:
filterInclude ( ) ; filterExclude ( ) ; for ( final File file : files ) { ThreadPool . invoke ( new Thread ( ) { @ Override public void run ( ) { new CodeProcessor ( file , CodeBuilder . this ) ; } } ) ; // 在线程池内运行
} ThreadPool . shutDown ( ) ; // 开启停止线程


signature:
public class CodeCondition { /** * 或者被 < code > orAnnotationClass < / code > 注解的条件 , 与andAnnotation方法冲突
 * @ param orAnnotationClass
 * @ return */
public CodeCondition orAnnotation ( Class < ? > orAnnotationClass ) { } }

implementation: if ( ! orAnnotationClass . isAnnotation ( ) ) { System . out . println ( "Class: " + orAnnotationClass + " 不是注解类！" ) ; return this ; } orAnnotatedClasses = CollectionHelper . checkOrInitHashSet ( orAnnotatedClasses ) ; orAnnotatedClasses . add ( orAnnotationClass ) ; return this ;


signature:
public class CodeCondition { /** * 并且被 < code > andAnnotationClass < / code > 注解的条件
 * @ param andAnnotationClass
 * @ return */
public CodeCondition andAnnotation ( Class < ? > andAnnotationClass ) { } }

implementation: if ( ! andAnnotationClass . isAnnotation ( ) ) { System . out . println ( "Class: " + andAnnotationClass + " 不是注解类！" ) ; return this ; } andAnnotatedClasses = CollectionHelper . checkOrInitHashSet ( andAnnotatedClasses ) ; andAnnotatedClasses . add ( andAnnotationClass ) ; return this ;


signature:
public class CodeCondition { /** * 条件且
 * @ param anotherCodeCondition
 * @ return */
public CodeCondition and ( CodeCondition anotherCodeCondition ) { } }

implementation: if ( anotherCodeCondition == null ) { System . out . println ( "CodeCondition为空！" ) ; return this ; } andCodeConditions = CollectionHelper . checkOrInitHashSet ( andCodeConditions ) ; return this ;


signature:
public class CodeCondition { /** * 条件或
 * @ param anotherCodeCondition
 * @ return */
public CodeCondition or ( CodeCondition anotherCodeCondition ) { } }

implementation: if ( anotherCodeCondition == null ) { System . out . println ( "CodeCondition为空！" ) ; return this ; } orCodeConditions = CollectionHelper . checkOrInitHashSet ( orCodeConditions ) ; return this ;


signature:
public class StringUtil { /** * 填充0 < br >
 * 2013-10-31 下午2:46:15
 * @ param number
 * @ param length
 * @ return */
public static String fillZero ( long number , int length ) { } }

implementation: StringBuilder builder = new StringBuilder ( ) ; int least = length - numberLength ( number ) ; char [ ] zeros = new char [ least ] ; for ( int i = 0 ; i < least ; i ++ ) { zeros [ i ] = '0' ; } builder . append ( new String ( zeros ) ) ; builder . append ( number ) ; return builder . toString ( ) ;


signature:
public class MD5Crypt { /** * Function to return a string from the set : A - Za - z0-9 . /
 * @ param size Length of the string
 * @ param v value to be converted
 * @ return A string of size ( size ) from the set A - Za - z0-9 . / */
static private final String to64 ( long v , int size ) { } }

implementation: StringBuffer result = new StringBuffer ( ) ; while ( -- size >= 0 ) { result . append ( itoa64 . charAt ( ( int ) ( v & 0x3f ) ) ) ; v >>>= 6 ; } return result . toString ( ) ;


signature:
public class MD5Crypt { /** * LINUX / BSD MD5Crypt function
 * @ param password Password to be encrypted
 * @ return The encrypted password as an MD5 hash */
static public final String crypt ( String password ) { } }

implementation:
StringBuffer salt = new StringBuffer ( ) ; java . util . Random rnd = new java . util . Random ( ) ; // build a random 8 chars salt
while ( salt . length ( ) < 8 ) { int index = ( int ) ( rnd . nextFloat ( ) * SALTCHARS . length ( ) ) ; salt . append ( SALTCHARS . substring ( index , index + 1 ) ) ; } // crypt
return crypt ( password , salt . toString ( ) , "$1$" ) ;


signature:
public class ClassLookupHelper { /** * 从所有的 classpath 下面搜索指定的 Class */
public static Collection < Class < ? > > getClasses ( ClassFileFilter filter ) { } }

implementation: Set < URLClassLoader > loaders = new LinkedHashSet < URLClassLoader > ( 8 ) ; loaders . addAll ( getClassLoaders ( Thread . currentThread ( ) . getContextClassLoader ( ) ) ) ; loaders . addAll ( getClassLoaders ( ClassLookupHelper . class . getClassLoader ( ) ) ) ; Set < Class < ? > > klasses = new LinkedHashSet < Class < ? > > ( ) ; for ( URLClassLoader cl : loaders ) { for ( URL url : cl . getURLs ( ) ) { String file = url . getFile ( ) ; if ( file . endsWith ( ".jar" ) || file . endsWith ( ".zip" ) ) { lookupClassesInJar ( null , url , true , cl , filter , klasses ) ; } else { lookupClassesInFileSystem ( null , new File ( file ) , true , cl , filter , klasses ) ; } } } return klasses ;


signature:
public class ClassLookupHelper { /** * 根据 baseClassLoader 找到所有的祖先 URLClassLoader ( 包括自己 ) */
private static Collection < URLClassLoader > getClassLoaders ( ClassLoader baseClassLoader ) { } }

implementation: Collection < URLClassLoader > loaders = new ArrayList < URLClassLoader > ( 8 ) ; ClassLoader loader = baseClassLoader ; while ( loader != null ) { if ( "sun.misc.Launcher$ExtClassLoader" . equals ( loader . getClass ( ) . getName ( ) ) ) { break ; } if ( loader instanceof URLClassLoader ) { loaders . add ( ( URLClassLoader ) loader ) ; } loader = loader . getParent ( ) ; } return loaders ;


signature:
public class ClassLookupHelper { /** * 从指定 package 中获取所有的 Class
 * @ param pkg 包
 * @ param recursive 是否递归查找
 * @ param filter class 过滤器
 * @ return 所有找到的 Class */
public static Set < Class < ? > > getClasses ( Package pkg , boolean recursive , ClassFileFilter filter ) { } }

implementation: return getClasses ( pkg . getName ( ) , recursive , filter ) ;


signature:
public class ClassLookupHelper { /** * 从指定 package 中获取所有的 Class
 * @ param packageName 包名
 * @ param recursive 是否递归查找
 * @ param filter class 过滤器
 * @ return 所有找到的 Class */
public static Set < Class < ? > > getClasses ( String packageName , boolean recursive , ClassFileFilter filter ) { } }

implementation: if ( packageName == null || packageName . length ( ) == 0 ) { throw new IllegalArgumentException ( "packageName is empty." ) ; } ClassLoader loader = Thread . currentThread ( ) . getContextClassLoader ( ) ; String packageDirName = packageName . replace ( '.' , '/' ) ; Collection < URL > urls ; try { Enumeration < URL > dirs = loader . getResources ( packageDirName ) ; urls = Collections . list ( dirs ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } Set < Class < ? > > klasses = new LinkedHashSet < Class < ? > > ( ) ; for ( URL url : urls ) { String protocol = url . getProtocol ( ) ; if ( "file" . equals ( protocol ) ) { lookupClassesInFileSystem ( packageName , new File ( url . getFile ( ) ) , recursive , loader , filter , klasses ) ; } else if ( "jar" . equals ( protocol ) ) { lookupClassesInJar ( packageName , url , recursive , loader , filter , klasses ) ; } } return klasses ;


signature:
public class ClassLookupHelper { /** * 以文件的形式来获取包下的所有 Class
 * @ param packageName JAVA包名
 * @ param packagePath 包所在的文件目录
 * @ param recursive 是否递归查找
 * @ param loader 负责该包的 ClassLoader
 * @ param filter class 过滤器
 * @ param klasses 返回找到的 class */
private static void lookupClassesInFileSystem ( String packageName , File packagePath , final boolean recursive , ClassLoader loader , ClassFileFilter filter , Set < Class < ? > > klasses ) { } }

implementation:
if ( ! packagePath . exists ( ) || ! packagePath . isDirectory ( ) ) { return ; } File [ ] dirfiles = packagePath . listFiles ( new FileFilter ( ) { public boolean accept ( File file ) { return ( recursive && file . isDirectory ( ) ) || ( file . getName ( ) . endsWith ( ".class" ) ) ; } } ) ; String packageNamePrefix = "" ; if ( packageName != null && packageName . length ( ) > 0 ) { packageNamePrefix = packageName + '.' ; } for ( File file : dirfiles ) { if ( file . isDirectory ( ) ) { lookupClassesInFileSystem ( packageNamePrefix + file . getName ( ) , file , recursive , loader , filter , klasses ) ; } else { // 去掉后面的 . class 只留下类名
String klassName = packageNamePrefix + file . getName ( ) . substring ( 0 , file . getName ( ) . length ( ) - 6 ) ; try { if ( filter == null || filter . accept ( klassName , file , loader ) ) { Class < ? > klass = loader . loadClass ( klassName ) ; klasses . add ( klass ) ; } } catch ( Throwable e ) { } } }


signature:
public class ClassLookupHelper { /** * 以在 Jar 包中获取指定包下的所有 Class
 * @ param packageName JAVA包名
 * @ param jarUrl Jar 包文件对应的 URL
 * @ param recursive 是否递归查找
 * @ param loader 负责该包的 ClassLoader
 * @ param filter class 过滤器
 * @ param klasses 返回找到的 class */
private static void lookupClassesInJar ( String packageName , URL jarUrl , boolean recursive , ClassLoader loader , ClassFileFilter filter , Set < Class < ? > > klasses ) { } }

implementation:
String packageDirName = "" ; if ( packageName != null && packageName . length ( ) > 0 ) { packageDirName = packageName . replace ( '.' , '/' ) + '/' ; } JarFile jar = null ; try { if ( "jar" . equals ( jarUrl . getProtocol ( ) ) ) { jar = ( ( JarURLConnection ) jarUrl . openConnection ( ) ) . getJarFile ( ) ; } else { jar = new JarFile ( jarUrl . getFile ( ) ) ; } Enumeration < JarEntry > entries = jar . entries ( ) ; while ( entries . hasMoreElements ( ) ) { // 获取jar里的一个实体 可以是目录和一些jar包里的其他文件 如META - INF等文件
JarEntry entry = entries . nextElement ( ) ; if ( entry . isDirectory ( ) ) { continue ; } String name = entry . getName ( ) ; if ( name . charAt ( 0 ) == '/' ) { name = name . substring ( 1 ) ; } if ( name . startsWith ( packageDirName ) && name . endsWith ( ".class" ) ) { if ( name . lastIndexOf ( '/' ) > packageDirName . length ( ) ) { // 在子包内
if ( ! recursive ) continue ; } // 去掉后面的 . class 只留下类名
String klassName = name . substring ( 0 , name . length ( ) - 6 ) ; klassName = klassName . replace ( '/' , '.' ) ; try { if ( filter == null || filter . accept ( klassName , jar , entry , loader ) ) { Class < ? > klass = loader . loadClass ( klassName ) ; klasses . add ( klass ) ; } } catch ( Throwable e ) { } } } } catch ( IOException e ) { } finally { }


signature:
public class ExceptionUtil { /** * Returns an input stream that contains what will written in this Application to
 * { @ link System # err } .
 * < b > Caution < / b >
 * If you do not consume the bytes to read from the result you may block the whole application . Do
 * only use this for debugging purposes or end to end test code !
 * Attempting to read from the result in the same thread that called here is not recommended as it
 * may deadlock the thread . Also the thread reading from the stream result should not write
 * anything to { @ link System # err } .
 * Prefer using { @ link # findMatchInSystemErr ( String ) } to avoid deadlocks .
 * @ param teeToOriginalSysErr
 * if true , all writes to the newly installed { @ link System # err } will also sent to the
 * original one ( thus be visible on the console if the original one was untouched
 * before ) .
 * @ return an input stream that contains what will written in this Application to
 * { @ link System # err } .
 * @ throws java . io . IOException
 * if something goes wrong . */
public static InputStream captureSystemErrForDebuggingPurposesOnly ( final boolean teeToOriginalSysErr ) throws IOException { } }

implementation: PipedOutputStream pipeOut = new PipedOutputStream ( ) ; PipedInputStream pipeIn = new PipedInputStream ( pipeOut ) ; OutputStream out = pipeOut ; if ( teeToOriginalSysErr ) { out = new MultiplexingOutputStream ( System . err , pipeOut ) ; } PrintStream streamOut = new PrintStream ( out ) ; System . setErr ( streamOut ) ; return pipeIn ;


signature:
public class ExceptionUtil { /** * Returns an input stream that contains what will written in this Application to
 * { @ link System # out } .
 * < b > Caution < / b >
 * If you do not consume the bytes to read from the result you may block the whole application . Do
 * only use this for debugging purposes or end to end test code !
 * Attempting to read from the result in the same thread that called here is not recommended as it
 * may deadlock the thread . Also the thread reading from the stream result should not write
 * anything to { @ link System # out } .
 * Prefer using { @ link # findMatchInSystemOut ( String ) } to avoid deadlocks .
 * @ param teeToOriginalSysOut
 * if true , all writes to the newly installed { @ link System # out } will also sent to the
 * original one ( thus be visible on the console if the original one was untouched
 * before ) .
 * @ return an input stream that contains what will written in this Application to
 * { @ link System # out } .
 * @ throws java . io . IOException
 * if something goes wrong . */
public static InputStream captureSystemOutForDebuggingPurposesOnly ( final boolean teeToOriginalSysOut ) throws IOException { } }

implementation: PipedOutputStream pipeOut = new PipedOutputStream ( ) ; PipedInputStream pipeIn = new PipedInputStream ( pipeOut ) ; OutputStream out = pipeOut ; if ( teeToOriginalSysOut ) { out = new MultiplexingOutputStream ( System . out , pipeOut ) ; } PrintStream streamOut = new PrintStream ( out ) ; System . setOut ( streamOut ) ; return pipeIn ;


signature:
public class ExceptionUtil { /** * Returns an instance to a runnable running in a separate Thread that tries to match the expected
 * output in { @ link System # out } .
 * Ensure that you found the expected String in the input stream given by calling
 * { @ link info . monitorenter . util . ExceptionUtil . InputStreamTracer # isMatched ( ) } . But take into account that it is time -
 * critical ( concurrency ) if your result was found .
 * Prefer this instead of { @ link # captureSystemOutForDebuggingPurposesOnly ( boolean ) } as this will
 * avoid blocking your application .
 * @ return an instance to a runnable running in a separate Thread that tries to match the expected
 * output in { @ link System # out } .
 * @ throws java . io . IOException
 * if something goes wrong . */
public static InputStreamTracer findMatchInSystemOut ( final String expectMatch ) throws IOException { } }

implementation: InputStream systemout = captureSystemOutForDebuggingPurposesOnly ( true ) ; InputStreamTracer result = new InputStreamTracer ( systemout , expectMatch , Charset . defaultCharset ( ) ) ; Thread traceThread = new Thread ( result ) ; traceThread . setDaemon ( true ) ; traceThread . start ( ) ; return result ;


signature:
public class ExceptionUtil { /** * Returns an instance to a runnable running in a separate Thread that tries to match the expected
 * output in { @ link System # err } .
 * Ensure that you found the expected String in the input stream given by calling
 * { @ link info . monitorenter . util . ExceptionUtil . InputStreamTracer # isMatched ( ) } . But take into account that it is time -
 * critical ( concurrency ) if your result was found .
 * Prefer this instead of { @ link # captureSystemErrForDebuggingPurposesOnly ( boolean ) } as this will
 * avoid blocking your application .
 * @ return an instance to a runnable running in a separate Thread that tries to match the expected
 * output in { @ link System # out } .
 * @ throws java . io . IOException
 * if something goes wrong . */
public static InputStreamTracer findMatchInSystemErr ( final String expectMatch ) throws IOException { } }

implementation: InputStream systemout = captureSystemErrForDebuggingPurposesOnly ( true ) ; InputStreamTracer result = new InputStreamTracer ( systemout , expectMatch , Charset . defaultCharset ( ) ) ; Thread traceThread = new Thread ( result ) ; traceThread . setDaemon ( true ) ; traceThread . start ( ) ; return result ;


signature:
public class ExceptionUtil { /** * Prints out the current Thread stack to the given stream .
 * @ see Thread # getStackTrace ( )
 * @ param outprint
 * the stream to print to ( e . g . < code > { @ link System # err } < / code > ) . */
public static void dumpThreadStack ( PrintStream outprint ) { } }

implementation: StackTraceElement [ ] stackTrace = Thread . currentThread ( ) . getStackTrace ( ) ; String stackTraceString = StringUtil . arrayToString ( stackTrace , "\n" ) ; outprint . println ( stackTraceString ) ;


signature:
public class ExceptionUtil { /** * Returns the singleton instance of this class .
 * This method is useless for now as all methods are static . It may be used in future if VM - global
 * configuration will be put to the state of the instance .
 * @ return the singleton instance of this class . */
public static ExceptionUtil instance ( ) { } }

implementation: if ( ExceptionUtil . instance == null ) { ExceptionUtil . instance = new ExceptionUtil ( ) ; } return ExceptionUtil . instance ;


signature:
public class CmdLineParser { /** * Add the specified Option to the list of accepted options */
public final Option addOption ( Option opt ) { } }

implementation: if ( opt . shortForm ( ) != null ) this . options . put ( "-" + opt . shortForm ( ) , opt ) ; this . options . put ( "--" + opt . longForm ( ) , opt ) ; return opt ;


signature:
public class CmdLineParser { /** * Convenience method for adding a string option .
 * @ return the new Option */
public final Option addStringOption ( char shortForm , String longForm ) { } }

implementation: return addOption ( new Option . StringOption ( shortForm , longForm ) ) ;


signature:
public class CmdLineParser { /** * Convenience method for adding an integer option .
 * @ return the new Option */
public final Option addIntegerOption ( char shortForm , String longForm ) { } }

implementation: return addOption ( new Option . IntegerOption ( shortForm , longForm ) ) ;


signature:
public class CmdLineParser { /** * Convenience method for adding a long integer option .
 * @ return the new Option */
public final Option addLongOption ( char shortForm , String longForm ) { } }

implementation: return addOption ( new Option . LongOption ( shortForm , longForm ) ) ;


signature:
public class CmdLineParser { /** * Convenience method for adding a double option .
 * @ return the new Option */
public final Option addDoubleOption ( char shortForm , String longForm ) { } }

implementation: return addOption ( new Option . DoubleOption ( shortForm , longForm ) ) ;


signature:
public class CmdLineParser { /** * Convenience method for adding a boolean option .
 * @ return the new Option */
public final Option addBooleanOption ( char shortForm , String longForm ) { } }

implementation: return addOption ( new Option . BooleanOption ( shortForm , longForm ) ) ;


signature:
public class CmdLineParser { /** * Extract the options and non - option arguments from the given
 * list of command - line arguments . The specified locale is used for
 * parsing options whose values might be locale - specific . */
public final void parse ( String [ ] argv , Locale locale ) throws IllegalOptionValueException , UnknownOptionException { } }

implementation:
// It would be best if this method only threw OptionException , but for
// backwards compatibility with old user code we throw the two
// exceptions above instead .
Vector otherArgs = new Vector ( ) ; int position = 0 ; this . values = new Hashtable ( 10 ) ; while ( position < argv . length ) { String curArg = argv [ position ] ; if ( curArg . startsWith ( "-" ) ) { if ( curArg . equals ( "--" ) ) { // end of options
position += 1 ; break ; } String valueArg = null ; if ( curArg . startsWith ( "--" ) ) { // handle - - arg = value
int equalsPos = curArg . indexOf ( "=" ) ; if ( equalsPos != - 1 ) { valueArg = curArg . substring ( equalsPos + 1 ) ; curArg = curArg . substring ( 0 , equalsPos ) ; } } else if ( curArg . length ( ) > 2 ) { // handle - abcd
for ( int i = 1 ; i < curArg . length ( ) ; i ++ ) { Option opt = ( Option ) this . options . get ( "-" + curArg . charAt ( i ) ) ; if ( opt == null ) throw new UnknownSuboptionException ( curArg , curArg . charAt ( i ) ) ; if ( opt . wantsValue ( ) ) throw new NotFlagException ( curArg , curArg . charAt ( i ) ) ; addValue ( opt , opt . getValue ( null , locale ) ) ; } position ++ ; continue ; } Option opt = ( Option ) this . options . get ( curArg ) ; if ( opt == null ) { throw new UnknownOptionException ( curArg ) ; } Object value = null ; if ( opt . wantsValue ( ) ) { if ( valueArg == null ) { position += 1 ; if ( position < argv . length ) { valueArg = argv [ position ] ; } } value = opt . getValue ( valueArg , locale ) ; } else { value = opt . getValue ( null , locale ) ; } addValue ( opt , value ) ; position += 1 ; } else { otherArgs . addElement ( curArg ) ; position += 1 ; } } for ( ; position < argv . length ; ++ position ) { otherArgs . addElement ( argv [ position ] ) ; } this . remainingArgs = new String [ otherArgs . size ( ) ] ; otherArgs . copyInto ( remainingArgs ) ;


signature:
public class AbstractCodepageDetector { /** * A default delegation to { @ link # detectCodepage ( java . net . URL ) } that opens the document specified by the given URL with the
 * detected codepage .
 * @ see ICodepageDetector # open ( java . net . URL ) */
public final Reader open ( final URL url ) throws IOException { } }

implementation: Reader ret = null ; Charset cs = this . detectCodepage ( url ) ; if ( cs != null ) { ret = new InputStreamReader ( new BufferedInputStream ( url . openStream ( ) ) , cs ) ; } return ret ;


signature:
public class StackTraceHelper { /** * 打印出调用堆栈 < br >
 * 2013-8-28 下午3:52:17 */
public static void printStackTrace ( ) { } }

implementation:
Throwable throwable = new Throwable ( ) ; StackTraceElement [ ] stackTraceElements = throwable . getStackTrace ( ) ; StackTraceElement [ ] stackTraceElementsTarget = new StackTraceElement [ stackTraceElements . length - 1 ] ; // for ( int i = 1 , j = 0 ; i < stackTraceElements . length ; i + + ) {
// StackTraceElement stackTraceElement = stackTraceElements [ i ] ;
// System . out . println ( stackTraceElement . getClassName ( ) ) ;
// System . out . println ( stackTraceElement . getFileName ( ) ) ;
// System . out . println ( stackTraceElement . getMethodName ( ) ) ;
// System . out . println ( stackTraceElement . getLineNumber ( ) ) ;
// System . out . println ( " at " + stackTraceElement . getClassName ( ) + " . "
// + stackTraceElement . getMethodName ( ) + " ( " +
// stackTraceElement . getFileName ( ) + " : " +
// stackTraceElement . getLineNumber ( ) + " ) " ) ;
System . arraycopy ( stackTraceElements , 1 , stackTraceElementsTarget , 0 , stackTraceElementsTarget . length ) ; System . out . println ( " ----------------------- StackTrace Info ----------------------- " ) ; System . out . print ( buildStackTrace ( stackTraceElementsTarget ) ) ;


signature:
public class StackTraceHelper { /** * 组织堆栈信息 , 将堆栈数组拼接成字符串 < br >
 * 2013-8-28 下午3:50:50
 * @ param stackTraceElements
 * @ return String */
public static String buildStackTrace ( StackTraceElement [ ] stackTraceElements ) { } }

implementation: StringBuilder builder = new StringBuilder ( ) ; for ( int i = 0 ; i < stackTraceElements . length ; i ++ ) { StackTraceElement stackTraceElement = stackTraceElements [ i ] ; builder . append ( "    at " ) ; builder . append ( stackTraceElement . getClassName ( ) ) ; builder . append ( "." ) ; builder . append ( stackTraceElement . getMethodName ( ) ) ; builder . append ( "(" ) ; builder . append ( stackTraceElement . getFileName ( ) ) ; builder . append ( ":" ) ; builder . append ( stackTraceElement . getLineNumber ( ) ) ; builder . append ( ")" ) ; builder . append ( StringHelper . line ( ) ) ; } return builder . toString ( ) ;


signature:
public class StackTraceHelper { /** * 返回不包括本类调用堆栈的当前堆栈 < br >
 * 2013-7-26 下午6:09:09
 * @ return */
public static StackTraceElement [ ] getStackTrace ( ) { } }

implementation: Throwable throwable = new Throwable ( ) ; StackTraceElement [ ] stackTraceElements = throwable . getStackTrace ( ) ; StackTraceElement [ ] stackTraceElementsTarget = new StackTraceElement [ stackTraceElements . length ] ; System . arraycopy ( stackTraceElements , 0 , stackTraceElementsTarget , 0 , stackTraceElementsTarget . length ) ; return stackTraceElementsTarget ;


signature:
public class StackTraceHelper { /** * 获取间接调用的类名 < p > < / p >
 * 比如A方法调用B方法 , B方法再调用whoInvoke ( ) 方法 , 这样B方法内就能返回A方法在那个类下
 * @ return */
public static Class whoInvoke ( ) { } }

implementation: Throwable throwable = new Throwable ( ) ; StackTraceElement [ ] stackTraceElements = throwable . getStackTrace ( ) ; StackTraceElement stackTraceElement = stackTraceElements [ 2 ] ; try { return Class . forName ( stackTraceElement . getClassName ( ) ) ; } catch ( ClassNotFoundException e ) { e . printStackTrace ( ) ; } return null ;


signature:
public class Logger { /** * - - - - - debug - - - - - */
public static void debug ( Object object , Object message ) { } }

implementation: Class clazz = object . getClass ( ) ; debug ( clazz , message ) ;


signature:
public class AnnotationHelper { /** * 读取field的注解值 ( 包括get 、 set方法 )
 * @ param field
 * @ param annotationClass
 * @ param < T >
 * @ return */
public static < T extends Annotation > T readAnnotationValueOnField ( Field field , Class < T > annotationClass ) { } }

implementation: if ( field . isAnnotationPresent ( annotationClass ) ) { T t = field . getAnnotation ( annotationClass ) ; return t ; } else { Method method = EntityHelper . findGetMethod ( field ) ; if ( method . isAnnotationPresent ( annotationClass ) ) { T t = method . getAnnotation ( annotationClass ) ; return t ; } return null ; }


signature:
public class AnnotationHelper { /** * 在类内搜索所有的字段的annotationClass注解值
 * @ param clazz
 * @ param annotationClass
 * @ param < T >
 * @ return */
public static < T extends Annotation > Collection < T > readAnnotationsInClass ( Class < ? > clazz , Class < T > annotationClass ) { } }

implementation: Collection < T > collection = null ; Field [ ] fields = clazz . getDeclaredFields ( ) ; for ( Field field : fields ) { T t = readAnnotationValueOnField ( field , annotationClass ) ; if ( t == null ) { continue ; } if ( collection == null ) { collection = new ArrayList < T > ( ) ; } collection . add ( t ) ; } return collection ;


signature:
public class AnnotationHelper { /** * 在类内搜索使用annotationClass注解的字段 ( 包括在get 、 set方法上注解 )
 * @ param inClazz
 * @ param annotationClass
 * @ param < T >
 * @ return */
public static < T extends Annotation > Collection < Field > getFieldsWithAnnotationInClass ( Class < ? > inClazz , Class < T > annotationClass ) { } }

implementation: Collection < Field > fieldCollection = null ; Field [ ] fields = inClazz . getDeclaredFields ( ) ; for ( Field field : fields ) { if ( Modifier . isStatic ( field . getModifiers ( ) ) || Modifier . isFinal ( field . getModifiers ( ) ) ) { continue ; } T t = readAnnotationValueOnField ( field , annotationClass ) ; if ( t == null ) { continue ; } if ( fieldCollection == null ) { fieldCollection = new ArrayList < Field > ( ) ; } fieldCollection . add ( field ) ; } return fieldCollection ;


signature:
public class StringHelper { /** * 从第一个字符开始比较两个字符串的大小 ( 按照单个字符的ascii码比较 ) , 例如 : " abc " 大于 " aac " 、 " 1234 " 小于 " 2234 " 、 " 1234 " 大于 " 123 " 、 " 223 " 大于 " 1234"
 * @ param firstString 第一个字符串
 * @ param secondString 第二个字符串
 * @ return 如果第一个字符串小于第二个字符串 , 则返回true , 否则返回false */
public static boolean compareNumberString ( String firstString , String secondString ) { } }

implementation: Assert . notNull ( firstString , "第一个字符串为空！" ) ; Assert . notNull ( secondString , "第二个字符串为空！" ) ; char [ ] chars1 = firstString . toCharArray ( ) ; char [ ] chars2 = secondString . toCharArray ( ) ; int length1 = chars1 . length ; int length2 = chars2 . length ; int maxLength = length1 > length2 ? length1 : length2 ; for ( int i = 0 ; i < maxLength ; i ++ ) { int value1 = - 1 ; int value2 = - 1 ; if ( i < length1 ) { value1 = chars1 [ i ] ; } if ( i < length2 ) { value2 = chars2 [ i ] ; } if ( value1 < value2 ) { return true ; } else { return false ; } } return false ;


signature:
public class StringHelper { /** * 计算数组的hashCode < br >
 * 2013-10-25 上午11:06:57
 * @ param stringArray
 * @ return */
public static int hashCodeOfStringArray ( String [ ] stringArray ) { } }

implementation: if ( stringArray == null ) { return 0 ; } int hashCode = 17 ; for ( int i = 0 ; i < stringArray . length ; i ++ ) { String value = stringArray [ i ] ; hashCode = hashCode * 31 + ( value == null ? 0 : value . hashCode ( ) ) ; } return hashCode ;


signature:
public class StringHelper { /** * 换行符 < br >
 * 2013-8-14 下午1:20:06
 * @ return */
public static String line ( ) { } }

implementation:
String lineSeparator = java . security . AccessController . doPrivileged ( new sun . security . action . GetPropertyAction ( "line.separator" ) ) ; // String lineSeparator = System . getProperty ( " line . separator " ) ;
return lineSeparator ;


signature:
public class StringHelper { /** * < br >
 * 2013-8-28 下午5:26:24
 * @ param str
 * @ return */
public static String convertEncode ( String str ) { } }

implementation: if ( nullOrEmpty ( str ) ) { return null ; } try { return new String ( str . getBytes ( ) , "UTF-8" ) ; } catch ( UnsupportedEncodingException e ) { e . printStackTrace ( ) ; } return str ;


signature:
public class StringHelper { /** * StringReader转换为字符串 < br >
 * 2013-9-2 下午9:03:29
 * @ param reader
 * @ return */
public String stringReaderToString ( StringReader reader ) { } }

implementation: StringBuilder builder = new StringBuilder ( ) ; char [ ] buffer = new char [ 128 ] ; int length = - 1 ; try { while ( ( length = reader . read ( buffer ) ) != - 1 ) { if ( buffer . length != length ) { System . arraycopy ( buffer , 0 , buffer , 0 , length ) ; } builder . append ( buffer ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } finally { reader . close ( ) ; } return builder . toString ( ) ;


signature:
public class SingletonLoader { /** * High - level method for instantiation of a new instance of the class specified by the given fully qualified class
 * name with singleton retrieval support . Delegates to { @ link # newInstance ( Class ) } . */
public Object newInstance ( String fullyQualifiedClassName ) throws InstantiationException , IllegalAccessException , ClassNotFoundException { } }

implementation: Object ret = this . newInstance ( Class . forName ( fullyQualifiedClassName ) ) ; return ret ;


signature:
public class SingletonLoader { /** * Dynamic instantiation of the given type with singleton retrieval support as described in this class description . */
public Object newInstance ( Class c ) throws InstantiationException , IllegalAccessException { } }

implementation:
Object ret = null ; Method [ ] methods = c . getDeclaredMethods ( ) ; Method m ; int modifiers ; // searching for static methods :
for ( int i = 0 ; i < methods . length ; i ++ ) { m = methods [ i ] ; modifiers = m . getModifiers ( ) ; if ( ( modifiers & Modifier . STATIC ) != 0 ) { // searching for public access :
if ( ( modifiers & Modifier . PUBLIC ) != 0 ) { // searching for no parameters :
if ( m . getParameterTypes ( ) . length == 0 ) { // searching for return type :
if ( m . getReturnType ( ) == c ) { // searching for substring " instance " in method name :
if ( m . getName ( ) . toLowerCase ( ) . indexOf ( "instance" ) != - 1 ) { try { // Finally we found a singleton method :
// we are static and don ' t need an instance .
ret = m . invoke ( null , dummyParameters ) ; } catch ( IllegalArgumentException e ) { // This will not happen :
// we ensured that no arguments are needed .
e . printStackTrace ( ) ; } catch ( IllegalAccessException e ) { // This will not happen ( only in applet context perhaps or with some
// SecurityManager ) :
// we ensured public access .
e . printStackTrace ( ) ; } catch ( InvocationTargetException e ) { e . printStackTrace ( ) ; } } } } } } } // check , if we found a singleton :
if ( ret == null ) { // try to invoke the default constructor :
Constructor [ ] constructors = c . getConstructors ( ) ; Constructor con = null ; // search for a parameterless constructor :
for ( int i = 0 ; i < constructors . length ; i ++ ) { con = constructors [ i ] ; if ( con . getParameterTypes ( ) . length == 0 ) { // see , if public :
modifiers = con . getModifiers ( ) ; try { if ( ( modifiers & Modifier . PUBLIC ) == 0 ) { // try to set accessible :
con . setAccessible ( true ) ; } // invokes the default constructor
ret = c . newInstance ( ) ; } catch ( SecurityException se ) { // damn
} } } } if ( ret == null ) { System . err . println ( "Unable to instantiate: " + c . getName ( ) + ": no singleton method, no public default constructor." ) ; } return ret ;


signature:
public class CodepageDetectorProxy { /** * Singleton retrieval method .
 * Be sure to configure the instance returned at a single location in your
 * code to avoid unpredictable application - wide side effects .
 * @ return the sole instance in this VM . */
public static CodepageDetectorProxy getInstance ( ) { } }

implementation: if ( CodepageDetectorProxy . instance == null ) { CodepageDetectorProxy . instance = new CodepageDetectorProxy ( ) ; } return CodepageDetectorProxy . instance ;


signature:
public class CodepageDetectorProxy { /** * Detects the codepage by iteratively delegating the call to all internal
 * { @ link info . monitorenter . cpdetector . io . ICodepageDetector } instances added by
 * { @ link # add ( info . monitorenter . cpdetector . io . ICodepageDetector ) } .
 * The given InputStream has to support mark such that the call
 * { @ link java . io . InputStream # mark ( int ) } with argument length does not throw an
 * exception . This is needed , as the stream has to be resetted to the
 * beginning for each internal delegate that tries to detect .
 * If this is impossible ( large documents ) , prefer using
 * { @ link # detectCodepage ( java . net . URL ) } .
 * @ param in
 * An InputStream for the document , that supports mark and a
 * readlimit of argument length .
 * @ param length
 * The amount of bytes to take into account . This number shouls not
 * be longer than the amount of bytes retrievable from the
 * InputStream but should be as long as possible to give the fallback
 * detection ( chardet ) more hints to guess .
 * @ throws IllegalArgumentException
 * if more bytes had to be read from the input stream than param
 * length or the given input stream does not support marking . */
public Charset detectCodepage ( final InputStream in , final int length ) throws IOException , IllegalArgumentException { } }

implementation:
if ( ! in . markSupported ( ) ) { throw new IllegalArgumentException ( "The given input stream (" + in . getClass ( ) . getName ( ) + ") has to support for marking." ) ; } Charset ret = null ; int markLimit = length ; Iterator < ICodepageDetector > detectorIt = this . detectors . iterator ( ) ; while ( detectorIt . hasNext ( ) ) { in . mark ( markLimit ) ; ret = detectorIt . next ( ) . detectCodepage ( in , length ) ; // if more bytes have been read than marked ( length ) this will throw an
// exception :
try { in . reset ( ) ; } catch ( IOException ioex ) { IllegalStateException ise = new IllegalStateException ( "More than the given length had to be read and the given stream could not be reset. Undetermined state for this detection." ) ; ise . initCause ( ioex ) ; throw ise ; } if ( ret != null ) { if ( ret != UnknownCharset . getInstance ( ) ) { if ( ret instanceof UnsupportedCharset ) { // TODO : Debug logging : found illegal charset tag or encoding
// declaration .
} else { break ; } } } } return ret ;


signature:
public class AopTargetUtils { /** * 获取 目标对象
 * @ param proxy 代理对象
 * @ return
 * @ throws Exception */
public static Object getTarget ( Object proxy ) throws Exception { } }

implementation:
if ( ! AopUtils . isAopProxy ( proxy ) ) { return proxy ; // 不是代理对象
} if ( AopUtils . isJdkDynamicProxy ( proxy ) ) { return getJdkDynamicProxyTargetObject ( proxy ) ; } else { // cglib
return getCglibProxyTargetObject ( proxy ) ; }


signature:
public class CalendarHelper { /** * 返回两个日期的毫秒之差
 * @ param nearDate
 * @ param farDate
 * @ return */
public static long compareDate ( Date nearDate , Date farDate ) { } }

implementation: long nearMilli = nearDate . getTime ( ) ; long farMilli = farDate . getTime ( ) ; long result = nearMilli - farMilli ; if ( result < 0 ) { result = - result ; } return result ;


signature:
public class CalendarHelper { /** * 计算指定日期到现在的时间计算
 * @ param date
 * @ return */
public static String caculatorDateToString ( Date date ) { } }

implementation:
long milliSecond = compareDate ( date ) ; List dateCaculators = DateCalculator . getDateCalculators ( ) ; for ( Iterator iterator = dateCaculators . iterator ( ) ; iterator . hasNext ( ) ; ) { DateCalculator dateCalculator = ( DateCalculator ) iterator . next ( ) ; if ( milliSecond >= dateCalculator . getMinMilliSecond ( ) && milliSecond <= dateCalculator . getMaxMilliSecond ( ) ) { String displayStr = dateCalculator . getDisplayStr ( ) ; long numberOfUnit = 0 ; if ( dateCalculator . getMinMilliSecond ( ) == 0 ) { // 分母为零 , 则直接为0
numberOfUnit = 0 ; } else { numberOfUnit = milliSecond / dateCalculator . getMinMilliSecond ( ) ; } // 替代所有 { 0}
Pattern p = Pattern . compile ( "(\\{.+?\\})" ) ; Matcher m = p . matcher ( displayStr ) ; displayStr = m . replaceAll ( numberOfUnit + "" ) ; // displayStr = displayStr . replace ( " \ \ { 0 \ \ } " , numberOfUnit +
return displayStr ; } } return milliSecond + "" ;


signature:
public class Entry { /** * Sets a new value instance overwriting the old value which is returned .
 * You may use null . But you will get it back next call !
 * @ see java . util . Map . Entry # setValue ( Object )
 * @ return the previous value instance . */
public K setValue ( final K value ) { } }

implementation: final K ret = this . m_value ; this . m_value = value ; return ret ;


signature:
public class QRCodeGenerator { /** * 生成文件
 * @ return 返回二维码文件 */
public File generate ( ) { } }

implementation: QRCode qrCode = new QRCode ( ) ; File file = qrCode . encode ( profile ) ; return file ;


signature:
public class PackageScanner { /** * 增加扫描的包
 * @ param pkg
 * @ return */
public PackageScanner addPackage ( String pkg ) { } }

implementation: Package aPackage = Package . getPackage ( pkg ) ; addPackage ( aPackage ) ; return this ;


signature:
public class PackageScanner { /** * 开始扫描
 * @ return */
public Collection < Class < ? > > scan ( ) { } }

implementation: Assert . notEmpty ( packages , "待扫描的包为空！" ) ; Collection < Class < ? > > classes = new ArrayList < Class < ? > > ( ) ; ClassLookupHelper . ClassFileFilter classFileFilter = new ClassLookupHelper . ClassFileFilter ( ) { @ Override public boolean accept ( String klassName , File file , ClassLoader loader ) { return true ; } @ Override public boolean accept ( String klassName , JarFile jar , JarEntry entry , ClassLoader loader ) { return true ; } } ; for ( Package pkg : packages ) { Set < Class < ? > > scanClasses = ClassLookupHelper . getClasses ( pkg , recursive , classFileFilter ) ; for ( Class < ? > scanClass : scanClasses ) { if ( isAnnotationPassed ( scanClass ) && isStartWithPassed ( scanClass ) && isInterfacePassed ( scanClass ) ) { classes . add ( scanClass ) ; } } } return classes ;


signature:
public class FileFilterExtensions { /** * / * ( non - Javadoc )
 * @ see java . io . FileFilter # accept ( java . io . File ) */
public boolean accept ( File pathname ) { } }

implementation:
boolean ret = false ; // search for extension without dot .
StringTokenizer tokenizer = new StringTokenizer ( pathname . getAbsolutePath ( ) , "." ) ; String extension = "no.txt" ; // a dot , because verify will not allow these tokens : won ' t accept , if no extension in pathname .
while ( tokenizer . hasMoreElements ( ) ) { extension = tokenizer . nextToken ( ) ; } for ( int i = this . m_extensions . length - 1 ; i >= 0 ; i -- ) { if ( this . m_extensions [ i ] . equals ( extension ) ) { ret = true ; break ; } } return ret ;


signature:
public class QRCode { /** * 生成QRCode二维码 */
public File encode ( Profile profile ) { } }

implementation:
try { File isFile = new File ( profile . getPath ( ) ) ; if ( ! isFile . exists ( ) ) { isFile . mkdirs ( ) ; } SimpleDateFormat sdf = new SimpleDateFormat ( "yyyyMMddHHmmss" ) ; String fileName = UUID . randomUUID ( ) + "." + profile . getFormat ( ) ; // String url = zxing . getPath ( ) + fileName ;
File file = new File ( profile . getPath ( ) , fileName ) ; // writeToFile ( bitMatrix , profile . getFormat ( ) , file , profile . isLogoFlag ( ) , profile . getLogoPath ( ) ) ;
BufferedImage bufferedImage = encodeToBufferedImage ( profile ) ; ImageIO . write ( bufferedImage , profile . getFormat ( ) , file ) ; return file ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return null ;


signature:
public class QRCode { /** * 生成二维码内容
 * @ param bitMatrix
 * @ return */
public BufferedImage toBufferedImageContents ( BitMatrix bitMatrix ) { } }

implementation: int width = bitMatrix . getWidth ( ) ; int height = bitMatrix . getHeight ( ) ; BufferedImage image = new BufferedImage ( width , height , BufferedImage . TYPE_INT_RGB ) ; for ( int x = 0 ; x < width ; x ++ ) { for ( int y = 0 ; y < height ; y ++ ) { image . setRGB ( x , y , bitMatrix . get ( x , y ) == true ? BLACK : WHITE ) ; } } return image ;


signature:
public class QRCode { /** * 解析二维码
 * @ param path 图片的绝对路径 */
public String decode ( String path ) throws IOException , NotFoundException { } }

implementation:
if ( path == null || path . equals ( "" ) ) { System . out . println ( "文件路径不能为空!" ) ; } File file = new File ( path ) ; BufferedImage image = ImageIO . read ( file ) ; /* 判断是否是图片 */
if ( image != null ) { return decode ( image ) ; } return null ;


signature:
public class ConcurrencyThrottleSupport { /** * To be invoked before the main execution logic of concrete subclasses .
 * < p > This implementation applies the concurrency throttle .
 * @ see # afterAccess ( ) */
protected void beforeAccess ( ) { } }

implementation:
if ( this . concurrencyLimit == NO_CONCURRENCY ) { throw new IllegalStateException ( "Currently no invocations allowed - concurrency limit set to NO_CONCURRENCY" ) ; } if ( this . concurrencyLimit > 0 ) { boolean debug = logger . isDebugEnabled ( ) ; synchronized ( this . monitor ) { boolean interrupted = false ; while ( this . concurrencyCount >= this . concurrencyLimit ) { if ( interrupted ) { throw new IllegalStateException ( "Thread was interrupted while waiting for invocation access, " + "but concurrency limit still does not allow for entering" ) ; } if ( debug ) { logger . debug ( "Concurrency count " + this . concurrencyCount + " has reached limit " + this . concurrencyLimit + " - blocking" ) ; } try { this . monitor . wait ( ) ; } catch ( InterruptedException ex ) { // Re - interrupt current thread , to allow other threads to react .
Thread . currentThread ( ) . interrupt ( ) ; interrupted = true ; } } if ( debug ) { logger . debug ( "Entering throttle at concurrency count " + this . concurrencyCount ) ; } this . concurrencyCount ++ ; } }


signature:
public class ConcurrencyThrottleSupport { /** * To be invoked after the main execution logic of concrete subclasses .
 * @ see # beforeAccess ( ) */
protected void afterAccess ( ) { } }

implementation: if ( this . concurrencyLimit >= 0 ) { synchronized ( this . monitor ) { this . concurrencyCount -- ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Returning from throttle at concurrency count " + this . concurrencyCount ) ; } this . monitor . notify ( ) ; } }


signature: public class ConcurrencyThrottleSupport { private void readObject ( ObjectInputStream ois ) throws IOException , ClassNotFoundException { } }

implementation:
// Rely on default serialization , just initialize state after deserialization .
ois . defaultReadObject ( ) ; // Initialize transient fields .
this . logger = LogFactory . getLog ( getClass ( ) ) ; this . monitor = new Object ( ) ;


signature:
public class ThreadPool { /** * 带回调函数的代理线程 , 本方法将创建新线程在线程池内运行 < br >
 * < b > 注意 : 回调函数一定要是带三个参数的方法 : < br >
 * 第一个参数来接收代理函数执行方法的返回值 , < br >
 * 第二个参数用来接收代理函数执行过程中抛出的异常 , < br >
 * 第三个参数用来回调调用时传给代理线程的参数列表 < / b > < br >
 * < br >
 * < br >
 * 回调方法的获取方法 < br >
 * < pre >
 * Class . getDeclaredMethod ( & quot ; callBack & quot ; , Object . class , Throwable . class , Object [ ] . class ) ;
 * < / pre >
 * 2013-9-16 下午9:30:29
 * @ param callBackInstance 接收代理线程执行完成之后调用方法所在对象 , 如果为静态方法则该参数可为null
 * @ param callBackMethod 代理线程执行完后的回调函数 , 必须是method ( Object , Throwable , Object . . . ) 形式的函数
 * @ param instance 调用实例 , 如果为静态方法则该参数可为null
 * @ param method 调用方法
 * @ param parameters 参数列表 */
public static void invoke ( Object callBackInstance , Method callBackMethod , Object instance , Method method , Object ... parameters ) { } }

implementation: if ( method != null ) { ProxyThread proxyThread = new ProxyThread ( callBackInstance , callBackMethod , instance , method , parameters ) ; pool . execute ( proxyThread ) ; } else { EntityHelper . print ( "空对象" ) ; StackTraceHelper . printStackTrace ( ) ; }


signature:
public class ThreadPool { /** * 代理线程 , 本方法将创建新线程在线程池内运行 < br >
 * 2013-9-16 下午9:38:12
 * @ param instance 调用实例 , 如果为静态方法则该参数可为null
 * @ param method 调用方法
 * @ param parameters 参数列表 , 必须是Method对应的 */
public static void invoke ( Object instance , Method method , Object ... parameters ) { } }

implementation: invoke ( null , null , instance , method , parameters ) ;


signature:
public class JsonHelper { /** * 获取json字符串
 * @ param object
 * @ return */
public static String getJsonString ( Object object ) { } }

implementation: ObjectMapper objectMapper = new ObjectMapper ( ) ; String json = null ; try { json = objectMapper . writeValueAsString ( object ) ; } catch ( JsonProcessingException e ) { e . printStackTrace ( ) ; } return json ;


signature:
public class JsonHelper { /** * 获取格式化的json数组
 * @ param object
 * @ return */
public static String getPrettyJsonString ( Object object ) { } }

implementation: ObjectMapper objectMapper = new ObjectMapper ( ) ; String json = null ; try { json = objectMapper . writerWithDefaultPrettyPrinter ( ) . writeValueAsString ( object ) ; } catch ( JsonProcessingException e ) { e . printStackTrace ( ) ; } return json ;


signature:
public class CalendarBuilder { /** * 增加指定字段的数量
 * @ param field 字段 { @ link java . util . Calendar # set ( int , int ) }
 * @ param plus
 * @ return */
public CalendarBuilder next ( int field , int plus ) { } }

implementation: calculateCalendar . set ( field , calculateCalendar . get ( field ) + plus ) ; return this ;


signature:
public class FileSystemUtils { /** * Delete the supplied { @ link java . io . File } - for directories ,
 * recursively delete any nested directories or files as well .
 * @ param root the root { @ code File } to delete
 * @ return { @ code true } if the { @ code File } was deleted ,
 * otherwise { @ code false } */
public static boolean deleteRecursively ( File root ) { } }

implementation: if ( root != null && root . exists ( ) ) { if ( root . isDirectory ( ) ) { File [ ] children = root . listFiles ( ) ; if ( children != null ) { for ( File child : children ) { deleteRecursively ( child ) ; } } } return root . delete ( ) ; } return false ;


signature:
public class FileSystemUtils { /** * Recursively copy the contents of the { @ code src } file / directory
 * to the { @ code dest } file / directory .
 * @ param src the source directory
 * @ param dest the destination directory
 * @ throws java . io . IOException in the case of I / O errors */
public static void copyRecursively ( File src , File dest ) throws IOException { } }

implementation: Assert . isTrue ( src != null && ( src . isDirectory ( ) || src . isFile ( ) ) , "Source File must denote a directory or file" ) ; Assert . notNull ( dest , "Destination File must not be null" ) ; doCopyRecursively ( src , dest ) ;


signature:
public class FileSystemUtils { /** * Actually copy the contents of the { @ code src } file / directory
 * to the { @ code dest } file / directory .
 * @ param src the source directory
 * @ param dest the destination directory
 * @ throws java . io . IOException in the case of I / O errors */
private static void doCopyRecursively ( File src , File dest ) throws IOException { } }

implementation:
if ( src . isDirectory ( ) ) { dest . mkdir ( ) ; File [ ] entries = src . listFiles ( ) ; if ( entries == null ) { throw new IOException ( "Could not list files in directory: " + src ) ; } for ( File entry : entries ) { doCopyRecursively ( entry , new File ( dest , entry . getName ( ) ) ) ; } } else if ( src . isFile ( ) ) { try { dest . createNewFile ( ) ; } catch ( IOException ex ) { IOException ioex = new IOException ( "Failed to create file: " + dest ) ; ioex . initCause ( ex ) ; throw ioex ; } FileCopyUtils . copy ( src , dest ) ; } else { // Special File handle : neither a file not a directory .
// Simply skip it when contained in nested directory . . .
}


signature:
public class JavassistFilterPropertyHandler { /** * < br >
 * 2013-10-28 上午11:11:24
 * @ param collection
 * @ param names
 * @ return */
private Collection < String > checkAndPutToCollection ( Collection < String > collection , String [ ] names ) { } }

implementation: if ( collection == null ) { collection = new HashSet < String > ( ) ; } Collections . addAll ( collection , names ) ; return collection ;


signature:
public class JavassistFilterPropertyHandler { /** * 处理IgnoreProperties注解 < br >
 * 2013-10-30 下午6:15:41
 * @ param properties
 * @ param pojoAndNamesMap */
private void processIgnorePropertiesAnnotation ( IgnoreProperties properties , Map < Class < ? > , Collection < String > > pojoAndNamesMap ) { } }

implementation: IgnoreProperty [ ] values = properties . value ( ) ; AllowProperty [ ] allowProperties = properties . allow ( ) ; if ( allowProperties != null ) { for ( AllowProperty allowProperty : allowProperties ) { processAllowPropertyAnnotation ( allowProperty , pojoAndNamesMap ) ; } } if ( values != null ) { for ( IgnoreProperty property : values ) { processIgnorePropertyAnnotation ( property , pojoAndNamesMap ) ; } }


signature:
public class JavassistFilterPropertyHandler { /** * 处理IgnoreProperty注解 < br >
 * 2013-10-30 下午6:16:08
 * @ param property
 * @ param pojoAndNamesMap */
private void processIgnorePropertyAnnotation ( IgnoreProperty property , Map < Class < ? > , Collection < String > > pojoAndNamesMap ) { } }

implementation:
String [ ] names = property . name ( ) ; Class < ? > pojoClass = property . pojo ( ) ; // Class < ? > proxyAnnotationInterface = createMixInAnnotation ( names ) ; / /
// 根据注解创建代理接口
Collection < String > nameCollection = pojoAndNamesMap . get ( pojoClass ) ; nameCollection = checkAndPutToCollection ( nameCollection , names ) ; pojoAndNamesMap . put ( pojoClass , nameCollection ) ;


signature:
public class JavassistFilterPropertyHandler { /** * 处理AllowProperty注解 < br >
 * 2013-10-30 下午6:16:08
 * @ param property
 * @ param pojoAndNamesMap */
private void processAllowPropertyAnnotation ( AllowProperty property , Map < Class < ? > , Collection < String > > pojoAndNamesMap ) { } }

implementation: String [ ] allowNames = property . name ( ) ; Class < ? > pojoClass = property . pojo ( ) ; Collection < String > ignoreProperties = EntityHelper . getUnstaticClassFieldNameCollection ( pojoClass ) ; Collection < String > allowNameCollection = new ArrayList < String > ( ) ; Collections . addAll ( allowNameCollection , allowNames ) ; Collection < String > nameCollection = pojoAndNamesMap . get ( pojoClass ) ; if ( nameCollection != null ) { nameCollection . removeAll ( allowNameCollection ) ; } else { ignoreProperties . removeAll ( allowNameCollection ) ; nameCollection = ignoreProperties ; } pojoAndNamesMap . put ( pojoClass , nameCollection ) ;


signature:
public class JavassistFilterPropertyHandler { /** * 根据方法获取过滤映射表 < br >
 * 2013-10-25 下午2:47:34
 * @ param method 注解了 @ IgnoreProperties 或 @ IgnoreProperty 的方法 ( 所在的类 )
 * @ return Map pojo与其属性的映射表 */
public Map < Class < ? > , Class < ? > > getProxyMixInAnnotation ( Method method ) { } }

implementation:
// if ( isResponseBodyAnnotation & & ! method . isAnnotationPresent ( ResponseBody . class ) ) {
// return null ;
Map < Class < ? > , Class < ? > > map = proxyMethodMap . get ( method ) ; // 从缓存中查找是否存在
if ( map != null && map . entrySet ( ) . size ( ) > 0 ) { // 如果已经读取该方法的注解信息 , 则从缓存中读取
return map ; } else { map = new HashMap < Class < ? > , Class < ? > > ( ) ; } Class < ? > clazzOfMethodIn = method . getDeclaringClass ( ) ; // 方法所在的class
Map < Class < ? > , Collection < String > > pojoAndNamesMap = new HashMap < Class < ? > , Collection < String > > ( ) ; IgnoreProperties classIgnoreProperties = clazzOfMethodIn . getAnnotation ( IgnoreProperties . class ) ; IgnoreProperty classIgnoreProperty = clazzOfMethodIn . getAnnotation ( IgnoreProperty . class ) ; AllowProperty classAllowProperty = clazzOfMethodIn . getAnnotation ( AllowProperty . class ) ; IgnoreProperties ignoreProperties = method . getAnnotation ( IgnoreProperties . class ) ; IgnoreProperty ignoreProperty = method . getAnnotation ( IgnoreProperty . class ) ; AllowProperty allowProperty = method . getAnnotation ( AllowProperty . class ) ; if ( allowProperty != null ) { // 方法上的AllowProperty注解
processAllowPropertyAnnotation ( allowProperty , pojoAndNamesMap ) ; } if ( classAllowProperty != null ) { processAllowPropertyAnnotation ( classAllowProperty , pojoAndNamesMap ) ; } if ( classIgnoreProperties != null ) { // 类上的IgnoreProperties注解
processIgnorePropertiesAnnotation ( classIgnoreProperties , pojoAndNamesMap ) ; } if ( classIgnoreProperty != null ) { // 类上的IgnoreProperty注解
processIgnorePropertyAnnotation ( classIgnoreProperty , pojoAndNamesMap ) ; } if ( ignoreProperties != null ) { // 方法上的IgnoreProperties注解
processIgnorePropertiesAnnotation ( ignoreProperties , pojoAndNamesMap ) ; } if ( ignoreProperty != null ) { // 方法上的IgnoreProperties注解
processIgnorePropertyAnnotation ( ignoreProperty , pojoAndNamesMap ) ; } Set < Entry < Class < ? > , Collection < String > > > entries = pojoAndNamesMap . entrySet ( ) ; for ( Iterator < Entry < Class < ? > , Collection < String > > > iterator = entries . iterator ( ) ; iterator . hasNext ( ) ; ) { Entry < Class < ? > , Collection < String > > entry = ( Entry < Class < ? > , Collection < String > > ) iterator . next ( ) ; Collection < String > nameCollection = entry . getValue ( ) ; nameCollection = putGlobalIgnoreProperties ( nameCollection ) ; // 将全局过滤字段放入集合内
String [ ] names = nameCollection . toArray ( new String [ ] { } ) ; // EntityHelper . print ( entry . getKey ( ) ) ;
// for ( int i = 0 ; i < names . length ; i + + ) {
// String name = names [ i ] ;
// EntityHelper . print ( name ) ;
Class < ? > clazz = createMixInAnnotation ( names ) ; map . put ( entry . getKey ( ) , clazz ) ; } proxyMethodMap . put ( method , map ) ; return map ;