signature:
public class JmxAttributePoller { /** * Poll all of the objects , one at a time .
 * @ return false = > if polling completed normally ; true = > if polling stopped due to shutdown .
 * @ throws IOException */
protected boolean pollIndividually ( ) throws IOException { } }

implementation:
this . concurrencyTestHooks . onStartPollIndividually ( ) ; List < SchedulerProcessExecutionSlip > processExecutionSlipList = new LinkedList < > ( ) ; for ( final Object onePolledObject : this . polledObjects ) { // Stop as soon as possible if shutting down .
if ( shutdownInd ) { return true ; } SchedulerProcess process = new PollOneObjectSchedulerProcess ( onePolledObject ) ; SchedulerProcessExecutionSlip executionSlip = this . scheduler . startProcess ( process ) ; processExecutionSlipList . add ( executionSlip ) ; } for ( SchedulerProcessExecutionSlip oneExecutionSlip : processExecutionSlipList ) { try { // Wait for this process to complete
oneExecutionSlip . waitUntilComplete ( ) ; // Check for a failure
PollOneObjectSchedulerProcess process = ( PollOneObjectSchedulerProcess ) oneExecutionSlip . getSchedulerProcess ( ) ; Exception exc = process . getFailureException ( ) ; if ( exc != null ) { log . warn ( "failed to poll object" , exc ) ; // Propagate IOExceptions since they most likely mean that the connection needs to be recovered .
if ( exc instanceof IOException ) { throw ( IOException ) exc ; } } } catch ( InterruptedException intExc ) { log . info ( "interrupted while polling object" ) ; } } return false ;


signature:
public class ClassUtil { /** * Create new instance of specified class and type
 * @ param clazz class
 * @ param accessible accessible
 * @ param parameterTypes parameter types
 * @ param paramValue param value
 * @ param < T > t
 * @ return instance */
public static < T > T getInstance ( Class < T > clazz , boolean accessible , Class < ? > [ ] parameterTypes , Object [ ] paramValue ) { } }

implementation: if ( clazz == null ) return null ; T t = null ; try { if ( parameterTypes != null && paramValue != null ) { Constructor < T > constructor = clazz . getDeclaredConstructor ( parameterTypes ) ; Object [ ] obj = new Object [ parameterTypes . length ] ; System . arraycopy ( paramValue , 0 , obj , 0 , parameterTypes . length ) ; constructor . setAccessible ( accessible ) ; t = constructor . newInstance ( obj ) ; } } catch ( SecurityException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } catch ( NoSuchMethodException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } catch ( IllegalArgumentException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } catch ( InstantiationException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } catch ( IllegalAccessException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } catch ( InvocationTargetException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } return t ;


signature:
public class ClassUtil { /** * Create new instance of specified class and type
 * @ param clazz class
 * @ param accessible accessible
 * @ param < T > t
 * @ return instance */
public static < T > T getInstance ( Class < T > clazz , boolean accessible ) { } }

implementation: if ( clazz == null ) return null ; T t = null ; try { Constructor < T > constructor = clazz . getDeclaredConstructor ( ) ; constructor . setAccessible ( accessible ) ; t = constructor . newInstance ( ) ; } catch ( InstantiationException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } catch ( IllegalAccessException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } catch ( SecurityException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } catch ( NoSuchMethodException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } catch ( IllegalArgumentException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } catch ( InvocationTargetException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } return t ;


signature:
public class ClassUtil { /** * obtain field If recursively is true , obtain fields from all class
 * hierarchy
 * @ param clazz class
 * where fields are searching
 * @ param fieldName
 * field name
 * @ param recursively
 * param
 * @ return list of fields */
public static Field getDeclaredField ( Class < ? > clazz , String fieldName , boolean recursively ) { } }

implementation: try { return clazz . getDeclaredField ( fieldName ) ; } catch ( NoSuchFieldException e ) { Class < ? > superClass = clazz . getSuperclass ( ) ; if ( superClass != null && recursively ) { return getDeclaredField ( superClass , fieldName , true ) ; } } catch ( SecurityException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } return null ;


signature:
public class ClassUtil { /** * obtain methods list of specified class If recursively is true , obtain
 * methods from all class hierarchy
 * @ param clazz class
 * where fields are searching
 * @ param recursively
 * param
 * @ return array of methods */
public static Method [ ] getDeclaredMethods ( Class < ? > clazz , boolean recursively ) { } }

implementation: List < Method > methods = new LinkedList < Method > ( ) ; Method [ ] declaredMethods = clazz . getDeclaredMethods ( ) ; Collections . addAll ( methods , declaredMethods ) ; Class < ? > superClass = clazz . getSuperclass ( ) ; if ( superClass != null && recursively ) { Method [ ] declaredMethodsOfSuper = getDeclaredMethods ( superClass , true ) ; if ( declaredMethodsOfSuper . length > 0 ) Collections . addAll ( methods , declaredMethodsOfSuper ) ; } return methods . toArray ( new Method [ methods . size ( ) ] ) ;


signature:
public class ClassUtil { /** * obtain method list of specified class If recursively is true , obtain
 * method from all class hierarchy
 * @ param clazz class
 * @ param recursively recursively
 * @ param methodName method name
 * @ param parameterTypes parameter types
 * @ return method */
public static Method getDeclaredMethod ( Class < ? > clazz , boolean recursively , String methodName , Class < ? > ... parameterTypes ) { } }

implementation: try { return clazz . getDeclaredMethod ( methodName , parameterTypes ) ; } catch ( NoSuchMethodException e ) { Class < ? > superClass = clazz . getSuperclass ( ) ; if ( superClass != null && recursively ) { return getDeclaredMethod ( superClass , true , methodName , parameterTypes ) ; } } catch ( SecurityException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } return null ;


signature:
public class ClassUtil { /** * obtain constructor list of specified class If recursively is true , obtain
 * constructor from all class hierarchy
 * @ param clazz class
 * where fields are searching
 * @ param recursively
 * param
 * @ return array of constructors */
public static Constructor < ? > [ ] getDeclaredConstructors ( Class < ? > clazz , boolean recursively ) { } }

implementation: List < Constructor < ? > > constructors = new LinkedList < Constructor < ? > > ( ) ; Constructor < ? > [ ] declaredConstructors = clazz . getDeclaredConstructors ( ) ; Collections . addAll ( constructors , declaredConstructors ) ; Class < ? > superClass = clazz . getSuperclass ( ) ; if ( superClass != null && recursively ) { Constructor < ? > [ ] declaredConstructorsOfSuper = getDeclaredConstructors ( superClass , true ) ; if ( declaredConstructorsOfSuper . length > 0 ) Collections . addAll ( constructors , declaredConstructorsOfSuper ) ; } return constructors . toArray ( new Constructor < ? > [ constructors . size ( ) ] ) ;


signature:
public class ClassUtil { /** * obtain constructor list of specified class If recursively is true , obtain
 * constructor from all class hierarchy
 * @ param clazz class
 * where fields are searching
 * @ param recursively
 * param
 * @ param parameterTypes parameter types
 * @ return constructor */
public static Constructor < ? > getDeclaredConstructor ( Class < ? > clazz , boolean recursively , Class < ? > ... parameterTypes ) { } }

implementation: try { return clazz . getDeclaredConstructor ( parameterTypes ) ; } catch ( NoSuchMethodException e ) { Class < ? > superClass = clazz . getSuperclass ( ) ; if ( superClass != null && recursively ) { return getDeclaredConstructor ( superClass , true , parameterTypes ) ; } } catch ( SecurityException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } return null ;


signature:
public class ClassUtil { /** * obtain methods list of specified class and which are annotated by
 * incoming annotation class If recursively is true , obtain methods from all
 * class hierarchy
 * @ param clazz class
 * - where methods are searching
 * @ param annotationClass
 * - specified annotation class
 * @ param recursively
 * param
 * @ return list of annotated methods */
public static Method [ ] getAnnotatedDeclaredMethods ( Class < ? > clazz , Class < ? extends Annotation > annotationClass , boolean recursively ) { } }

implementation: Method [ ] allMethods = getDeclaredMethods ( clazz , recursively ) ; List < Method > annotatedMethods = new LinkedList < Method > ( ) ; for ( Method method : allMethods ) { if ( method . isAnnotationPresent ( annotationClass ) ) annotatedMethods . add ( method ) ; } return annotatedMethods . toArray ( new Method [ annotatedMethods . size ( ) ] ) ;


signature:
public class ClassUtil { /** * obtain constructors list of specified class and which are annotated by
 * incoming annotation class If recursively is true , obtain constructors
 * from all class hierarchy
 * @ param clazz class
 * - where constructors are searching
 * @ param annotationClass
 * - specified annotation class
 * @ param recursively
 * param
 * @ return list of annotated constructors */
public static Constructor < ? > [ ] getAnnotatedDeclaredConstructors ( Class < ? > clazz , Class < ? extends Annotation > annotationClass , boolean recursively ) { } }

implementation: Constructor < ? > [ ] allConstructors = getDeclaredConstructors ( clazz , recursively ) ; List < Constructor < ? > > annotatedConstructors = new LinkedList < Constructor < ? > > ( ) ; for ( Constructor < ? > field : allConstructors ) { if ( field . isAnnotationPresent ( annotationClass ) ) annotatedConstructors . add ( field ) ; } return annotatedConstructors . toArray ( new Constructor < ? > [ annotatedConstructors . size ( ) ] ) ;


signature:
public class JdbcNestedTransaction { /** * 回滚一个事务 */
@ Override public void rollback ( ) { } }

implementation: try { if ( conn . isClosed ( ) ) { throw new TransactionException ( "the connection is closed in transaction." ) ; } conn . rollback ( savepoint ) ; } catch ( SQLException e ) { throw new TransactionException ( e ) ; }


signature:
public class JdbcTransaction { /** * 回滚一个事务 */
@ Override public void rollback ( ) { } }

implementation: try { if ( conn . isClosed ( ) ) { throw new TransactionException ( "the connection is closed in transaction." ) ; } conn . rollback ( ) ; conn . setAutoCommit ( true ) ; } catch ( SQLException e ) { throw new TransactionException ( e ) ; }


signature:
public class JdbcTransaction { /** * 结束一个事务 */
@ Override public void close ( ) { } }

implementation: try { if ( conn . isClosed ( ) ) { throw new TransactionException ( "the connection is closed in transaction." ) ; } DbUtils . closeQuietly ( conn ) ; } catch ( SQLException e ) { throw new TransactionException ( e ) ; } finally { transationHandler . set ( null ) ; }


signature:
public class JdbcLogPreparedStatement { /** * Creates a logging version of a PreparedStatement
 * @ param stmt
 * - the statement
 * @ param sql
 * - the sql statement
 * @ return - the proxy */
public static PreparedStatement getInstance ( PreparedStatement stmt , String sql ) { } }

implementation: InvocationHandler handler = new JdbcLogPreparedStatement ( stmt , sql ) ; ClassLoader cl = PreparedStatement . class . getClassLoader ( ) ; return ( PreparedStatement ) Proxy . newProxyInstance ( cl , new Class [ ] { PreparedStatement . class } , handler ) ;


signature:
public class ResultHandlerResolver { /** * 是否支持该 resultClass */
public boolean validate ( Class < ? > resultClass ) { } }

implementation:
// 查找 : 已经注册的类
if ( mapping . containsKey ( resultClass ) ) { return true ; } // 查找 : 用 annotation 标注 , 但是没有注册的 ResultHandler
ManagedWith with = resultClass . getAnnotation ( ManagedWith . class ) ; if ( with != null && ResultHandler . class . isAssignableFrom ( with . value ( ) ) ) { register ( resultClass , with . value ( ) ) ; // 发现后注册
return true ; } // 查找 : 使用了已经注册的类的子类
for ( Map . Entry < Class < ? > , ResultHandler < ? > > entry : mapping . entrySet ( ) ) { Class < ? > targetClass = entry . getKey ( ) ; if ( targetClass != Object . class && targetClass . isAssignableFrom ( resultClass ) ) { mapping . put ( resultClass , entry . getValue ( ) ) ; // 发现后关联
return true ; } } return false ;


signature:
public class ZipSourcePropertyView { /** * Add your property controls to this panel .
 * Remember to set your own layout manager .
 * Also , remember to create a new JPanel , and pass it to the super class
 * so controls of the superclass can be included .
 * You have a 3 x 3 grid , so add three columns for each control
 * @ param panel This is the panel to add your controls to . */
public void addControlsToView ( JPanel panel ) { } }

implementation: panel . setLayout ( new BorderLayout ( ) ) ; JPanel panelMain = this . makeNewPanel ( panel , BorderLayout . CENTER ) ; panelMain . setLayout ( new GridLayout ( 1 , 2 ) ) ; panelMain . add ( new JLabel ( "Zip filename: " , JLabel . RIGHT ) ) ; panelMain . add ( m_tfRootPathname = new JTextField ( ) ) ; JPanel panelSub = this . makeNewPanel ( panel , BorderLayout . SOUTH ) ; super . addControlsToView ( panelSub ) ;


signature:
public class ZipSourcePropertyView { /** * Set the properties to the current control values . */
public void controlsToProperties ( ) { } }

implementation: super . controlsToProperties ( ) ; String strPathname = m_tfRootPathname . getText ( ) ; m_properties . setProperty ( ZIPIN_FILENAME_PARAM , strPathname ) ;


signature:
public class ZipSourcePropertyView { /** * Set the properties to the current control values . */
public void propertiesToControls ( ) { } }

implementation: super . propertiesToControls ( ) ; String strPathname = m_properties . getProperty ( ZIPIN_FILENAME_PARAM ) ; m_tfRootPathname . setText ( strPathname ) ;


signature:
public class DbUtils { /** * 从一个标准的select语句中 , 生成一个 select count ( * ) 语句 */
public static String get_sql_select_count ( String sql ) { } }

implementation: String count_sql = sql . replaceAll ( "\\s+" , " " ) ; int pos = count_sql . toLowerCase ( ) . indexOf ( " from " ) ; count_sql = count_sql . substring ( pos ) ; pos = count_sql . toLowerCase ( ) . lastIndexOf ( " order by " ) ; int lastpos = count_sql . toLowerCase ( ) . lastIndexOf ( ")" ) ; if ( pos != - 1 && pos > lastpos ) { count_sql = count_sql . substring ( 0 , pos ) ; } String regex = "(left|right|inner) join (fetch )?\\w+(\\.\\w+)*" ; Pattern p = Pattern . compile ( regex , Pattern . CASE_INSENSITIVE ) ; count_sql = p . matcher ( count_sql ) . replaceAll ( "" ) ; count_sql = "select count(*) " + count_sql ; return count_sql ;


signature:
public class PictureFilter { /** * Accept this file ?
 * @ param dir The directory this file is in .
 * @ param filename The filename . */
public boolean accept ( File dir , String filename ) { } }

implementation:
String strPath = dir . getPath ( ) ; // if ( ( strPath . indexOf ( " mediumpics " ) ! = - 1)
// | | ( strPath . indexOf ( " smallpics " ) ! = - 1)
// | | ( strPath . indexOf ( " thumbpics " ) ! = - 1 ) )
// return false ;
// if ( strPath . indexOf ( " \ \ trips \ \ " ) ! = - 1)
if ( ( strPath . indexOf ( "\\html\\pics\\pictures\\" ) != - 1 ) && ( filename . indexOf ( ".html" ) != - 1 ) && ( strPath . indexOf ( "\\html\\pics\\pictures\\donandannie\\trips" ) == - 1 ) ) return false ; // Don ' t replicate the html files , except the trip
if ( ( strPath . indexOf ( "\\html\\pics\\smallpics\\pictures" ) != - 1 ) && ( filename . indexOf ( ".html" ) != - 1 ) && ( strPath . indexOf ( "\\html\\pics\\smallpics\\pictures\\donandannie\\trips" ) == - 1 ) ) return false ; // Don ' t replicate the html files , except the trip
return true ;


signature:
public class ZipSource { /** * Get ready to start processing . */
public void init ( Properties properties ) { } }

implementation: super . init ( properties ) ; String strPathname = properties . getProperty ( ZIPIN_FILENAME_PARAM ) ; if ( ( strPathname == null ) || ( strPathname . length ( ) == 0 ) ) { strPathname = "in.zip" ; properties . setProperty ( ZIPIN_FILENAME_PARAM , strPathname ) ; }


signature:
public class ZipSource { /** * Set up everything to start processing */
public void initTransfer ( Properties properties ) { } }

implementation: super . initTransfer ( properties ) ; m_strZipFilename = properties . getProperty ( ZIPIN_FILENAME_PARAM ) ; try { FileInputStream inStream = new FileInputStream ( m_strZipFilename ) ; m_inZip = new ZipInputStream ( inStream ) ; } catch ( IOException ex ) { ex . printStackTrace ( ) ; }


signature:
public class ZipSource { /** * Close everything down after processing . */
public void finishTransfer ( Properties properties ) { } }

implementation: try { m_inZip . close ( ) ; } catch ( FileNotFoundException ex ) { ex . printStackTrace ( ) ; } catch ( IOException ex ) { ex . printStackTrace ( ) ; } super . finishTransfer ( properties ) ;


signature:
public class ZipSource { /** * Returns the next element in the interation .
 * ( Returns a SourceFileObject ) .
 * @ returns the next element in the interation .
 * @ exception NoSuchElementException iteration has no more elements . */
public SourceFile next ( ) { } }

implementation:
if ( this . isPend ( ) ) return this . getPend ( ) ; try { ZipEntry entry = m_inZip . getNextEntry ( ) ; if ( entry == null ) return null ; // EOF
String strPath = entry . getName ( ) ; String strFilename = strPath ; if ( strPath . lastIndexOf ( gchSeparator ) != - 1 ) if ( strPath . lastIndexOf ( gchSeparator ) + 1 < strPath . length ( ) ) strFilename = strPath . substring ( strPath . lastIndexOf ( gchSeparator ) + 1 ) ; long lStreamLength = entry . getSize ( ) ; if ( DEBUG ) System . out . println ( "Name: " + entry . getName ( ) + " size: " + entry . getSize ( ) ) ; return new StreamSourceFile ( null , m_inZip , strPath , strFilename , lStreamLength ) ; // Return the file
} catch ( IOException ex ) { ex . printStackTrace ( ) ; } return null ; // pend ( don ) Don ' t do this !


signature:
public class ReplicatorXmlHttps { /** * < p > It will clear current database then copy
 * data from another with XML messages trough HTTPS connection . < / p >
 * @ param pAddParams additional params
 * @ throws Exception - an exception */
@ Override public final void replicate ( final Map < String , Object > pAddParams ) throws Exception { } }

implementation:
Writer htmlWriter = ( Writer ) pAddParams . get ( "htmlWriter" ) ; try { // URL must be
String urlSourceStr = "https://" + ( String ) pAddParams . get ( "urlSource" ) ; if ( urlSourceStr == null || urlSourceStr . length ( ) < 10 ) { throw new ExceptionWithCode ( ExceptionWithCode . WRONG_PARAMETER , "Where is no urlSource!!!" ) ; } URL url = new URL ( urlSourceStr ) ; String authMethod = ( String ) pAddParams . get ( "authMethod" ) ; if ( "base" . equals ( authMethod ) ) { final String userName = ( String ) pAddParams . get ( "userName" ) ; final String userPass = ( String ) pAddParams . get ( "userPass" ) ; Authenticator . setDefault ( new Authenticator ( ) { @ Override protected PasswordAuthentication getPasswordAuthentication ( ) { return new PasswordAuthentication ( userName , userPass . toCharArray ( ) ) ; } } ) ; } else if ( "form" . equals ( authMethod ) ) { CookieManager cookieManager = new CookieManager ( ) ; CookieHandler . setDefault ( cookieManager ) ; cookieManager . setCookiePolicy ( CookiePolicy . ACCEPT_ALL ) ; requestCookiesGet ( pAddParams ) ; authForm ( pAddParams , cookieManager ) ; } Map < String , Integer > classesCounts = makeJob ( url , pAddParams ) ; if ( htmlWriter != null ) { String statusString = ", replication has been done." ; htmlWriter . write ( "
" + new Date ( ) . toString ( ) + statusString + "
" ) ; pAddParams . put ( "statusString" , new Date ( ) . toString ( ) + ", " + ReplicatorXmlHttp . class . getSimpleName ( ) + statusString ) ; this . logger . info ( null , ReplicatorXmlHttp . class , statusString ) ; htmlWriter . write ( "
" ) ; htmlWriter . write ( "
Class	Total records
" ) ; for ( Map . Entry < String , Integer > entry : classesCounts . entrySet ( ) ) { htmlWriter . write ( "
" ) ; htmlWriter . write ( "" + entry . getKey ( ) + "	" ) ; htmlWriter . write ( "" + entry . getValue ( ) + "	" ) ; htmlWriter . write ( "
" ) ; } htmlWriter . write ( "
" ) ; } } catch ( ExceptionWithCode ex ) { if ( htmlWriter != null ) { htmlWriter . write ( new Date ( ) . toString ( ) + ", " + ReplicatorXmlHttp . class . getSimpleName ( ) + ", " + ex . getShortMessage ( ) ) ; } this . logger . error ( null , ReplicatorXmlHttp . class , ex . getShortMessage ( ) ) ; throw ex ; }


signature:
public class ReplicatorXmlHttps { /** * < p > It copy data from another with XML messages
 * through given HTTP connection . < / p >
 * @ param pUrl URL
 * @ param pAddParams additional params
 * @ return Map < String , Integer > affected Class - records count
 * @ throws Exception - an exception */
public final Map < String , Integer > makeJob ( final URL pUrl , final Map < String , Object > pAddParams ) throws Exception { } }

implementation:
String requestedDatabaseId = ( String ) pAddParams . get ( "requestedDatabaseId" ) ; String maxRecordsStr = ( String ) pAddParams . get ( "maxRecords" ) ; if ( maxRecordsStr == null || maxRecordsStr . length ( ) == 0 ) { throw new ExceptionWithCode ( ExceptionWithCode . WRONG_PARAMETER , "Where is no maxRecords!!!" ) ; } int maxRecords = Integer . parseInt ( maxRecordsStr ) ; Map < String , Integer > classesCounts = new LinkedHashMap < String , Integer > ( ) ; Integer classCount = 0 ; boolean isDbPreparedBefore = false ; int databaseVersion = this . srvDatabase . getVersionDatabase ( ) ; for ( Class < ? > entityClass : this . mngSettings . getClasses ( ) ) { int entitiesReceived = 0 ; int firstRecord = 0 ; do { // HttpsURLConnection is single request connection
HttpsURLConnection urlConnection = ( HttpsURLConnection ) pUrl . openConnection ( ) ; if ( ! pUrl . getHost ( ) . equals ( urlConnection . getURL ( ) . getHost ( ) ) ) { throw new ExceptionWithCode ( ExceptionWithCode . SOMETHING_WRONG , "You should sign-in in browser first!" ) ; } OutputStreamWriter writer = null ; BufferedReader reader = null ; try { urlConnection . setDoOutput ( true ) ; urlConnection . setRequestMethod ( "POST" ) ; if ( getCookies ( ) != null ) { urlConnection . addRequestProperty ( "Cookie" , getCookies ( ) ) ; } writer = new OutputStreamWriter ( urlConnection . getOutputStream ( ) , Charset . forName ( "UTF-8" ) . newEncoder ( ) ) ; String nameFilterEntities = this . mngSettings . lazClsSts ( entityClass ) . get ( "filter" ) ; String conditions = "" ; if ( nameFilterEntities != null ) { IFilterEntities filterEntities = this . filtersEntities . get ( nameFilterEntities ) ; if ( filterEntities != null ) { String cond = filterEntities . makeFilter ( entityClass , pAddParams ) ; if ( cond != null ) { conditions = " where " + cond ; } } } conditions += " limit " + maxRecords + " offset " + firstRecord ; String requestedDatabaseIdStr = "" ; if ( requestedDatabaseId != null ) { if ( Integer . parseInt ( requestedDatabaseId ) == getSrvDatabase ( ) . getIdDatabase ( ) ) { throw new ExceptionWithCode ( ExceptionWithCode . WRONG_PARAMETER , "requested_database_must_be_different" ) ; } requestedDatabaseIdStr = "&requestedDatabaseId=" + requestedDatabaseId ; } writer . write ( "entityName=" + entityClass . getCanonicalName ( ) + "&conditions=" + conditions + "&requestingDatabaseVersion=" + databaseVersion + requestedDatabaseIdStr ) ; writer . write ( "&writerName=" + pAddParams . get ( "writerName" ) ) ; writer . flush ( ) ; if ( HttpsURLConnection . HTTP_OK == urlConnection . getResponseCode ( ) ) { reader = new BufferedReader ( new InputStreamReader ( urlConnection . getInputStream ( ) , Charset . forName ( "UTF-8" ) . newDecoder ( ) ) ) ; if ( ! this . utilXml . readUntilStart ( reader , "message" ) ) { throw new ExceptionWithCode ( ExceptionWithCode . SOMETHING_WRONG , "Wrong XML response without message tag!!!" ) ; } Map < String , String > msgAttrsMap = this . srvEntityReaderXml . readAttributes ( pAddParams , reader ) ; String error = msgAttrsMap . get ( "error" ) ; if ( error != null ) { throw new ExceptionWithCode ( ExceptionWithCode . SOMETHING_WRONG , error ) ; } String entitiesCountStr = msgAttrsMap . get ( "entitiesCount" ) ; if ( entitiesCountStr == null ) { throw new ExceptionWithCode ( ExceptionWithCode . SOMETHING_WRONG , "Wrong XML response without entitiesCount in message!!!" ) ; } entitiesReceived = Integer . parseInt ( entitiesCountStr ) ; if ( entitiesReceived > 0 ) { classCount += entitiesReceived ; this . logger . info ( null , ReplicatorXmlHttp . class , "Try to parse entities total: " + entitiesReceived + " of " + entityClass . getCanonicalName ( ) ) ; if ( ! isDbPreparedBefore ) { if ( this . databasePrepearerBefore != null ) { this . databasePrepearerBefore . make ( pAddParams ) ; } isDbPreparedBefore = true ; } this . databaseReader . readAndStoreEntities ( pAddParams , reader ) ; if ( entitiesReceived == maxRecords ) { firstRecord += maxRecords ; } else { firstRecord = 0 ; entitiesReceived = 0 ; } } else { firstRecord = 0 ; } } else { throw new ExceptionWithCode ( ExceptionWithCode . SOMETHING_WRONG , "Can't receive data!!! Response code=" + urlConnection . getResponseCode ( ) ) ; } } finally { if ( reader != null ) { try { reader . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } if ( writer != null ) { try { writer . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } urlConnection . disconnect ( ) ; } } while ( entitiesReceived > 0 ) ; classesCounts . put ( entityClass . getCanonicalName ( ) , classCount ) ; classCount = 0 ; } if ( this . databasePrepearerAfter != null ) { this . databasePrepearerAfter . make ( pAddParams ) ; } return classesCounts ;


signature:
public class ReplicatorXmlHttps { /** * < p > Connect to secure address with method GET to receive
 * authenticate cookies . < / p >
 * @ param pAddParams additional params
 * @ throws Exception - an exception */
public final void requestCookiesGet ( final Map < String , Object > pAddParams ) throws Exception { } }

implementation:
String urlGetAuthCookStr = ( String ) pAddParams . get ( "urlGetAuthCookies" ) ; URL urlGetAuthCookies = new URL ( urlGetAuthCookStr ) ; HttpsURLConnection urlConnection = null ; BufferedReader reader = null ; try { urlConnection = ( HttpsURLConnection ) urlGetAuthCookies . openConnection ( ) ; urlConnection . setRequestMethod ( "GET" ) ; urlConnection . addRequestProperty ( "Connection" , "keep-alive" ) ; if ( HttpsURLConnection . HTTP_OK == urlConnection . getResponseCode ( ) ) { reader = new BufferedReader ( new InputStreamReader ( urlConnection . getInputStream ( ) , Charset . forName ( "UTF-8" ) . newDecoder ( ) ) ) ; while ( reader . read ( ) != - 1 ) { // NOPMD
// just read out
} } else { throw new ExceptionWithCode ( ExceptionWithCode . SOMETHING_WRONG , "requestCookiesGet Can't receive data!!! Response code=" + urlConnection . getResponseCode ( ) ) ; } } finally { if ( reader != null ) { try { reader . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } if ( urlConnection != null ) { urlConnection . disconnect ( ) ; } }


signature:
public class ReplicatorXmlHttps { /** * < p > It authenticate by post simulate form . < / p >
 * @ param pAddParams additional params
 * @ param pCookieManager CookieManager for form auth
 * @ throws Exception - an exception */
public final void authForm ( final Map < String , Object > pAddParams , final CookieManager pCookieManager ) throws Exception { } }

implementation:
String authUrl = ( String ) pAddParams . get ( "authUrl" ) ; String authUserName = ( String ) pAddParams . get ( "authUserName" ) ; String authUserPass = ( String ) pAddParams . get ( "authUserPass" ) ; String userName = ( String ) pAddParams . get ( "userName" ) ; String userPass = ( String ) pAddParams . get ( "userPass" ) ; URL url = new URL ( authUrl ) ; HttpsURLConnection urlConnection = ( HttpsURLConnection ) url . openConnection ( ) ; if ( ! url . getHost ( ) . equals ( urlConnection . getURL ( ) . getHost ( ) ) ) { throw new ExceptionWithCode ( ExceptionWithCode . SOMETHING_WRONG , "You should sign-in in browser first!" ) ; } OutputStreamWriter writer = null ; BufferedReader reader = null ; try { urlConnection . setDoOutput ( true ) ; urlConnection . setRequestMethod ( "POST" ) ; String paramStr = authUserName + "=" + userName + "&" + authUserPass + "=" + userPass ; StringBuffer cookiesSb = new StringBuffer ( ) ; for ( HttpCookie cookie : pCookieManager . getCookieStore ( ) . getCookies ( ) ) { cookiesSb . append ( cookie . getName ( ) + "=" + cookie . getValue ( ) + ";" ) ; } setCookies ( cookiesSb . toString ( ) ) ; urlConnection . addRequestProperty ( "Cookie" , getCookies ( ) ) ; urlConnection . addRequestProperty ( "Connection" , "keep-alive" ) ; urlConnection . addRequestProperty ( "Content-Type" , "application/x-www-form-urlencoded" ) ; urlConnection . addRequestProperty ( "Content-Length" , String . valueOf ( paramStr . length ( ) ) ) ; boolean isDbgSh = this . logger . getDbgSh ( this . getClass ( ) ) && this . logger . getDbgFl ( ) < 8001 && this . logger . getDbgCl ( ) > 8003 ; if ( isDbgSh ) { getLogger ( ) . debug ( null , ReplicatorXmlHttp . class , "Request before flush auth:" ) ; for ( Map . Entry < String , List < String > > entry : urlConnection . getRequestProperties ( ) . entrySet ( ) ) { this . logger . debug ( null , ReplicatorXmlHttp . class , "  Request entry key: " + entry . getKey ( ) ) ; for ( String val : entry . getValue ( ) ) { this . logger . debug ( null , ReplicatorXmlHttp . class , "   Request entry value: " + val ) ; } } } writer = new OutputStreamWriter ( urlConnection . getOutputStream ( ) , Charset . forName ( "UTF-8" ) . newEncoder ( ) ) ; writer . write ( paramStr ) ; writer . flush ( ) ; reader = new BufferedReader ( new InputStreamReader ( urlConnection . getInputStream ( ) , Charset . forName ( "UTF-8" ) . newDecoder ( ) ) ) ; while ( reader . read ( ) != - 1 ) { // NOPMD
// just read out
} } finally { if ( reader != null ) { try { reader . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } if ( writer != null ) { try { writer . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } urlConnection . disconnect ( ) ; }


signature:
public class DebugOutputStream { /** * Dumps single byte to output stream . */
protected void dumpByte ( int b ) { } }

implementation: if ( passThrough == true ) { System . out . print ( '\t' ) ; } if ( b < 0 ) { b += 128 ; } if ( b < 0x10 ) { System . out . print ( '0' ) ; } System . out . print ( ' ' ) ; System . out . print ( Integer . toHexString ( b ) . toUpperCase ( ) ) ;


signature:
public class SubStyleType { /** * longvarbinary */
public static Class < ? > getJavaClass ( String typeName ) { } }

implementation: Class < ? > clazz = javaClassMapping . get ( typeName . toLowerCase ( ) ) ; return clazz == null ? Object . class : clazz ;


signature:
public class SampleMessageLogger { /** * Check is broken [ LOG . info ( ) ] : PMD reports issues although log stmt is guarded . @ todo revisit when upgrading PMD . */
@ SuppressWarnings ( "PMD.GuardLogStatementJavaUtil" ) @ Override public final void create ( final Events event , final String userId ) { } }

implementation:
Validate . notNull ( event , "The validated object 'event' is null" ) ; Validate . notBlank ( userId , "The validated character sequence 'userId' is null or empty" ) ; // PMD does not recognize the guarded log statement
if ( LOG . isInfoEnabled ( ) ) { LOG . info ( "[MESSAGEQ] " + event . getValue ( ) + ". User ID '" + userId ) ; }


signature:
public class AReplicationMethod { /** * < p > Setter for lastDateReplication . < / p >
 * @ param pLastDateReplication reference */
public final void setLastDateReplication ( final Date pLastDateReplication ) { } }

implementation: if ( pLastDateReplication == null ) { this . lastDateReplication = null ; } else { this . lastDateReplication = new Date ( pLastDateReplication . getTime ( ) ) ; }


signature:
public class AnnotationClassReader { /** * Inspect the given ( Java ) class file in streaming mode . */
private boolean readClassFile ( final ClassFileDataInput di ) throws IOException { } }

implementation: if ( ! readMagicCode ( di ) ) { return false ; } if ( ! readVersion ( di ) ) { return false ; } readConstantPoolEntries ( di ) ; if ( ! readAccessFlags ( di ) ) { return false ; } readThisClass ( di ) ; readSuperClass ( di ) ; readInterfaces ( di ) ; readFields ( di ) ; readMethods ( di ) ; return readAttributes ( di , ElementType . TYPE ) ;


signature:
public class AnnotationClassReader { /** * Look up the String value , identified by the u2 index value from constant pool
 * ( direct or indirect ) . */
private String resolveUtf8 ( final DataInput di ) throws IOException { } }

implementation: final int index = di . readUnsignedShort ( ) ; final Object value = constantPool [ index ] ; final String s ; if ( value instanceof Integer ) { s = ( String ) constantPool [ ( Integer ) value ] ; } else { s = ( String ) value ; } return s ;


signature:
public class StringUtils { /** * Removes control characters ( char & lt ; = 32 ) from both ends of this String
 * returning { @ code null } if the String is empty ( " " ) after the trim or if
 * it is { @ code null } .
 * The String is trimmed using { @ link String # trim ( ) } . Trim removes start and
 * end characters & lt ; = 32.
 * < pre >
 * StringUtils . trimToNull ( null ) = null
 * StringUtils . trimToNull ( " " ) = null
 * StringUtils . trimToNull ( " " ) = null
 * StringUtils . trimToNull ( " abc " ) = " abc "
 * StringUtils . trimToNull ( " abc " ) = " abc "
 * < / pre > */
public static String trimToNull ( final String s ) { } }

implementation: final String ts = trim ( s ) ; return ts == null || ts . length ( ) == 0 ? null : ts ;


signature:
public class StringUtils { /** * Returns either the passed in String , or if the String is { @ code null } ,
 * the value of { @ code defaultStr } .
 * < pre >
 * StringUtils . defaultIfNull ( null , " NULL " ) = " NULL "
 * StringUtils . defaultIfNull ( " " , " NULL " ) = " "
 * StringUtils . defaultIfNull ( " bat " , " NULL " ) = " bat "
 * < / pre > */
public static String defaultIfNull ( final String s , final String defaultStr ) { } }

implementation: return s == null ? defaultStr : s ;


signature:
public class StringUtils { /** * Returns either the passed in String , or if the String is
 * empty or { @ code null } , the value of { @ code defaultStr } .
 * < pre >
 * StringUtils . defaultIfEmpty ( null , " NULL " ) = " NULL "
 * StringUtils . defaultIfEmpty ( " " , " NULL " ) = " NULL "
 * StringUtils . defaultIfEmpty ( " " , " NULL " ) = " "
 * StringUtils . defaultIfEmpty ( " bat " , " NULL " ) = " bat "
 * StringUtils . defaultIfEmpty ( " " , null ) = null
 * < / pre > */
public static String defaultIfEmpty ( final String s , final String defaultStr ) { } }

implementation: return isEmpty ( s ) ? defaultStr : s ;


signature:
public class StringUtils { /** * Returns either the passed in String , or if the String is
 * whitespace , empty ( " " ) or { @ code null } , the value of { @ code defaultStr } .
 * < pre >
 * StringUtils . defaultIfBlank ( null , " NULL " ) = " NULL "
 * StringUtils . defaultIfBlank ( " " , " NULL " ) = " NULL "
 * StringUtils . defaultIfBlank ( " " , " NULL " ) = " NULL "
 * StringUtils . defaultIfBlank ( " bat " , " NULL " ) = " bat "
 * StringUtils . defaultIfBlank ( " " , null ) = null
 * < / pre > */
public static String defaultIfBlank ( final String s , final String defaultStr ) { } }

implementation: return isBlank ( s ) ? defaultStr : s ;


signature:
public class StringUtils { /** * Compares two CharSequences , returning { @ code true } if they represent
 * equal sequences of characters , ignoring case .
 * { @ code null } s are handled without exceptions . Two { @ code null } references
 * are considered equal . Comparison is case insensitive .
 * < pre >
 * StringUtils . equalsIgnoreCase ( null , null ) = true
 * StringUtils . equalsIgnoreCase ( null , " abc " ) = false
 * StringUtils . equalsIgnoreCase ( " abc " , null ) = false
 * StringUtils . equalsIgnoreCase ( " abc " , " abc " ) = true
 * StringUtils . equalsIgnoreCase ( " abc " , " ABC " ) = true
 * < / pre > */
public static boolean equalsIgnoreCase ( final String s1 , final String s2 ) { } }

implementation: if ( s1 == null || s2 == null ) { return s1 == s2 ; } else if ( s1 == s2 ) { return true ; } else if ( s1 . length ( ) != s2 . length ( ) ) { return false ; } else { return s1 . equals ( s2 ) ; }


signature:
public class StringUtils { /** * Check if a String starts with a specified prefix ( optionally case
 * insensitive ) .
 * @ see java . lang . String # startsWith ( String ) */
private static boolean startsWith ( final String s , final String prefix , final boolean ignoreCase ) { } }

implementation: if ( s == null || prefix == null ) { return s == null && prefix == null ; } if ( prefix . length ( ) > s . length ( ) ) { return false ; } return s . toString ( ) . regionMatches ( ignoreCase , 0 , prefix . toString ( ) , 0 , prefix . length ( ) ) ;


signature:
public class StringUtils { /** * Check if a String ends with a specified suffix ( optionally case
 * insensitive ) .
 * @ see java . lang . String # endsWith ( String ) */
private static boolean endsWith ( final String s , final String suffix , final boolean ignoreCase ) { } }

implementation: if ( s == null || suffix == null ) { return s == null && suffix == null ; } if ( suffix . length ( ) > s . length ( ) ) { return false ; } final int strOffset = s . length ( ) - suffix . length ( ) ; return s . toString ( ) . regionMatches ( ignoreCase , strOffset , suffix . toString ( ) , 0 , suffix . length ( ) ) ;


signature:
public class StringUtils { /** * Finds first occurrence of a substring in the given source but within limited range [ start , end ) .
 * It is fastest possible code , but still original < code > String . indexOf ( String , int ) < / code >
 * is much faster ( since it uses char [ ] value directly ) and should be used when no range is needed .
 * @ param s source string for examination
 * @ param substr substring to find
 * @ param startIndex starting index
 * @ param endIndex ending index
 * @ return index of founded substring or - 1 if substring not found */
public static int indexOf ( String s , String substr , int startIndex , int endIndex ) { } }

implementation: if ( startIndex < 0 ) { startIndex = 0 ; } int srclen = s . length ( ) ; if ( endIndex > srclen ) { endIndex = srclen ; } int sublen = substr . length ( ) ; if ( sublen == 0 ) { return startIndex > srclen ? srclen : startIndex ; } int total = endIndex - sublen + 1 ; char c = substr . charAt ( 0 ) ; mainloop : for ( int i = startIndex ; i < total ; i ++ ) { if ( s . charAt ( i ) != c ) { continue ; } int j = 1 ; int k = i + 1 ; while ( j < sublen ) { if ( substr . charAt ( j ) != s . charAt ( k ) ) { continue mainloop ; } j ++ ; k ++ ; } return i ; } return - 1 ;


signature:
public class StringUtils { /** * Finds first index of a substring in the given source string with ignored case .
 * @ param s source string for examination
 * @ param substr substring to find
 * @ return index of founded substring or - 1 if substring is not found
 * @ see # indexOfIgnoreCase ( String , String , int ) */
public static int indexOfIgnoreCase ( String s , String substr ) { } }

implementation: return indexOfIgnoreCase ( s , substr , 0 , s . length ( ) ) ;


signature:
public class StringUtils { /** * Finds first index of a substring in the given source string and range with
 * ignored case .
 * @ param s source string for examination
 * @ param substr substring to find
 * @ param startIndex starting index from where search begins
 * @ param endIndex endint index
 * @ return index of founded substring or - 1 if substring is not found
 * @ see # indexOfIgnoreCase ( String , String , int ) */
public static int indexOfIgnoreCase ( String s , String substr , int startIndex , int endIndex ) { } }

implementation: if ( startIndex < 0 ) { startIndex = 0 ; } int srclen = s . length ( ) ; if ( endIndex > srclen ) { endIndex = srclen ; } int sublen = substr . length ( ) ; if ( sublen == 0 ) { return startIndex > srclen ? srclen : startIndex ; } substr = substr . toLowerCase ( ) ; int total = endIndex - sublen + 1 ; char c = substr . charAt ( 0 ) ; mainloop : for ( int i = startIndex ; i < total ; i ++ ) { if ( Character . toLowerCase ( s . charAt ( i ) ) != c ) { continue ; } int j = 1 ; int k = i + 1 ; while ( j < sublen ) { char source = Character . toLowerCase ( s . charAt ( k ) ) ; if ( substr . charAt ( j ) != source ) { continue mainloop ; } j ++ ; k ++ ; } return i ; } return - 1 ;


signature:
public class StringUtils { /** * Finds the very first index of a char from the specified array . It
 * returns an int [ 2 ] where int [ 0 ] represents the char index and int [ 1]
 * represents position where char was found . Returns < code > null < / code >
 * if noting found .
 * @ param s source string
 * @ param c char array
 * @ param start starting position */
public static int [ ] indexOf ( String s , char c [ ] , int start ) { } }

implementation: int arrLen = c . length ; int index = Integer . MAX_VALUE ; int last = - 1 ; for ( int j = 0 ; j < arrLen ; j ++ ) { int i = s . indexOf ( c [ j ] , start ) ; if ( i != - 1 ) { if ( i < index ) { index = i ; last = j ; } } } return last == - 1 ? null : new int [ ] { last , index } ;


signature:
public class StringUtils { /** * Finds last index of a substring in the given source string with ignored
 * case .
 * @ param s source string
 * @ param substr substring to find
 * @ return last index of founded substring or - 1 if substring is not found
 * @ see # indexOfIgnoreCase ( String , String , int )
 * @ see # lastIndexOfIgnoreCase ( String , String , int ) */
public static int lastIndexOfIgnoreCase ( String s , String substr ) { } }

implementation: return lastIndexOfIgnoreCase ( s , substr , s . length ( ) , 0 ) ;


signature:
public class StringUtils { /** * Finds last index of a substring in the given source string with ignored
 * case .
 * @ param s source string for examination
 * @ param substr substring to find
 * @ param startIndex starting index from where search begins
 * @ return last index of founded substring or - 1 if substring is not found
 * @ see # indexOfIgnoreCase ( String , String , int ) */
public static int lastIndexOfIgnoreCase ( String s , String substr , int startIndex ) { } }

implementation: return lastIndexOfIgnoreCase ( s , substr , startIndex , 0 ) ;


signature:
public class StringUtils { /** * Finds last index of a character in the given source string in specified range [ end , start ] */
public static int lastIndexOfIgnoreCase ( String s , char c , int startIndex , int endIndex ) { } }

implementation: int total = s . length ( ) - 1 ; if ( total < 0 ) { return - 1 ; } if ( startIndex >= total ) { startIndex = total ; } if ( endIndex < 0 ) { endIndex = 0 ; } c = Character . toLowerCase ( c ) ; for ( int i = startIndex ; i >= endIndex ; i -- ) { if ( Character . toLowerCase ( s . charAt ( i ) ) == c ) { return i ; } } return - 1 ;


signature:
public class StringUtils { /** * Finds the very last index of a substring from the specified array . It
 * returns an int [ 2 ] where int [ 0 ] represents the substring index and int [ 1]
 * represents position where substring was found . Returns < code > null < / code >
 * if noting found .
 * @ param s source string
 * @ param arr string array */
public static int [ ] lastIndexOf ( String s , String arr [ ] ) { } }

implementation: return lastIndexOf ( s , arr , s . length ( ) ) ;


signature:
public class StringUtils { /** * Finds the very last index of a substring from the specified array . It
 * returns an int [ 2 ] where int [ 0 ] represents the substring index and int [ 1]
 * represents position where substring was found . Returns < code > null < / code >
 * if noting found .
 * @ param s source string
 * @ param arr string array
 * @ param fromIndex starting position */
public static int [ ] lastIndexOf ( String s , String arr [ ] , int fromIndex ) { } }

implementation: int arrLen = arr . length ; int index = - 1 ; int last = - 1 ; for ( int j = 0 ; j < arrLen ; j ++ ) { int i = s . lastIndexOf ( arr [ j ] , fromIndex ) ; if ( i != - 1 ) { if ( i > index ) { index = i ; last = j ; } } } return last == - 1 ? null : new int [ ] { last , index } ;


signature:
public class StringUtils { /** * Gets a substring from the specified String avoiding exceptions .
 * A negative start position can be used to start { @ code n } characters from
 * the end of the String .
 * A { @ code null } String will return { @ code null } . An empty ( " " ) String will
 * return " " .
 * < pre >
 * StringUtils . substring ( null , * ) = null
 * StringUtils . substring ( " " , * ) = " "
 * StringUtils . substring ( " abc " , 0 ) = " abc "
 * StringUtils . substring ( " abc " , 2 ) = " c "
 * StringUtils . substring ( " abc " , 4 ) = " "
 * StringUtils . substring ( " abc " , - 2 ) = " bc "
 * StringUtils . substring ( " abc " , - 4 ) = " abc "
 * < / pre > */
public static String substring ( final String s , int start ) { } }

implementation:
if ( s == null ) { return null ; } // handle negatives , which means last n characters
if ( start < 0 ) { start = s . length ( ) + start ; // remember start is negative
} if ( start < 0 ) { start = 0 ; } if ( start > s . length ( ) ) { return "" ; } return s . substring ( start ) ;


signature:
public class StringUtils { /** * Gets a substring from the specified String avoiding exceptions .
 * A negative start position can be used to start / end { @ code n } characters
 * from the end of the String .
 * The returned substring starts with the character in the { @ code start }
 * position and ends before the { @ code end } position . All position counting
 * is zero - based - - i . e . , to start at the beginning of the string use
 * { @ code start = 0 } . Negative start and end positions can be used to
 * specify offsets relative to the end of the String .
 * If { @ code start } is not strictly to the left of { @ code end } , " " is
 * returned .
 * < pre >
 * StringUtils . substring ( null , * , * ) = null
 * StringUtils . substring ( " " , * , * ) = " " ;
 * StringUtils . substring ( " abc " , 0 , 2 ) = " ab "
 * StringUtils . substring ( " abc " , 2 , 0 ) = " "
 * StringUtils . substring ( " abc " , 2 , 4 ) = " c "
 * StringUtils . substring ( " abc " , 4 , 6 ) = " "
 * StringUtils . substring ( " abc " , 2 , 2 ) = " "
 * StringUtils . substring ( " abc " , - 2 , - 1 ) = " b "
 * StringUtils . substring ( " abc " , - 4 , 2 ) = " ab "
 * < / pre > */
public static String substring ( final String s , int start , int end ) { } }

implementation:
if ( s == null ) { return null ; } // handle negatives
if ( end < 0 ) { end = s . length ( ) + end ; // remember end is negative
} if ( start < 0 ) { start = s . length ( ) + start ; // remember start is negative
} // check length next
if ( end > s . length ( ) ) { end = s . length ( ) ; } // if start is greater than end , return " "
if ( start > end ) { return "" ; } if ( start < 0 ) { start = 0 ; } if ( end < 0 ) { end = 0 ; } return s . substring ( start , end ) ;


signature:
public class StringUtils { /** * Gets the substring before the first occurrence of a separator . The
 * separator is not returned .
 * A { @ code null } string input will return { @ code null } . An empty ( " " )
 * string input will return the empty string . A { @ code null } separator will
 * return the input string .
 * If nothing is found , the string input is returned .
 * < pre >
 * StringUtils . substringBefore ( null , * ) = null
 * StringUtils . substringBefore ( " " , * ) = " "
 * StringUtils . substringBefore ( " abc " , " a " ) = " "
 * StringUtils . substringBefore ( " abcba " , " b " ) = " a "
 * StringUtils . substringBefore ( " abc " , " c " ) = " ab "
 * StringUtils . substringBefore ( " abc " , " d " ) = " abc "
 * StringUtils . substringBefore ( " abc " , " " ) = " "
 * StringUtils . substringBefore ( " abc " , null ) = " abc "
 * < / pre > */
public static String substringBefore ( final String s , final String separator ) { } }

implementation: if ( isEmpty ( s ) || separator == null ) { return s ; } if ( separator . isEmpty ( ) ) { return "" ; } final int pos = s . indexOf ( separator ) ; if ( pos < 0 ) { return s ; } return s . substring ( 0 , pos ) ;


signature:
public class StringUtils { /** * Gets the substring after the first occurrence of a separator . The
 * separator is not returned .
 * A { @ code null } string input will return { @ code null } . An empty ( " " )
 * string input will return the empty string . A { @ code null } separator will
 * return the empty string if the input string is not { @ code null } .
 * If nothing is found , the empty string is returned .
 * < pre >
 * StringUtils . substringAfter ( null , * ) = null
 * StringUtils . substringAfter ( " " , * ) = " "
 * StringUtils . substringAfter ( * , null ) = " "
 * StringUtils . substringAfter ( " abc " , " a " ) = " bc "
 * StringUtils . substringAfter ( " abcba " , " b " ) = " cba "
 * StringUtils . substringAfter ( " abc " , " c " ) = " "
 * StringUtils . substringAfter ( " abc " , " d " ) = " "
 * StringUtils . substringAfter ( " abc " , " " ) = " abc "
 * < / pre > */
public static String substringAfter ( final String s , final String separator ) { } }

implementation: if ( isEmpty ( s ) ) { return s ; } if ( separator == null ) { return "" ; } final int pos = s . indexOf ( separator ) ; if ( pos < 0 ) { return "" ; } return s . substring ( pos + separator . length ( ) ) ;


signature:
public class StringUtils { /** * Gets the substring before the last occurrence of a separator . The
 * separator is not returned .
 * A { @ code null } string input will return { @ code null } . An empty ( " " )
 * string input will return the empty string . An empty or { @ code null }
 * separator will return the input string .
 * If nothing is found , the string input is returned .
 * < pre >
 * StringUtils . substringBeforeLast ( null , * ) = null
 * StringUtils . substringBeforeLast ( " " , * ) = " "
 * StringUtils . substringBeforeLast ( " abcba " , " b " ) = " abc "
 * StringUtils . substringBeforeLast ( " abc " , " c " ) = " ab "
 * StringUtils . substringBeforeLast ( " a " , " a " ) = " "
 * StringUtils . substringBeforeLast ( " a " , " z " ) = " a "
 * StringUtils . substringBeforeLast ( " a " , null ) = " a "
 * StringUtils . substringBeforeLast ( " a " , " " ) = " a "
 * < / pre > */
public static String substringBeforeLast ( final String s , final String separator ) { } }

implementation: if ( isEmpty ( s ) || isEmpty ( separator ) ) { return s ; } final int pos = s . lastIndexOf ( separator ) ; if ( pos < 0 ) { return s ; } return s . substring ( 0 , pos ) ;


signature:
public class StringUtils { /** * Gets the substring after the last occurrence of a separator . The
 * separator is not returned .
 * A { @ code null } string input will return { @ code null } . An empty ( " " )
 * string input will return the empty string . An empty or { @ code null }
 * separator will return the empty string if the input string is not
 * { @ code null } .
 * If nothing is found , the empty string is returned .
 * < pre >
 * StringUtils . substringAfterLast ( null , * ) = null
 * StringUtils . substringAfterLast ( " " , * ) = " "
 * StringUtils . substringAfterLast ( * , " " ) = " "
 * StringUtils . substringAfterLast ( * , null ) = " "
 * StringUtils . substringAfterLast ( " abc " , " a " ) = " bc "
 * StringUtils . substringAfterLast ( " abcba " , " b " ) = " a "
 * StringUtils . substringAfterLast ( " abc " , " c " ) = " "
 * StringUtils . substringAfterLast ( " a " , " a " ) = " "
 * StringUtils . substringAfterLast ( " a " , " z " ) = " "
 * < / pre > */
public static String substringAfterLast ( final String s , final String separator ) { } }

implementation: if ( isEmpty ( s ) ) { return s ; } if ( isEmpty ( separator ) ) { return "" ; } final int pos = s . lastIndexOf ( separator ) ; if ( pos < 0 || pos == s . length ( ) - separator . length ( ) ) { return "" ; } return s . substring ( pos + separator . length ( ) ) ;


signature:
public class StringUtils { /** * Gets the String that is nested in between two instances of the same
 * String .
 * A { @ code null } input String returns { @ code null } . A { @ code null } tag
 * returns { @ code null } .
 * < pre >
 * StringUtils . substringBetween ( null , * ) = null
 * StringUtils . substringBetween ( " " , " " ) = " "
 * StringUtils . substringBetween ( " " , " tag " ) = null
 * StringUtils . substringBetween ( " tagabctag " , null ) = null
 * StringUtils . substringBetween ( " tagabctag " , " " ) = " "
 * StringUtils . substringBetween ( " tagabctag " , " tag " ) = " abc "
 * < / pre > */
public static String substringBetween ( final String s , final String tag ) { } }

implementation: return substringBetween ( s , tag , tag ) ;


signature:
public class StringUtils { /** * Gets the leftmost { @ code len } characters of a String .
 * If { @ code len } characters are not available , or the String is
 * { @ code null } , the String will be returned without an exception . An empty
 * String is returned if len is negative .
 * < pre >
 * StringUtils . left ( null , * ) = null
 * StringUtils . left ( * , - ve ) = " "
 * StringUtils . left ( " " , * ) = " "
 * StringUtils . left ( " abc " , 0 ) = " "
 * StringUtils . left ( " abc " , 2 ) = " ab "
 * StringUtils . left ( " abc " , 4 ) = " abc "
 * < / pre > */
public static String left ( final String s , final int len ) { } }

implementation: if ( s == null ) { return null ; } if ( len < 0 ) { return "" ; } if ( s . length ( ) <= len ) { return s ; } return s . substring ( 0 , len ) ;


signature:
public class StringUtils { /** * Gets the rightmost { @ code len } characters of a String .
 * If { @ code len } characters are not available , or the String is
 * { @ code null } , the String will be returned without an an exception . An
 * empty String is returned if len is negative .
 * < pre >
 * StringUtils . right ( null , * ) = null
 * StringUtils . right ( * , - ve ) = " "
 * StringUtils . right ( " " , * ) = " "
 * StringUtils . right ( " abc " , 0 ) = " "
 * StringUtils . right ( " abc " , 2 ) = " bc "
 * StringUtils . right ( " abc " , 4 ) = " abc "
 * < / pre > */
public static String right ( final String s , final int len ) { } }

implementation: if ( s == null ) { return null ; } if ( len < 0 ) { return "" ; } if ( s . length ( ) <= len ) { return s ; } return s . substring ( s . length ( ) - len ) ;


signature:
public class StringUtils { /** * Gets { @ code len } characters from the middle of a String .
 * If { @ code len } characters are not available , the remainder of the String
 * will be returned without an exception . If the String is { @ code null } ,
 * { @ code null } will be returned . An empty String is returned if len is
 * negative or exceeds the length of { @ code str } .
 * < pre >
 * StringUtils . mid ( null , * , * ) = null
 * StringUtils . mid ( * , * , - ve ) = " "
 * StringUtils . mid ( " " , 0 , * ) = " "
 * StringUtils . mid ( " abc " , 0 , 2 ) = " ab "
 * StringUtils . mid ( " abc " , 0 , 4 ) = " abc "
 * StringUtils . mid ( " abc " , 2 , 4 ) = " c "
 * StringUtils . mid ( " abc " , 4 , 2 ) = " "
 * StringUtils . mid ( " abc " , - 2 , 2 ) = " ab "
 * < / pre > */
public static String mid ( final String s , int pos , final int len ) { } }

implementation: if ( s == null ) { return null ; } if ( len < 0 || pos > s . length ( ) ) { return "" ; } if ( pos < 0 ) { pos = 0 ; } if ( s . length ( ) <= pos + len ) { return s . substring ( pos ) ; } return s . substring ( pos , pos + len ) ;


signature:
public class StringUtils { /** * Repeat a String { @ code repeat } times to form a new String .
 * < pre >
 * StringUtils . repeat ( null , 2 ) = null
 * StringUtils . repeat ( " " , 0 ) = " "
 * StringUtils . repeat ( " " , 2 ) = " "
 * StringUtils . repeat ( " a " , 3 ) = " aaa "
 * StringUtils . repeat ( " ab " , 2 ) = " abab "
 * StringUtils . repeat ( " a " , - 2 ) = " "
 * < / pre > */
public static String repeat ( final String s , final int repeat ) { } }

implementation: if ( s == null ) { return null ; } if ( repeat <= 0 ) { return "" ; } final int inputLength = s . length ( ) ; if ( repeat == 1 || inputLength == 0 ) { return s ; } final int outputLength = inputLength * repeat ; switch ( inputLength ) { case 1 : return repeat ( s . charAt ( 0 ) , repeat ) ; case 2 : final char ch0 = s . charAt ( 0 ) ; final char ch1 = s . charAt ( 1 ) ; final char [ ] output2 = new char [ outputLength ] ; for ( int i = repeat * 2 - 2 ; i >= 0 ; i -- , i -- ) { output2 [ i ] = ch0 ; output2 [ i + 1 ] = ch1 ; } return new String ( output2 ) ; default : final StringBuilder buf = new StringBuilder ( outputLength ) ; for ( int i = 0 ; i < repeat ; i ++ ) { buf . append ( s ) ; } return buf . toString ( ) ; }


signature:
public class StringUtils { /** * Repeat a String { @ code repeat } times to form a new String , with a String
 * separator injected each time .
 * < pre >
 * StringUtils . repeat ( null , null , 2 ) = null
 * StringUtils . repeat ( null , " x " , 2 ) = null
 * StringUtils . repeat ( " " , null , 0 ) = " "
 * StringUtils . repeat ( " " , " " , 2 ) = " "
 * StringUtils . repeat ( " " , " x " , 3 ) = " xxx "
 * StringUtils . repeat ( " ? " , " , " , 3 ) = " ? , ? , ? "
 * < / pre > */
public static String repeat ( final String s , final String separator , final int repeat ) { } }

implementation:
if ( s == null || separator == null ) { return repeat ( s , repeat ) ; } // given that repeat ( String , int ) is quite optimized , better to rely on
// it than try and splice this into it
final String result = repeat ( s + separator , repeat ) ; return removeEnd ( result , separator ) ;


signature:
public class StringUtils { /** * Deletes all whitespaces from a String as defined by
 * { @ link Character # isWhitespace ( char ) } .
 * < pre >
 * StringUtils . deleteWhitespace ( null ) = null
 * StringUtils . deleteWhitespace ( " " ) = " "
 * StringUtils . deleteWhitespace ( " abc " ) = " abc "
 * StringUtils . deleteWhitespace ( " ab c " ) = " abc "
 * < / pre >
 * @ param s
 * the String to delete whitespace from , may be null
 * @ return the String without whitespaces , { @ code null } if null String input */
public static String deleteWhitespace ( final String s ) { } }

implementation: if ( isEmpty ( s ) ) { return s ; } final int sz = s . length ( ) ; final char [ ] chs = new char [ sz ] ; int count = 0 ; for ( int i = 0 ; i < sz ; i ++ ) { if ( ! Character . isWhitespace ( s . charAt ( i ) ) ) { chs [ count ++ ] = s . charAt ( i ) ; } } if ( count == sz ) { return s ; } return new String ( chs , 0 , count ) ;


signature:
public class StringUtils { /** * Removes a substring only if it is at the beginning of a source string ,
 * otherwise returns the source string .
 * A { @ code null } source string will return { @ code null } . An empty ( " " )
 * source string will return the empty string . A { @ code null } search string
 * will return the source string .
 * < pre >
 * StringUtils . removeStart ( null , * ) = null
 * StringUtils . removeStart ( " " , * ) = " "
 * StringUtils . removeStart ( * , null ) = *
 * StringUtils . removeStart ( " www . domain . com " , " www . " ) = " domain . com "
 * StringUtils . removeStart ( " domain . com " , " www . " ) = " domain . com "
 * StringUtils . removeStart ( " www . domain . com " , " domain " ) = " www . domain . com "
 * StringUtils . removeStart ( " abc " , " " ) = " abc "
 * < / pre > */
public static String removeStart ( final String s , final String remove ) { } }

implementation: if ( isEmpty ( s ) || isEmpty ( remove ) ) { return s ; } if ( s . startsWith ( remove ) ) { return s . substring ( remove . length ( ) ) ; } return s ;


signature:
public class StringUtils { /** * Case insensitive removal of a substring if it is at the beginning of a
 * source string , otherwise returns the source string .
 * A { @ code null } source string will return { @ code null } . An empty ( " " )
 * source string will return the empty string . A { @ code null } search string
 * will return the source string .
 * < pre >
 * StringUtils . removeStartIgnoreCase ( null , * ) = null
 * StringUtils . removeStartIgnoreCase ( " " , * ) = " "
 * StringUtils . removeStartIgnoreCase ( * , null ) = *
 * StringUtils . removeStartIgnoreCase ( " www . domain . com " , " www . " ) = " domain . com "
 * StringUtils . removeStartIgnoreCase ( " www . domain . com " , " WWW . " ) = " domain . com "
 * StringUtils . removeStartIgnoreCase ( " domain . com " , " www . " ) = " domain . com "
 * StringUtils . removeStartIgnoreCase ( " www . domain . com " , " domain " ) = " www . domain . com "
 * StringUtils . removeStartIgnoreCase ( " abc " , " " ) = " abc "
 * < / pre > */
public static String removeStartIgnoreCase ( final String s , final String remove ) { } }

implementation: if ( isEmpty ( s ) || isEmpty ( remove ) ) { return s ; } if ( startsWithIgnoreCase ( s , remove ) ) { return s . substring ( remove . length ( ) ) ; } return s ;


signature:
public class StringUtils { /** * Removes a substring only if it is at the end of a source string ,
 * otherwise returns the source string .
 * A { @ code null } source string will return { @ code null } . An empty ( " " )
 * source string will return the empty string . A { @ code null } search string
 * will return the source string .
 * < pre >
 * StringUtils . removeEnd ( null , * ) = null
 * StringUtils . removeEnd ( " " , * ) = " "
 * StringUtils . removeEnd ( * , null ) = *
 * StringUtils . removeEnd ( " www . domain . com " , " . com . " ) = " www . domain . com "
 * StringUtils . removeEnd ( " www . domain . com " , " . com " ) = " www . domain "
 * StringUtils . removeEnd ( " www . domain . com " , " domain " ) = " www . domain . com "
 * StringUtils . removeEnd ( " abc " , " " ) = " abc "
 * < / pre > */
public static String removeEnd ( final String s , final String remove ) { } }

implementation: if ( isEmpty ( s ) || isEmpty ( remove ) ) { return s ; } if ( s . endsWith ( remove ) ) { return s . substring ( 0 , s . length ( ) - remove . length ( ) ) ; } return s ;


signature:
public class StringUtils { /** * Case insensitive removal of a substring if it is at the end of a source
 * string , otherwise returns the source string .
 * A { @ code null } source string will return { @ code null } . An empty ( " " )
 * source string will return the empty string . A { @ code null } search string
 * will return the source string .
 * < pre >
 * StringUtils . removeEndIgnoreCase ( null , * ) = null
 * StringUtils . removeEndIgnoreCase ( " " , * ) = " "
 * StringUtils . removeEndIgnoreCase ( * , null ) = *
 * StringUtils . removeEndIgnoreCase ( " www . domain . com " , " . com . " ) = " www . domain . com "
 * StringUtils . removeEndIgnoreCase ( " www . domain . com " , " . com " ) = " www . domain "
 * StringUtils . removeEndIgnoreCase ( " www . domain . com " , " domain " ) = " www . domain . com "
 * StringUtils . removeEndIgnoreCase ( " abc " , " " ) = " abc "
 * StringUtils . removeEndIgnoreCase ( " www . domain . com " , " . COM " ) = " www . domain " )
 * StringUtils . removeEndIgnoreCase ( " www . domain . COM " , " . com " ) = " www . domain " )
 * < / pre > */
public static String removeEndIgnoreCase ( final String s , final String remove ) { } }

implementation: if ( isEmpty ( s ) || isEmpty ( remove ) ) { return s ; } if ( endsWithIgnoreCase ( s , remove ) ) { return s . substring ( 0 , s . length ( ) - remove . length ( ) ) ; } return s ;


signature:
public class StringUtils { /** * Removes all occurrences of a substring from within the source string .
 * A { @ code null } source string will return { @ code null } . An empty ( " " )
 * source string will return the empty string . A { @ code null } remove string
 * will return the source string . An empty ( " " ) remove string will return
 * the source string .
 * < pre >
 * StringUtils . remove ( null , * ) = null
 * StringUtils . remove ( " " , * ) = " "
 * StringUtils . remove ( * , null ) = *
 * StringUtils . remove ( * , " " ) = *
 * StringUtils . remove ( " queued " , " ue " ) = " qd "
 * StringUtils . remove ( " queued " , " zz " ) = " queued "
 * < / pre > */
public static String remove ( final String s , final String remove ) { } }

implementation: if ( isEmpty ( s ) || isEmpty ( remove ) ) { return s ; } return replace ( s , remove , "" , - 1 ) ;


signature:
public class StringUtils { /** * Removes all characters contained in provided string .
 * @ param s source string
 * @ param chars string containing characters to remove */
public static String removeChars ( String s , String chars ) { } }

implementation: int i = s . length ( ) ; StringBuilder sb = new StringBuilder ( i ) ; for ( int j = 0 ; j < i ; j ++ ) { char c = s . charAt ( j ) ; if ( chars . indexOf ( c ) == - 1 ) { sb . append ( c ) ; } } return sb . toString ( ) ;


signature:
public class StringUtils { /** * 按逗号分隔 , 两边加引号的不分割 ( CSV 规则 ) . */
public static String [ ] splitCSV ( String str ) { } }

implementation: if ( str == null ) return null ; String [ ] parts = StringUtils . split ( str , ',' ) ; List < String > results = new ArrayList < String > ( ) ; for ( int i = 0 ; i < parts . length ; i ++ ) { String s = parts [ i ] . trim ( ) ; if ( s . length ( ) == 0 ) { results . add ( s ) ; } else { char c = s . charAt ( 0 ) ; if ( c == '"' || c == '\'' || c == '`' ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( s ) ; while ( i + 1 < parts . length ) { if ( sb . length ( ) > 1 && s . length ( ) > 0 && s . charAt ( s . length ( ) - 1 ) == c ) { break ; } s = parts [ ++ i ] ; sb . append ( ',' ) . append ( s ) ; } s = sb . toString ( ) . trim ( ) ; if ( s . charAt ( s . length ( ) - 1 ) == c ) { s = s . substring ( 1 , s . length ( ) - 1 ) ; } results . add ( s ) ; } else { results . add ( s ) ; } } } return results . toArray ( new String [ results . size ( ) ] ) ;


signature:
public class PasswordLoginModule { /** * { @ inheritDoc }
 * @ throws NullPointerException When the { @ code subject } , { @ code callbackHandler } , { @ code sharedState } , or
 * { @ code options } are { @ code null } */
@ Override public final void initialize ( final Subject subject , final CallbackHandler callbackHandler , final Map < String , ? > sharedState , final Map < String , ? > options ) { } }

implementation:
LOG . debug ( "Initializing" ) ; Validate . notNull ( subject , "The validated object 'subject' is null" ) ; Validate . notNull ( callbackHandler , "The validated object 'callbackHandler' is null" ) ; Validate . notNull ( sharedState , "The validated object 'sharedState' is null" ) ; Validate . notNull ( options , "The validated object 'options' is null" ) ; // keep a reference to the originally provided arguments ( no defensive copy )
this . pSubject = subject ; this . pCallbackHandler = callbackHandler ; // It would be nice to parse the configuration only once , and store it for later use . However , we are
// deliberately NOT caching the parsed configuration , as JAAS does not offer a standard way to to reset the
// cached variable , and allow users of the login module to reset the parsed config in case an app does need to
// re - read its configuration .
final CommonProperties commonProps = JaasBasedCommonPropsBuilder . build ( options ) ; // initialize the audit object
initAudit ( commonProps ) ; // initialize the message object
initMessageQueue ( commonProps ) ; // initialize the validator object
initPwValidator ( commonProps ) ; // initialize the authenticator object
initPwAuthenticator ( commonProps ) ; LOG . info ( "Initialization complete" ) ;


signature:
public class PasswordLoginModule { /** * { @ inheritDoc }
 * @ return { @ code true } if authentication succeeds
 * @ throws LoginException if this { @ code LoginModule } is unable to perform the authentication . Catch a
 * { @ link javax . security . auth . login . FailedLoginException } to determine if the authentication
 * failed ( wrong username or password ) */
@ Override // Check is broken [ LOG . info ( ) ] : PMD reports issues although log stmt is guarded . @ todo revisit when upgrading PMD .
@ SuppressWarnings ( "PMD.GuardLogStatementJavaUtil" ) public final boolean login ( ) throws LoginException { } }

implementation:
LOG . debug ( "Attempting login" ) ; if ( pCallbackHandler == null ) { final String error = "No CallbackHandler available to garner authentication information from the user" ; LOG . error ( error ) ; throw new LoginException ( error ) ; } Callback [ ] callbacks = new Callback [ 3 ] ; callbacks [ 0 ] = new TextInputCallback ( "j_domain" ) ; callbacks [ 1 ] = new NameCallback ( "j_username" ) ; callbacks [ 2 ] = new PasswordCallback ( "j_password" , false ) ; try { pCallbackHandler . handle ( callbacks ) ; // store the domain
domain = ( ( TextInputCallback ) callbacks [ 0 ] ) . getText ( ) ; // store the username
username = ( ( NameCallback ) callbacks [ 1 ] ) . getName ( ) ; // store the password ( i . e . a copy of the password )
final char [ ] tempPassword = ( ( PasswordCallback ) callbacks [ 2 ] ) . getPassword ( ) ; password = tempPassword . clone ( ) ; // clear the password in the callback
( ( PasswordCallback ) callbacks [ 2 ] ) . clearPassword ( ) ; } catch ( java . io . IOException e ) { cleanState ( ) ; final String error = "Encountered an I/O exception during login" ; LOG . warn ( error , e ) ; throw Util . newLoginException ( error , e ) ; } catch ( UnsupportedCallbackException e ) { cleanState ( ) ; final String error = e . getCallback ( ) . toString ( ) + " not available to garner authentication information from the user" ; LOG . warn ( error , e ) ; throw Util . newLoginException ( error , e ) ; } LOG . debug ( "Attempting login - discovered user '" + username + "@" + domain + "'" ) ; // Using a try / catch construct for managing control flows is really a bad idea .
// Unfortunately , this is how JAAS works : - (
try { // authenticate , and update state and pending subject if successful
pendingSubject = pwAuthenticator . authenticate ( domain , username , password , pwValidator ) ; // then clear the password
Cleanser . wipe ( password ) ; final String baseError = new StringBuilder ( ) . append ( "Login successful for '" ) . append ( username ) . append ( "@" ) . append ( domain ) . toString ( ) ; AuditHelper . auditEvent ( audit , domain , username , Events . AUTHN_ATTEMPT , baseError + "', but cannot audit login attempt, and hence fail the operation" ) ; MessageHelper . postMessage ( messageQ , domain , username , Events . AUTHN_ATTEMPT , baseError + "', but cannot post MQ login attempt event, and hence fail the operation" ) ; // string concatenation is only executed if log level is actually enabled
if ( LOG . isInfoEnabled ( ) ) { LOG . info ( "Login complete for '" + username + "@" + domain + "'" ) ; } return true ; } catch ( LoginException e ) { // the login failed
// cache the username and domain , for they will be purged by " cleanState ( ) "
final String tempUsername = username ; final String tempDomain = domain ; cleanState ( ) ; final String baseError = new StringBuilder ( ) . append ( "Login failed for '" ) . append ( tempUsername ) . append ( "@" ) . append ( tempDomain ) . toString ( ) ; AuditHelper . auditEvent ( audit , tempDomain , tempUsername , Events . AUTHN_FAILURE , baseError + "', but cannot audit login attempt" ) ; MessageHelper . postMessage ( messageQ , tempDomain , tempUsername , Events . AUTHN_FAILURE , baseError + "', but cannot post MQ login attempt event" ) ; final String error = "Login failed for '" + tempUsername + "@" + tempDomain + "'" ; LOG . info ( error , e ) ; throw e ; }


signature:
public class PasswordLoginModule { /** * { @ inheritDoc } */
@ Override // Check is broken [ LOG . info ( ) ] : PMD reports issues although log stmt is guarded . @ todo revisit when upgrading PMD .
@ SuppressWarnings ( "PMD.GuardLogStatementJavaUtil" ) public final boolean commit ( ) throws LoginException { } }

implementation:
LOG . debug ( "Committing authentication" ) ; if ( pendingSubject == null ) { // the login method of this module has failed earlier , hence we do not need to clean up anything
// return ' false ' to indicate that this module ' s login and / or commit method failed
// As the login method failed , the state of the module has already been cleared and we do not know
// the username / domain anymore . Hence no auditing / message queue notification , and not verbose logging .
LOG . debug ( "Not committing authentication, as the authentication has failed earlier (login method)" ) ; return false ; } else { // The login has succeeded !
// Store the principals from the pending subject both in the ' subject ' object ( because this is what JAAS
// will use later on ) , but also create a new ' committedSubject ' object that this module uses to a ) keep
// state and b ) being able to remove the principals later
LOG . debug ( "Committing authentication: '" + username + "@" + domain + "'" ) ; if ( committedSubject == null ) { committedSubject = new Subject ( ) ; } else { // cache the username and domain , for they will be purged by " cleanState ( ) "
final String tempUsername = username ; final String tempDomain = domain ; cleanState ( ) ; final String baseError = new StringBuilder ( ) . append ( "Login post-processing failed for '" ) . append ( tempUsername ) . append ( "@" ) . append ( tempDomain ) . toString ( ) ; AuditHelper . auditEvent ( audit , tempDomain , tempUsername , Events . AUTHN_ERROR , baseError + "', but cannot audit login attempt" ) ; MessageHelper . postMessage ( messageQ , tempDomain , tempUsername , Events . AUTHN_ERROR , baseError + "', but cannot post MQ login attempt event" ) ; final String error = "Expected the committed subject to be 'null' (yes, really <null>), but this was " + "not the case! Has the commit method been called multiple times on the same object instance?" ; LOG . warn ( error ) ; throw new LoginException ( error ) ; } for ( final Principal p : pendingSubject . getPrincipals ( ) ) { // 1 . Add the principals to the ' subject ' object
if ( ! pSubject . getPrincipals ( ) . contains ( p ) ) { LOG . debug ( "Added principal " + p . getName ( ) + " to subject" ) ; pSubject . getPrincipals ( ) . add ( p ) ; } // 2 . Add the principals to the ' committedSubject ' object
if ( ! committedSubject . getPrincipals ( ) . contains ( p ) ) { LOG . debug ( "Added principal " + p . getName ( ) + " to committed subject" ) ; committedSubject . getPrincipals ( ) . add ( p ) ; } } final String baseError = new StringBuilder ( ) . append ( "Login succeeded for '" ) . append ( username ) . append ( "@" ) . append ( domain ) . toString ( ) ; AuditHelper . auditEvent ( audit , domain , username , Events . AUTHN_SUCCESS , baseError + "', but cannot audit login success, and hence fail the operation" ) ; MessageHelper . postMessage ( messageQ , domain , username , Events . AUTHN_SUCCESS , baseError + "', but cannot post MQ login success event, and hence fail the operation" ) ; // string concatenation is only executed if log level is actually enabled
if ( LOG . isInfoEnabled ( ) ) { LOG . info ( "Authentication committed for '" + username + "@" + domain + "'" ) ; } // do not clean the state here , as we may still need it in case of an abort ( )
return true ; }


signature:
public class PasswordLoginModule { /** * { @ inheritDoc } */
@ Override // Check is broken [ LOG . info ( ) ] : PMD reports issues although log stmt is guarded . @ todo revisit when upgrading PMD .
@ SuppressWarnings ( "PMD.GuardLogStatementJavaUtil" ) public final boolean abort ( ) throws LoginException { } }

implementation:
if ( pendingSubject == null ) { // the login method of this module has failed earlier , hence we do not need to clean up anything
// return ' false ' to indicate that this module ' s login and / or commit method failed
// As the login method failed , the state of the module has already been cleared and we do not know
// the username / domain anymore . Hence no auditing / message queue notification , and not verbose logging .
LOG . debug ( "Aborting authentication, as the authentication has failed earlier (login method)" ) ; return false ; } else if ( committedSubject == null ) { // the login method of this module succeeded , but the overall authentication failed
// string concatenation is only executed if log level is actually enabled
if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Aborting authentication: '" + username + "@" + domain + "'" ) ; } // cache the username and domain , for they will be purged by " cleanState ( ) "
final String tempUsername = username ; final String tempDomain = domain ; cleanState ( ) ; final String baseError = new StringBuilder ( ) . append ( "Login post-processing failed after abort for '" ) . append ( tempUsername ) . append ( "@" ) . append ( tempDomain ) . toString ( ) ; AuditHelper . auditEvent ( audit , tempDomain , tempUsername , Events . AUTHN_ABORT_COMMIT , baseError + "', but cannot audit login attempt" ) ; MessageHelper . postMessage ( messageQ , tempDomain , tempUsername , Events . AUTHN_ABORT_COMMIT , baseError + "', but cannot post MQ login attempt event" ) ; // string concatenation is only executed if log level is actually enabled
if ( LOG . isInfoEnabled ( ) ) { LOG . info ( "Authentication aborted for '" + tempUsername + "@" + tempDomain + "'" ) ; } return true ; } else { // overall authentication succeeded and commit succeeded , but someone else ' s commit failed
final String baseError = new StringBuilder ( ) . append ( "Login post-processing failed after abort for '" ) . append ( username ) . append ( "@" ) . append ( domain ) . toString ( ) ; AuditHelper . auditEvent ( audit , domain , username , Events . AUTHN_ABORT_CHAIN , baseError + "', but cannot audit login attempt" ) ; MessageHelper . postMessage ( messageQ , domain , username , Events . AUTHN_ABORT_CHAIN , baseError + "', but cannot post MQ login attempt event" ) ; // cache the username and domain , for they will be purged by " logout ( ) "
final String tempUsername = username ; final String tempDomain = domain ; logout ( ) ; // string concatenation is only executed if log level is actually enabled
if ( LOG . isInfoEnabled ( ) ) { LOG . info ( "Authentication aborted for '" + tempUsername + "@" + tempDomain + "'" ) ; } return true ; }


signature:
public class PasswordLoginModule { /** * { @ inheritDoc } */
@ Override // Check is broken [ LOG . info ( ) ] : PMD reports issues although log stmt is guarded . @ todo revisit when upgrading PMD .
@ SuppressWarnings ( "PMD.GuardLogStatementJavaUtil" ) public final boolean logout ( ) throws LoginException { } }

implementation:
final StringBuilder principals = new StringBuilder ( ":" ) ; // remove all the principals that we added in the commit ( ) method from the ' subject ' object
// ( that ' s why we stored our principals in the ' committedSubject ' object . . . )
if ( committedSubject != null && committedSubject . getPrincipals ( ) != null ) { final StringBuilder stringBuilder = new StringBuilder ( ) ; for ( final Principal p : committedSubject . getPrincipals ( ) ) { pSubject . getPrincipals ( ) . remove ( p ) ; // string concatenation is only executed if log level is actually enabled
if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Logging out subject: '" + p . getName ( ) + "'" ) ; } principals . append ( p . getName ( ) ) . append ( ':' ) ; stringBuilder . delete ( 0 , stringBuilder . length ( ) ) ; final String baseError = stringBuilder . append ( "Logout successful for '" ) . append ( username ) . append ( "@" ) . append ( domain ) . toString ( ) ; AuditHelper . auditEvent ( audit , domain , username , Events . AUTHN_LOGOUT , baseError + "', but cannot audit logout attempt" ) ; MessageHelper . postMessage ( messageQ , domain , username , Events . AUTHN_LOGOUT , baseError + "', but cannot post MQ logout attempt event" ) ; } } cleanState ( ) ; // string concatenation is only executed if log level is actually enabled
if ( LOG . isInfoEnabled ( ) ) { LOG . info ( "Principals logged out: '" + principals + "'" ) ; } return true ;


signature:
public class PasswordLoginModule { /** * Clean up any state associated with the current login attempt . */
@ SuppressWarnings ( "PMD.NullAssignment" ) private void cleanState ( ) { } }

implementation:
// null - assignments for de - referencing objects are okay
domain = null ; username = null ; Cleanser . wipe ( password ) ; pendingSubject = null ; committedSubject = null ;


signature:
public class PasswordLoginModule { /** * Initialize the instance - global audit object
 * @ param commonProps The parsed JAAS configuration , plus additional raw values */
@ SuppressWarnings ( "PMD.ConfusingTernary" ) private void initAudit ( final CommonProperties commonProps ) { } }

implementation:
try { final String auditClassName = commonProps . getAuditClassName ( ) ; // this would be harder to read when following PMD ' s advice - ignoring the PMD warning
if ( ! commonProps . isAuditEnabled ( ) ) { final String error = "Auditing has been disabled in the JAAS configuration" ; LOG . info ( error ) ; } else if ( auditClassName == null ) { final String error = "Auditing has been enabled in the JAAS configuration, but no audit class has been configured" ; LOG . error ( error ) ; throw new IllegalStateException ( error ) ; } else { if ( commonProps . isAuditSingleton ( ) ) { LOG . debug ( "Requesting singleton audit class instance of '" + auditClassName + "' from the audit factory" ) ; this . audit = AuditFactory . getSingleton ( auditClassName , commonProps ) ; } else { LOG . debug ( "Requesting non-singleton audit class instance of '" + auditClassName + "' from the audit factory" ) ; this . audit = AuditFactory . getInstance ( auditClassName , commonProps ) ; } } } catch ( FactoryException e ) { final String error = "The audit class cannot be instantiated. This is most likely a configuration" + " problem. Is the configured class available in the classpath?" ; LOG . error ( error , e ) ; throw new IllegalStateException ( error , e ) ; }


signature:
public class PasswordLoginModule { /** * Initialize the instance - global message queue object
 * @ param commonProps The parsed JAAS configuration , plus additional raw values */
@ SuppressWarnings ( "PMD.ConfusingTernary" ) private void initMessageQueue ( final CommonProperties commonProps ) { } }

implementation:
try { final String messageClassName = commonProps . getMessageQueueClassName ( ) ; // this would be harder to read when following PMD ' s advice - ignoring the PMD warning
if ( ! commonProps . isMessageQueueEnabled ( ) ) { final String error = "Message queue has been disabled in the JAAS configuration" ; LOG . info ( error ) ; } else if ( messageClassName == null ) { final String error = "Message queue has been enabled in the JAAS configuration, " + "but no message queue class has been configured" ; LOG . error ( error ) ; throw new IllegalStateException ( error ) ; } else { if ( commonProps . isMessageQueueSingleton ( ) ) { LOG . debug ( "Requesting singleton message class instance of '" + messageClassName + "' from the message factory" ) ; this . messageQ = MessageQFactory . getSingleton ( messageClassName , commonProps ) ; } else { LOG . debug ( "Requesting non-singleton message class instance of '" + messageClassName + "' from the message factory" ) ; this . messageQ = MessageQFactory . getInstance ( messageClassName , commonProps ) ; } } } catch ( FactoryException e ) { final String error = "The message class cannot be instantiated. This is most likely a configuration" + " problem. Is the configured class available in the classpath?" ; LOG . error ( error , e ) ; throw new IllegalStateException ( error , e ) ; }


signature:
public class PasswordLoginModule { /** * Initialize the instance - global password validator object
 * @ param commonProps The parsed JAAS configuration , plus additional raw values */
private void initPwValidator ( final CommonProperties commonProps ) { } }

implementation:
try { final String validatorClass = commonProps . getPasswordValidatorClassName ( ) ; if ( validatorClass == null ) { final String error = "No password validator class has been configured in the JAAS configuration" ; LOG . error ( error ) ; throw new IllegalStateException ( error ) ; } else { if ( commonProps . isPasswordValidatorSingleton ( ) ) { // Fortify will report a violation here because of disclosure of potentially confidential
// information . However , the class name is not confidential , which makes this a non - issue / false
// positive .
LOG . debug ( "Requesting singleton validator class instance of '" + validatorClass + "' from the validator factory" ) ; this . pwValidator = PasswordValidatorFactory . getSingleton ( validatorClass , commonProps ) ; } else { // Fortify will report a violation here because of disclosure of potentially confidential
// information . However , the class name is not confidential , which makes this a non - issue / false
// positive .
LOG . debug ( "Requesting non-singleton validator class instance of '" + validatorClass + "' from the validator factory" ) ; this . pwValidator = PasswordValidatorFactory . getInstance ( validatorClass , commonProps ) ; } } } catch ( FactoryException e ) { final String error = "The validator class cannot be instantiated. This is most likely a configuration" + " problem. Is the configured class available in the classpath?" ; LOG . error ( error , e ) ; throw new IllegalStateException ( error , e ) ; }


signature:
public class PasswordLoginModule { /** * Initialize the instance - global password authenticator object
 * @ param commonProps The parsed JAAS configuration , plus additional raw values */
private void initPwAuthenticator ( final CommonProperties commonProps ) { } }

implementation:
try { final String authNticatorClass = commonProps . getPasswordAuthenticatorClassName ( ) ; if ( authNticatorClass == null ) { final String error = "No password authenticator class has been configured in the JAAS configuration" ; LOG . error ( error ) ; throw new IllegalStateException ( error ) ; } else { if ( commonProps . isPasswordAuthenticatorSingleton ( ) ) { // Fortify will report a violation here because of disclosure of potentially confidential
// information . However , the class name is not confidential , which makes this a non - issue / false
// positive .
LOG . debug ( "Requesting singleton authenticator class instance of '" + authNticatorClass + "' from the authenticator factory" ) ; this . pwAuthenticator = PasswordAuthenticatorFactory . getSingleton ( authNticatorClass , commonProps ) ; } else { // Fortify will report a violation here because of disclosure of potentially confidential
// information . However , the class name is not confidential , which makes this a non - issue / false
// positive .
LOG . debug ( "Requesting non-singleton authenticator class instance of '" + authNticatorClass + "' from the authenticator factory" ) ; this . pwAuthenticator = PasswordAuthenticatorFactory . getInstance ( authNticatorClass , commonProps ) ; } } } catch ( FactoryException e ) { final String error = "The validator class cannot be instantiated. This is most likely a configuration" + " problem. Is the configured class available in the classpath?" ; LOG . error ( error , e ) ; throw new IllegalStateException ( error , e ) ; }


signature:
public class SrvEntitySyncHasId { /** * Synchronize entity ( that just read ) with entity in database .
 * It just check if it ' s new .
 * @ param pAddParam additional params
 * @ param pEntity object
 * @ return isNew if entity exist in database ( need update )
 * @ throws Exception - an exception */
@ Override public final boolean sync ( final Map < String , Object > pAddParam , final Object pEntity ) throws Exception { } }

implementation: Object entityPbDb = getSrvOrm ( ) . retrieveEntity ( pAddParam , pEntity ) ; return entityPbDb == null ;


signature:
public class BaseParametrizedOperation { /** * Sets the parameter using the appropriate setter method ( if present ) . */
@ Override public boolean setParam ( String name , Object value ) { } }

implementation:
String sname = "set" + name . substring ( 0 , 1 ) . toUpperCase ( ) + name . substring ( 1 ) ; Method m ; try { if ( value instanceof Integer ) { m = getClass ( ) . getMethod ( sname , int . class ) ; m . invoke ( this , value ) ; } else if ( value instanceof Double ) { try { m = getClass ( ) . getMethod ( sname , float . class ) ; m . invoke ( this , ( ( Double ) value ) . floatValue ( ) ) ; } catch ( NoSuchMethodException e ) { // no float version found , try the int version
m = getClass ( ) . getMethod ( sname , int . class ) ; m . invoke ( this , ( ( Double ) value ) . intValue ( ) ) ; } } else if ( value instanceof Float ) { try { m = getClass ( ) . getMethod ( sname , float . class ) ; m . invoke ( this , value ) ; } catch ( NoSuchMethodException e ) { // no float version found , try the int version
m = getClass ( ) . getMethod ( sname , int . class ) ; m . invoke ( this , ( ( Double ) value ) . intValue ( ) ) ; } } else if ( value instanceof Boolean ) { m = getClass ( ) . getMethod ( sname , boolean . class ) ; m . invoke ( this , value ) ; } else { m = getClass ( ) . getMethod ( sname , String . class ) ; m . invoke ( this , value . toString ( ) ) ; } return true ; } catch ( NoSuchMethodException e ) { log . warn ( "Setting unknown parameter: " + e . getMessage ( ) ) ; return false ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; return false ; } catch ( IllegalArgumentException e ) { e . printStackTrace ( ) ; return false ; } catch ( InvocationTargetException e ) { e . printStackTrace ( ) ; return false ; }


signature:
public class BaseParametrizedOperation { /** * Obtains the parameter using the appropriate getter method ( if present ) . */
@ Override public Object getParam ( String name ) { } }

implementation: String sname = "get" + name . substring ( 0 , 1 ) . toUpperCase ( ) + name . substring ( 1 ) ; try { Method m = getClass ( ) . getMethod ( sname ) ; return m . invoke ( this ) ; } catch ( NoSuchMethodException e ) { return null ; } catch ( SecurityException e ) { e . printStackTrace ( ) ; return null ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; return null ; } catch ( IllegalArgumentException e ) { e . printStackTrace ( ) ; return null ; } catch ( InvocationTargetException e ) { e . printStackTrace ( ) ; return null ; }


signature:
public class BaseSourcePropertyView { /** * Add your property controls to this panel .
 * Remember to set your own layout manager .
 * Also , remember to create a new JPanel , and pass it to the super class
 * so controls of the superclass can be included .
 * You have a 3 x 3 grid , so add three columns for each control
 * @ param panel This is the panel to add your controls to . */
public void addControlsToView ( JPanel panel ) { } }

implementation: panel . setLayout ( new BorderLayout ( ) ) ; JPanel panelMain = this . makeNewPanel ( panel , BorderLayout . CENTER ) ; panelMain . setLayout ( new GridLayout ( 3 , 2 ) ) ; panelMain . add ( new JLabel ( "Last backup: " , JLabel . RIGHT ) ) ; panelMain . add ( m_tfDate = new JTextField ( ) ) ; panelMain . add ( new JLabel ( "Filter: " , JLabel . RIGHT ) ) ; panelMain . add ( m_tfFilter = new JTextField ( ) ) ; panelMain . add ( new JPanel ( ) ) ; panelMain . add ( m_cbIncremental = new JCheckBox ( "Incremental" ) ) ; JPanel panelSub = this . makeNewPanel ( panel , BorderLayout . SOUTH ) ; super . addControlsToView ( panelSub ) ;


signature:
public class BaseSourcePropertyView { /** * Set the properties to the current control values . */
public void controlsToProperties ( ) { } }

implementation: super . controlsToProperties ( ) ; String strDate = m_tfDate . getText ( ) ; m_properties . setProperty ( BACKUPDATE_PARAM , strDate ) ; String strFilter = m_tfFilter . getText ( ) ; m_properties . setProperty ( FILTER_PARAM , strFilter ) ; boolean bSelected = m_cbIncremental . isSelected ( ) ; if ( bSelected ) m_properties . setProperty ( BACKUP_INCREMENTAL_PARAM , TRUE ) ; else m_properties . setProperty ( BACKUP_INCREMENTAL_PARAM , FALSE ) ;


signature:
public class BaseSourcePropertyView { /** * Set the properties to the current control values . */
public void propertiesToControls ( ) { } }

implementation: super . propertiesToControls ( ) ; String strDate = m_properties . getProperty ( BACKUPDATE_PARAM ) ; m_tfDate . setText ( strDate ) ; String strFilter = m_properties . getProperty ( FILTER_PARAM ) ; m_tfFilter . setText ( strFilter ) ; boolean bSelected = false ; String strSelected = m_properties . getProperty ( BACKUP_INCREMENTAL_PARAM ) ; if ( TRUE . equalsIgnoreCase ( strSelected ) ) bSelected = true ; m_cbIncremental . setSelected ( bSelected ) ;


signature:
public class LocaleUtils { /** * Returns Locale from cache . */
public static Locale getLocale ( final String language , final String country , final String variant ) { } }

implementation: LocaleInfo info = lookupLocaleInfo ( resolveLocaleCode ( language , country , variant ) ) ; return info . locale ;


signature:
public class LocaleUtils { /** * Returns Locale from cache . */
public static Locale getLocale ( final String language , final String country ) { } }

implementation: return getLocale ( language , country , null ) ;


signature:
public class LocaleUtils { /** * Returns Locale from cache where Locale may be specified also using language code .
 * Converts a locale string like " en " , " en _ US " or " en _ US _ win " to < b > new < / b > Java locale object . */
public static Locale getLocale ( final String languageCode ) { } }

implementation: LocaleInfo info = lookupLocaleInfo ( languageCode ) ; return info . locale ;


signature:
public class LocaleUtils { /** * Transforms locale data to locale code . < code > null < / code > values are allowed . */
public static String resolveLocaleCode ( final String lang , final String country , final String variant ) { } }

implementation: StringBuilder code = new StringBuilder ( lang ) ; if ( country != null && country . length ( ) > 0 ) { code . append ( '_' ) . append ( country ) ; if ( variant != null && variant . length ( ) > 0 ) { code . append ( '_' ) . append ( variant ) ; } } return code . toString ( ) ;


signature:
public class LocaleUtils { /** * Resolves locale code from locale . */
public static String resolveLocaleCode ( final Locale locale ) { } }

implementation: return resolveLocaleCode ( locale . getLanguage ( ) , locale . getCountry ( ) , locale . getVariant ( ) ) ;


signature:
public class LocaleUtils { /** * Decodes locale code in string array that can be used for < code > Locale < / code > constructor . */
public static String [ ] decodeLocaleCode ( final String localeCode ) { } }

implementation: String [ ] data = StringUtils . split ( localeCode , '_' ) ; String [ ] result = new String [ ] { data [ 0 ] , "" , "" } ; if ( data . length >= 2 ) { result [ 1 ] = data [ 1 ] ; if ( data . length >= 3 ) { result [ 2 ] = data [ 2 ] ; } } return result ;


signature:
public class LocaleUtils { /** * Returns cached < code > DateFormatSymbols < / code > instance for specified locale . */
public static DateFormatSymbols getDateFormatSymbols ( Locale locale ) { } }

implementation: LocaleInfo info = lookupLocaleInfo ( locale ) ; DateFormatSymbols dfs = info . dateFormatSymbols ; if ( dfs == null ) { dfs = new DateFormatSymbols ( locale ) ; info . dateFormatSymbols = dfs ; } return dfs ;


signature:
public class LocaleUtils { /** * Returns cached < code > NumberFormat < / code > instance for specified locale . */
public static NumberFormat getNumberFormat ( Locale locale ) { } }

implementation: LocaleInfo info = lookupLocaleInfo ( locale ) ; NumberFormat nf = info . numberFormat ; if ( nf == null ) { nf = NumberFormat . getInstance ( locale ) ; info . numberFormat = nf ; } return nf ;


signature:
public class LocaleUtils { /** * Lookups for locale info and creates new if it doesn ' t exist . */
protected static LocaleInfo lookupLocaleInfo ( final String code ) { } }

implementation: LocaleInfo info = locales . get ( code ) ; if ( info == null ) { String [ ] data = decodeLocaleCode ( code ) ; info = new LocaleInfo ( new Locale ( data [ 0 ] , data [ 1 ] , data [ 2 ] ) ) ; locales . put ( code , info ) ; } return info ;


signature:
public class JdbcLogStatement { /** * Creates a logging version of a Statement
 * @ param stmt - the statement
 * @ return - the proxy */
public static Statement getInstance ( Statement stmt ) { } }

implementation: InvocationHandler handler = new JdbcLogStatement ( stmt ) ; ClassLoader cl = Statement . class . getClassLoader ( ) ; return ( Statement ) Proxy . newProxyInstance ( cl , new Class [ ] { Statement . class } , handler ) ;


signature:
public class ArrayStack { /** * Removes all of the elements from this stack . */
public void clear ( ) { } }

implementation: int i = size ; Object [ ] els = elements ; while ( i -- > 0 ) { els [ i ] = null ; } this . size = 0 ;


signature:
public class ArrayStack { /** * Pushes an item onto the top of this stack .
 * @ param element - the element to be pushed onto this stack
 * @ return the item argument */
public T push ( T element ) { } }

implementation: int i ; Object [ ] els ; if ( ( i = size ++ ) >= ( els = elements ) . length ) { System . arraycopy ( els , 0 , els = elements = new Object [ i << 1 ] , 0 , i ) ; } els [ i ] = element ; return element ;


signature:
public class ArrayStack { /** * Removes the object at the top of this stack and returns that object as the value of this function .
 * @ return The object at the top of this stack
 * @ throws EmptyStackException - if this queue is empty */
@ SuppressWarnings ( "unchecked" ) public T pop ( ) throws EmptyStackException { } }

implementation: int i ; if ( ( i = -- size ) >= 0 ) { T element = ( T ) elements [ i ] ; elements [ i ] = null ; return element ; } else { size = 0 ; throw new EmptyStackException ( ) ; }


signature:
public class BaseSourceFile { /** * If there is no input stream , use the file to create one . */
public InputStream makeInStream ( ) { } }

implementation:
if ( m_InputStream != null ) return m_InputStream ; try { return new FileInputStream ( m_inputFile ) ; } catch ( FileNotFoundException ex ) { System . out . println ( "Warning: scanned file does not exist: " + m_inputFile . getPath ( ) ) ; // Skip this file
} return null ;