signature:
public class ClasspathUtils { /** * 根据 classLoader 获取指定 package 对应的 URLs . */
public static Collection < URL > getClasspathURLs ( ClassLoader classLoader , String packageName ) { } }

implementation: if ( packageName == null ) { throw new IllegalArgumentException ( "PackageName must be not null." ) ; } Collection < URL > urls = new ArrayList < URL > ( ) ; String dirname = packageName . replace ( '.' , '/' ) ; try { Enumeration < URL > dirs = classLoader . getResources ( dirname ) ; while ( dirs . hasMoreElements ( ) ) { urls . add ( dirs . nextElement ( ) ) ; } } catch ( IOException e ) { throw new RuntimeException ( e ) ; } return urls ;


signature:
public class PasswordAuthenticatorFactory { /** * Return a singleton , fully initialized instance of an { @ link PasswordAuthenticator } class to use for JAAS
 * authentication .
 * Retrieving a singleton by this method will cause the factory to keep state , and store a reference to the
 * singleton for later use . You may reset the factory state using the { @ code reset ( ) } method to retrieve a new
 * / different singleton the next time this method is called . .
 * Note that any properties of the singleton ( e . g . configuration ) cannot necessarily be changed easily . You may call
 * the singleton ' s { @ code init ( ) } method , but depending on the implementation provided by the respective class , this
 * may or may not have the expected effect .
 * If you need tight control over the singleton , including its lifecycle and configuration , or you require more than
 * one singleton that are different in their internal state ( e . g . with different configurations ) , then you should
 * create such objects with the { @ code getInstance ( ) } method and maintain their state as " singletons " in your
 * application ' s business logic .
 * Classes implementing the { @ link PasswordAuthenticator } interface < b > must < / b > be thread safe .
 * @ param className The name of a class that implements the PasswordAuthenticator interface
 * @ param properties The properties to initialize the instance with
 * @ return An instance of a class implementing the { @ code PasswordAuthenticator } interface
 * @ throws FactoryException When the class cannot be instantiated
 * @ throws NullPointerException When the { @ code className } or { @ code properties } are { @ code null }
 * @ throws IllegalArgumentException When { @ code className } is empty */
@ SuppressWarnings ( "PMD.NonThreadSafeSingleton" ) public static PasswordAuthenticator getSingleton ( final String className , final CommonProperties properties ) throws FactoryException { } }

implementation: Validate . notBlank ( className , "The validated character sequence 'className' is null or empty" ) ; Validate . notNull ( properties , "The validated object 'properties' is null" ) ; if ( passwordAuthenticatorInstance == null ) { synchronized ( PasswordAuthenticatorFactory . class ) { if ( passwordAuthenticatorInstance == null ) { passwordAuthenticatorInstance = getInstance ( className , properties ) ; } } } return passwordAuthenticatorInstance ;


signature:
public class ClassLoaderUtils { /** * Returns current thread ' s context class loader */
public static ClassLoader getDefault ( ) { } }

implementation: ClassLoader loader = null ; try { loader = Thread . currentThread ( ) . getContextClassLoader ( ) ; } catch ( Exception e ) { } if ( loader == null ) { loader = ClassLoaderUtils . class . getClassLoader ( ) ; if ( loader == null ) { loader = ClassLoader . getSystemClassLoader ( ) ; } } return loader ;


signature:
public class ClassLoaderUtils { /** * 使用默认的 ClassLoader 去载入类 .
 * @ return null if class not found */
public static Class < ? > loadClass ( final String qualifiedClassName , ClassLoader loader ) { } }

implementation: try { return loadClassEx ( qualifiedClassName , loader ) ; } catch ( ClassNotFoundException e ) { return null ; }


signature:
public class ClassLoaderUtils { /** * 使用指定的 ClassLoader 去载入类 .
 * @ throws ClassNotFoundException */
public static Class < ? > loadClassEx ( final String qualifiedClassName , final ClassLoader classLoader ) throws ClassNotFoundException { } }

implementation:
Validate . notNull ( qualifiedClassName , "qualifiedClassName must be not null" ) ; ClassLoader loader = ( classLoader == null ) ? getDefault ( ) : classLoader ; // 尝试基本类型
if ( abbreviationMap . containsKey ( qualifiedClassName ) ) { String className = '[' + abbreviationMap . get ( qualifiedClassName ) ; return Class . forName ( className , false , loader ) . getComponentType ( ) ; } // 尝试用 Class . forName ( )
try { String className = getCanonicalClassName ( qualifiedClassName ) ; return Class . forName ( className , false , loader ) ; } catch ( ClassNotFoundException e ) { } // 尝试当做一个内部类去识别
if ( qualifiedClassName . indexOf ( '$' ) == - 1 ) { int ipos = qualifiedClassName . lastIndexOf ( '.' ) ; if ( ipos > 0 ) { try { String className = qualifiedClassName . substring ( 0 , ipos ) + '$' + qualifiedClassName . substring ( ipos + 1 ) ; className = getCanonicalClassName ( className ) ; return Class . forName ( className , false , loader ) ; } catch ( ClassNotFoundException e ) { } } } throw new ClassNotFoundException ( qualifiedClassName ) ;


signature:
public class ClassLoaderUtils { /** * 将 Java 类名转为 { @ code Class . forName ( ) } 可以载入的类名格式 .
 * < pre >
 * getCanonicalClassName ( " int " ) = = " int " ;
 * getCanonicalClassName ( " int [ ] " ) = = " [ I " ;
 * getCanonicalClassName ( " java . lang . String " ) = = " java . lang . String " ;
 * getCanonicalClassName ( " java . lang . String [ ] " ) = = " [ Ljava . lang . String ; " ;
 * < / pre > */
public static String getCanonicalClassName ( String qualifiedClassName ) { } }

implementation: Validate . notNull ( qualifiedClassName , "qualifiedClassName must be not null" ) ; String name = StringUtils . deleteWhitespace ( qualifiedClassName ) ; if ( name . endsWith ( "[]" ) ) { StringBuilder sb = new StringBuilder ( ) ; while ( name . endsWith ( "[]" ) ) { name = name . substring ( 0 , name . length ( ) - 2 ) ; sb . append ( '[' ) ; } String abbreviation = abbreviationMap . get ( name ) ; if ( abbreviation != null ) { sb . append ( abbreviation ) ; } else { sb . append ( 'L' ) . append ( name ) . append ( ';' ) ; } name = sb . toString ( ) ; } return name ;


signature:
public class ClassLoaderUtils { /** * Finds the resource with the given name .
 * @ param name - The resource name
 * @ return A URL object for reading the resource , or null if the resource could not be found */
public static URL getResource ( String name , ClassLoader classLoader ) { } }

implementation: Validate . notNull ( name , "resourceName must be not null" ) ; if ( name . startsWith ( "/" ) ) { name = name . substring ( 1 ) ; } if ( classLoader != null ) { URL url = classLoader . getResource ( name ) ; if ( url != null ) { return url ; } } ClassLoader loader = Thread . currentThread ( ) . getContextClassLoader ( ) ; if ( loader != null && loader != classLoader ) { URL url = loader . getResource ( name ) ; if ( url != null ) { return url ; } } return ClassLoader . getSystemResource ( name ) ;


signature:
public class ClassLoaderUtils { /** * Returns an input stream for reading the specified resource . */
public static InputStream getResourceAsStream ( String name , ClassLoader classLoader ) throws IOException { } }

implementation: URL url = getResource ( name , classLoader ) ; if ( url != null ) { return url . openStream ( ) ; } return null ;


signature:
public class ClassLoaderUtils { /** * Returns an input stream for reading the specified class . */
public static InputStream getClassAsStream ( Class < ? > clazz ) throws IOException { } }

implementation: return getResourceAsStream ( getClassFileName ( clazz ) , clazz . getClassLoader ( ) ) ;


signature:
public class ClassLoaderUtils { /** * 获取一个 class 所代表的文件名 */
public static String getClassFileName ( Class < ? > clazz ) { } }

implementation: if ( clazz . isArray ( ) ) { clazz = clazz . getComponentType ( ) ; } return getClassFileName ( clazz . getName ( ) ) ;


signature:
public class URI { /** * Initialize all fields of this URI from another URI .
 * @ param p _ other the URI to copy ( cannot be null ) */
private void initialize ( URI p_other ) { } }

implementation: m_scheme = p_other . getScheme ( ) ; m_userinfo = p_other . getUserinfo ( ) ; m_host = p_other . getHost ( ) ; m_port = p_other . m_port ; n_port = p_other . n_port ; m_path = p_other . getPath ( ) ; m_queryString = p_other . getQueryString ( ) ; m_fragment = p_other . getFragment ( ) ;


signature:
public class URI { /** * Initializes this URI from a base URI and a URI specification string .
 * See RFC 2396 Section 4 and Appendix B for specifications on parsing
 * the URI and Section 5 for specifications on resolving relative URIs
 * and relative paths .
 * @ param p _ base the base URI ( may be null if p _ uriSpec is an absolute
 * URI )
 * @ param p _ uriSpec the URI spec string which may be an absolute or
 * relative URI ( can only be null / empty if p _ base
 * is not null )
 * @ exception MalformedURIException if p _ base is null and p _ uriSpec
 * is not an absolute URI or if
 * p _ uriSpec violates syntax rules */
private void initialize ( URI p_base , String p_uriSpec ) throws MalformedURIException { } }

implementation:
if ( p_base == null && ( p_uriSpec == null || p_uriSpec . length ( ) == 0 ) ) { throw new RelativeURIException ( "Cannot initialize URI with empty parameters." ) ; } // just make a copy of the base if spec is empty
if ( p_uriSpec == null || p_uriSpec . length ( ) == 0 ) { initialize ( p_base ) ; return ; } String uriSpec = p_uriSpec ; int uriSpecLen = uriSpec . length ( ) ; int index = 0 ; // Check for scheme , which must be before ' / ' , ' ? ' or ' # ' . Also handle
// names with DOS drive letters ( ' D : ' ) , so 1 - character schemes are not
// allowed .
int colonIdx = uriSpec . indexOf ( ':' ) ; int slashIdx = uriSpec . indexOf ( '/' ) ; int queryIdx = uriSpec . indexOf ( '?' ) ; int fragmentIdx = uriSpec . indexOf ( '#' ) ; if ( ( colonIdx < 2 ) || ( colonIdx > slashIdx && slashIdx != - 1 ) || ( colonIdx > queryIdx && queryIdx != - 1 ) || ( colonIdx > fragmentIdx && fragmentIdx != - 1 ) ) { // We need to do the relative URI algorithm :
// jjc : the spec says :
// ' URI - reference = [ absoluteURI | relativeURI ] [ " # " fragment ] '
// My understanding is that if there is only the fragment
// then this is a relative URI .
if ( p_base == null // del jjc : & & fragmentIdx ! = 0
) { // Nothing to be relative against .
throw new RelativeURIException ( "No scheme found in URI." + p_uriSpec ) ; } else { if ( ( ! p_base . isGenericURI ( ) ) && fragmentIdx != 0 ) // Can ' t be relative against opaque URI ( except using the # frag ) .
throw new MalformedURIException ( "Cannot apply relative URI to an opaque URI" ) ; } } else { initializeScheme ( uriSpec ) ; index = m_scheme . length ( ) + 1 ; } // two slashes means generic URI syntax , so we get the authority
if ( ( ( index + 1 ) < uriSpecLen ) && ( uriSpec . substring ( index ) . startsWith ( "//" ) ) ) { index += 2 ; int startPos = index ; // get authority - everything up to path , query or fragment
char testChar = '\0' ; while ( index < uriSpecLen ) { testChar = uriSpec . charAt ( index ) ; if ( testChar == '/' || testChar == '?' || testChar == '#' ) { break ; } index ++ ; } // if we found authority , parse it out , otherwise we set the
// host to empty string
if ( index > startPos ) { initializeAuthority ( uriSpec . substring ( startPos , index ) ) ; } else { m_host = "" ; } } initializePath ( uriSpec . substring ( index ) ) ; // Resolve relative URI to base URI - see RFC 2396 Section 5.2
// In some cases , it might make more sense to throw an exception
// ( when scheme is specified is the string spec and the base URI
// is also specified , for example ) , but we ' re just following the
// RFC specifications
if ( p_base != null ) { // check to see if this is the current doc - RFC 2396 5.2 # 2
// note that this is slightly different from the RFC spec in that
// we don ' t include the check for query string being null
// - this handles cases where the urispec is just a query
// string or a fragment ( e . g . " ? y " or " # s " ) -
// see < http : / / www . ics . uci . edu / ~ fielding / url / test1 . html > which
// identified this as a bug in the RFC
if ( m_path . length ( ) == 0 && m_scheme == null && m_host == null ) { m_scheme = p_base . getScheme ( ) ; m_userinfo = p_base . getUserinfo ( ) ; m_host = p_base . getHost ( ) ; m_port = p_base . m_port ; n_port = p_base . getPort ( ) ; m_path = p_base . getPath ( ) ; if ( m_queryString == null ) { m_queryString = p_base . getQueryString ( ) ; } return ; } // check for scheme - RFC 2396 5.2 # 3
// if we found a scheme , it means absolute URI , so we ' re done
if ( m_scheme == null ) { m_scheme = p_base . getScheme ( ) ; } else { return ; } // check for authority - RFC 2396 5.2 # 4
// if we found a host , then we ' ve got a network path , so we ' re done
if ( m_host == null ) { m_userinfo = p_base . getUserinfo ( ) ; m_host = p_base . getHost ( ) ; m_port = p_base . m_port ; n_port = p_base . getPort ( ) ; } else { return ; } // check for absolute path - RFC 2396 5.2 # 5
if ( m_path . length ( ) > 0 && m_path . startsWith ( "/" ) ) { return ; } // if we get to this point , we need to resolve relative path
// RFC 2396 5.2 # 6
String path = // jjc new String ( ) ;
"/" ; // jjc ins
String basePath = p_base . getPath ( ) ; // 6a - get all but the last segment of the base URI path
if ( basePath != null ) { int lastSlash = basePath . lastIndexOf ( '/' ) ; if ( lastSlash != - 1 ) { path = basePath . substring ( 0 , lastSlash + 1 ) ; } } // 6b - append the relative URI path
path = path . concat ( m_path ) ; // 6c - remove all " . / " where " . " is a complete path segment
index = - 1 ; while ( ( index = path . indexOf ( "/./" ) ) != - 1 ) { path = path . substring ( 0 , index + 1 ) . concat ( path . substring ( index + 3 ) ) ; } // 6d - remove " . " if path ends with " . " as a complete path segment
if ( path . endsWith ( "/." ) ) { path = path . substring ( 0 , path . length ( ) - 1 ) ; } // 6e - remove all " < segment > / . . / " where " < segment > " is a complete
// path segment not equal to " . . "
index = 1 ; int segIndex = - 1 ; while ( ( index = path . indexOf ( "/../" , index ) ) > 0 ) { segIndex = path . lastIndexOf ( '/' , index - 1 ) ; if ( segIndex != - 1 && ! path . substring ( segIndex + 1 , index ) . equals ( ".." ) ) { path = path . substring ( 0 , segIndex ) . concat ( path . substring ( index + 3 ) ) ; index = segIndex ; } else { index += 4 ; } } // 6f - remove ending " < segment > / . . " where " < segment > " is a
// complete path segment
if ( path . endsWith ( "/.." ) ) { index = path . length ( ) - 3 ; segIndex = path . lastIndexOf ( '/' , index - 1 ) ; if ( segIndex != - 1 && ! path . substring ( segIndex + 1 , index ) . equals ( ".." ) ) { path = path . substring ( 0 , segIndex + 1 ) ; } } m_path = path ; }


signature:
public class URI { /** * Initialize the scheme for this URI from a URI string spec .
 * @ param p _ uriSpec the URI specification ( cannot be null )
 * @ exception MalformedURIException if URI does not have a conformant
 * scheme */
private void initializeScheme ( String p_uriSpec ) throws MalformedURIException { } }

implementation: int uriSpecLen = p_uriSpec . length ( ) ; int index = p_uriSpec . indexOf ( ':' ) ; if ( index < 1 ) throw new MalformedURIException ( "No scheme found in URI." ) ; if ( index == uriSpecLen - 1 ) throw new MalformedURIException ( "A bare scheme name is not a URI." ) ; setScheme ( p_uriSpec . substring ( 0 , index ) ) ;


signature:
public class URI { /** * Initialize the authority ( userinfo , host and port ) for this
 * URI from a URI string spec .
 * @ param p _ uriSpec the URI specification ( cannot be null )
 * @ exception MalformedURIException if p _ uriSpec violates syntax rules */
private void initializeAuthority ( String p_uriSpec ) throws MalformedURIException { } }

implementation:
int index = 0 ; int start = 0 ; int end = p_uriSpec . length ( ) ; char testChar = '\0' ; String userinfo = null ; // userinfo is everything up @
if ( p_uriSpec . indexOf ( '@' , start ) != - 1 ) { while ( index < end ) { testChar = p_uriSpec . charAt ( index ) ; if ( testChar == '@' ) { break ; } index ++ ; } userinfo = p_uriSpec . substring ( start , index ) ; index ++ ; } // host is everything up to ' : '
String host = null ; start = index ; while ( index < end ) { testChar = p_uriSpec . charAt ( index ) ; if ( testChar == ':' ) { break ; } index ++ ; } host = p_uriSpec . substring ( start , index ) ; int port = - 1 ; if ( host . length ( ) > 0 ) { // port
if ( testChar == ':' ) { index ++ ; start = index ; while ( index < end ) { index ++ ; } String portStr = p_uriSpec . substring ( start , index ) ; if ( portStr . length ( ) > 0 ) { for ( int i = 0 ; i < portStr . length ( ) ; i ++ ) { if ( ! isDigit ( portStr . charAt ( i ) ) ) { throw new MalformedURIException ( portStr + " is invalid. Port should only contain digits!" ) ; } } try { port = Integer . parseInt ( portStr ) ; m_port = portStr ; } catch ( NumberFormatException nfe ) { // can ' t happen
} } } } setHost ( host ) ; setPort ( port ) ; setUserinfo ( userinfo ) ;


signature:
public class URI { /** * Initialize the path for this URI from a URI string spec .
 * @ param p _ uriSpec the URI specification ( cannot be null )
 * @ exception MalformedURIException if p _ uriSpec violates syntax rules */
private void initializePath ( String p_uriSpec ) throws MalformedURIException { } }

implementation:
if ( p_uriSpec == null ) { throw new MalformedURIException ( "Cannot initialize path from null string!" ) ; } int index = 0 ; int start = 0 ; int end = p_uriSpec . length ( ) ; char testChar = '\0' ; // path - everything up to query string or fragment
while ( index < end ) { testChar = p_uriSpec . charAt ( index ) ; if ( testChar == '?' || testChar == '#' ) { break ; } // check for valid escape sequence
if ( testChar == '%' ) { if ( index + 2 >= end || ! isHex ( p_uriSpec . charAt ( index + 1 ) ) || ! isHex ( p_uriSpec . charAt ( index + 2 ) ) ) { throw new MalformedURIException ( "Path contains invalid escape sequence!" ) ; } } else if ( ! isReservedCharacter ( testChar ) && ! isUnreservedCharacter ( testChar ) ) { throw new MalformedURIException ( "Path contains invalid character: " + testChar ) ; } index ++ ; } m_path = p_uriSpec . substring ( start , index ) ; // query - starts with ? and up to fragment or end
if ( testChar == '?' ) { index ++ ; start = index ; while ( index < end ) { testChar = p_uriSpec . charAt ( index ) ; if ( testChar == '#' ) { break ; } if ( testChar == '%' ) { if ( index + 2 >= end || ! isHex ( p_uriSpec . charAt ( index + 1 ) ) || ! isHex ( p_uriSpec . charAt ( index + 2 ) ) ) { throw new MalformedURIException ( "Query string contains invalid escape sequence!" ) ; } } else if ( ! isReservedCharacter ( testChar ) && ! isUnreservedCharacter ( testChar ) ) { throw new MalformedURIException ( "Query string contains invalid character:" + testChar ) ; } index ++ ; } m_queryString = p_uriSpec . substring ( start , index ) ; } // fragment - starts with #
if ( testChar == '#' ) { index ++ ; start = index ; while ( index < end ) { testChar = p_uriSpec . charAt ( index ) ; if ( testChar == '%' ) { if ( index + 2 >= end || ! isHex ( p_uriSpec . charAt ( index + 1 ) ) || ! isHex ( p_uriSpec . charAt ( index + 2 ) ) ) { throw new MalformedURIException ( "Fragment contains invalid escape sequence!" ) ; } } else if ( ! isReservedCharacter ( testChar ) && ! isUnreservedCharacter ( testChar ) ) { throw new MalformedURIException ( "Fragment contains invalid character:" + testChar ) ; } index ++ ; } m_fragment = p_uriSpec . substring ( start , index ) ; }


signature:
public class URI { /** * Get the scheme - specific part for this URI ( everything following the
 * scheme and the first colon ) . See RFC 2396 Section 5.2 for spec .
 * @ return the scheme - specific part for this URI */
public String getSchemeSpecificPart ( ) { } }

implementation: StringBuffer schemespec = new StringBuffer ( ) ; if ( m_userinfo != null || m_host != null || m_port != null ) { schemespec . append ( "//" ) ; } if ( m_userinfo != null ) { schemespec . append ( m_userinfo ) ; schemespec . append ( '@' ) ; } if ( m_host != null ) { schemespec . append ( m_host ) ; } if ( m_port != null ) { schemespec . append ( ':' ) ; schemespec . append ( m_port ) ; } if ( m_path != null ) { schemespec . append ( ( m_path ) ) ; } if ( m_queryString != null ) { schemespec . append ( '?' ) ; schemespec . append ( m_queryString ) ; } if ( m_fragment != null ) { schemespec . append ( '#' ) ; schemespec . append ( m_fragment ) ; } return schemespec . toString ( ) ;


signature:
public class URI { /** * Set the scheme for this URI . The scheme is converted to lowercase
 * before it is set .
 * @ param p _ scheme the scheme for this URI ( cannot be null )
 * @ exception MalformedURIException if p _ scheme is not a conformant
 * scheme name */
private void setScheme ( String p_scheme ) throws MalformedURIException { } }

implementation: if ( p_scheme == null ) { throw new MalformedURIException ( "Cannot set scheme from null string!" ) ; } if ( ! isConformantSchemeName ( p_scheme ) ) { throw new MalformedURIException ( "The scheme is not conformant." ) ; } m_scheme = p_scheme ; // . toLowerCase ( ) ;


signature:
public class URI { /** * Set the userinfo for this URI . If a non - null value is passed in and
 * the host value is null , then an exception is thrown .
 * @ param p _ userinfo the userinfo for this URI
 * @ exception MalformedURIException if p _ userinfo contains invalid
 * characters */
private void setUserinfo ( String p_userinfo ) throws MalformedURIException { } }

implementation:
if ( p_userinfo == null ) { m_userinfo = null ; } else { if ( m_host == null ) { throw new MalformedURIException ( "Userinfo cannot be set when host is null!" ) ; } // userinfo can contain alphanumerics , mark characters , escaped
// and ' ; ' , ' : ' , ' & ' , ' = ' , ' + ' , ' $ ' , ' , '
int index = 0 ; int end = p_userinfo . length ( ) ; char testChar = '\0' ; while ( index < end ) { testChar = p_userinfo . charAt ( index ) ; if ( testChar == '%' ) { if ( index + 2 >= end || ! isHex ( p_userinfo . charAt ( index + 1 ) ) || ! isHex ( p_userinfo . charAt ( index + 2 ) ) ) { throw new MalformedURIException ( "Userinfo contains invalid escape sequence!" ) ; } } else if ( ! isUnreservedCharacter ( testChar ) && USERINFO_CHARACTERS . indexOf ( testChar ) == - 1 ) { throw new MalformedURIException ( "Userinfo contains invalid character:" + testChar ) ; } index ++ ; } } m_userinfo = p_userinfo ;


signature:
public class URI { /** * Set the host for this URI . If null is passed in , the userinfo
 * field is also set to null and the port is set to - 1.
 * @ param p _ host the host for this URI
 * @ exception MalformedURIException if p _ host is not a valid IP
 * address or DNS hostname . */
private void setHost ( String p_host ) throws MalformedURIException { } }

implementation: if ( p_host == null || p_host . length ( ) == 0 ) { m_host = p_host ; m_userinfo = null ; m_port = null ; n_port = - 1 ; } else if ( ! isWellFormedAddress ( p_host ) ) { throw new MalformedURIException ( "Host is not a well formed address!" ) ; } m_host = p_host ;


signature:
public class URI { /** * Set the port for this URI . - 1 is used to indicate that the port is
 * not specified , otherwise valid port numbers are between 0 and 65535.
 * If a valid port number is passed in and the host field is null ,
 * an exception is thrown .
 * @ param p _ port the port number for this URI
 * @ exception MalformedURIException if p _ port is not - 1 and not a
 * valid port number */
private void setPort ( int p_port ) throws MalformedURIException { } }

implementation: if ( p_port >= 0 && p_port <= 65535 ) { if ( m_host == null ) { throw new MalformedURIException ( "Port cannot be set when host is null!" ) ; } } else if ( p_port != - 1 ) { throw new MalformedURIException ( "Invalid port number!" ) ; } n_port = p_port ;


signature:
public class URI { /** * Set the path for this URI . If the supplied path is null , then the
 * query string and fragment are set to null as well . If the supplied
 * path includes a query string and / or fragment , these fields will be
 * parsed and set as well . Note that , for URIs following the " generic
 * URI " syntax , the path specified should start with a slash .
 * For URIs that do not follow the generic URI syntax , this method
 * sets the scheme - specific part .
 * @ param p _ path the path for this URI ( may be null )
 * @ exception MalformedURIException if p _ path contains invalid
 * characters */
private void setPath ( String p_path ) throws MalformedURIException { } }

implementation: if ( p_path == null ) { m_path = null ; m_queryString = null ; m_fragment = null ; } else { initializePath ( p_path ) ; }


signature:
public class URI { /** * Append to the end of the path of this URI . If the current path does
 * not end in a slash and the path to be appended does not begin with
 * a slash , a slash will be appended to the current path before the
 * new segment is added . Also , if the current path ends in a slash
 * and the new segment begins with a slash , the extra slash will be
 * removed before the new segment is appended .
 * @ param p _ addToPath the new segment to be added to the current path
 * @ exception MalformedURIException if p _ addToPath contains syntax
 * errors */
private void appendPath ( String p_addToPath ) throws MalformedURIException { } }

implementation: if ( p_addToPath == null || p_addToPath . length ( ) == 0 ) { return ; } if ( ! isURIString ( p_addToPath ) ) { throw new MalformedURIException ( "Path contains invalid character!" ) ; } if ( m_path == null || m_path . length ( ) == 0 ) { if ( p_addToPath . startsWith ( "/" ) ) { m_path = p_addToPath ; } else { m_path = "/" + p_addToPath ; } } else if ( m_path . endsWith ( "/" ) ) { if ( p_addToPath . startsWith ( "/" ) ) { m_path = m_path . concat ( p_addToPath . substring ( 1 ) ) ; } else { m_path = m_path . concat ( p_addToPath ) ; } } else { if ( p_addToPath . startsWith ( "/" ) ) { m_path = m_path . concat ( p_addToPath ) ; } else { m_path = m_path . concat ( "/" + p_addToPath ) ; } }


signature:
public class URI { /** * Set the query string for this URI . A non - null value is valid only
 * if this is an URI conforming to the generic URI syntax and
 * the path value is not null .
 * @ param p _ queryString the query string for this URI
 * @ exception MalformedURIException if p _ queryString is not null and this
 * URI does not conform to the generic
 * URI syntax or if the path is null */
private void setQueryString ( String p_queryString ) throws MalformedURIException { } }

implementation: if ( p_queryString == null ) { m_queryString = null ; } else if ( ! isGenericURI ( ) ) { throw new MalformedURIException ( "Query string can only be set for a generic URI!" ) ; } else if ( getPath ( ) == null ) { throw new MalformedURIException ( "Query string cannot be set when path is null!" ) ; } else if ( ! isURIString ( p_queryString ) ) { throw new MalformedURIException ( "Query string contains invalid character!" ) ; } else { m_queryString = p_queryString ; }


signature:
public class URI { /** * Set the fragment for this URI . A non - null value is valid only
 * if this is a URI conforming to the generic URI syntax and
 * the path value is not null .
 * @ param p _ fragment the fragment for this URI
 * @ exception MalformedURIException if p _ fragment is not null and this
 * URI does not conform to the generic
 * URI syntax or if the path is null */
public void setFragment ( String p_fragment ) throws MalformedURIException { } }

implementation: if ( p_fragment == null ) { m_fragment = null ; } else if ( ! isGenericURI ( ) ) { throw new MalformedURIException ( "Fragment can only be set for a generic URI!" ) ; } else if ( getPath ( ) == null ) { throw new MalformedURIException ( "Fragment cannot be set when path is null!" ) ; } else if ( ! isURIString ( p_fragment ) ) { throw new MalformedURIException ( "Fragment contains invalid character!" ) ; } else { m_fragment = p_fragment ; }


signature:
public class URI { /** * Get the URI as a string specification . See RFC 2396 Section 5.2.
 * @ return the URI string specification */
public String getURIString ( ) { } }

implementation: StringBuffer uriSpecString = new StringBuffer ( ) ; if ( m_scheme != null ) { uriSpecString . append ( m_scheme ) ; uriSpecString . append ( ':' ) ; } uriSpecString . append ( getSchemeSpecificPart ( ) ) ; return uriSpecString . toString ( ) ;


signature:
public class URI { /** * Determine whether a string is syntactically capable of representing
 * a valid IPv4 address or the domain name of a network host . A valid
 * IPv4 address consists of four decimal digit groups separated by a
 * ' . ' . A hostname consists of domain labels ( each of which must
 * begin and end with an alphanumeric but may contain ' - ' ) separated
 * & by a ' . ' . See RFC 2396 Section 3.2.2.
 * @ return true if the string is a syntactically valid IPv4 address
 * or hostname */
public static boolean isWellFormedAddress ( String p_address ) { } }

implementation:
if ( p_address == null ) { return false ; } String address = p_address ; int addrLength = address . length ( ) ; if ( addrLength == 0 || addrLength > 255 ) { return false ; } if ( address . startsWith ( "." ) || address . startsWith ( "-" ) ) { return false ; } // rightmost domain label starting with digit indicates IP address
// since top level domain label can only start with an alpha
// see RFC 2396 Section 3.2.2
int index = address . lastIndexOf ( '.' ) ; if ( address . endsWith ( "." ) ) { index = address . substring ( 0 , index ) . lastIndexOf ( '.' ) ; } if ( index + 1 < addrLength && isDigit ( p_address . charAt ( index + 1 ) ) ) { char testChar ; int numDots = 0 ; // make sure that 1 ) we see only digits and dot separators , 2 ) that
// any dot separator is preceded and followed by a digit and
// 3 ) that we find 3 dots
for ( int i = 0 ; i < addrLength ; i ++ ) { testChar = address . charAt ( i ) ; if ( testChar == '.' ) { if ( ! isDigit ( address . charAt ( i - 1 ) ) || ( i + 1 < addrLength && ! isDigit ( address . charAt ( i + 1 ) ) ) ) { return false ; } numDots ++ ; } else if ( ! isDigit ( testChar ) ) { return false ; } } if ( numDots != 3 ) { return false ; } } else { // domain labels can contain alphanumerics and ' - "
// but must start and end with an alphanumeric
char testChar ; for ( int i = 0 ; i < addrLength ; i ++ ) { testChar = address . charAt ( i ) ; if ( testChar == '.' ) { if ( ! isAlphanum ( address . charAt ( i - 1 ) ) ) { return false ; } if ( i + 1 < addrLength && ! isAlphanum ( address . charAt ( i + 1 ) ) ) { return false ; } } else if ( ! isAlphanum ( testChar ) && testChar != '-' ) { return false ; } } } return true ;


signature:
public class Base64 { /** * - - - - - byte */
public static byte [ ] encodeToByte ( String s ) { } }

implementation: try { return encodeToByte ( s . getBytes ( ENCODING ) , false ) ; } catch ( UnsupportedEncodingException ignore ) { return null ; }


signature:
public class Base64 { /** * - - - - - string */
public static String encodeToString ( String s ) { } }

implementation: try { return new String ( encodeToChar ( s . getBytes ( ENCODING ) , false ) ) ; } catch ( UnsupportedEncodingException ignore ) { return null ; }


signature:
public class SrvFieldWriterXmlStd { /** * Write standard field of entity into a stream
 * ( writer - file or pass it through network ) .
 * @ param pAddParam additional params ( e . g . exclude fields set )
 * @ param pField value
 * @ param pFieldName Field Name
 * @ param pWriter writer
 * @ throws Exception - an exception */
@ Override public final void write ( final Map < String , Object > pAddParam , final Object pField , final String pFieldName , final Writer pWriter ) throws Exception { } }

implementation: String fieldValue ; if ( pField == null ) { fieldValue = "NULL" ; } else if ( Enum . class . isAssignableFrom ( pField . getClass ( ) ) ) { fieldValue = String . valueOf ( ( ( Enum ) pField ) . ordinal ( ) ) ; } else if ( pField . getClass ( ) == Date . class ) { fieldValue = String . valueOf ( ( ( Date ) pField ) . getTime ( ) ) ; } else { fieldValue = pField . toString ( ) ; if ( pField instanceof String ) { fieldValue = getUtilXml ( ) . escapeXml ( fieldValue ) ; } } pWriter . write ( " " + pFieldName + "=\"" + fieldValue + "\"\n" ) ;


signature:
public class PreparedStatementCreator { /** * Support ? as parameter */
protected static PreparedStatement createByIterator ( Connection conn , String sql , Iterator < ? > parameters ) throws SQLException { } }

implementation: PreparedStatement ps = conn . prepareStatement ( sql ) ; if ( parameters != null ) { int index = 1 ; while ( parameters . hasNext ( ) ) { Object parameter = parameters . next ( ) ; if ( parameter == null ) { ps . setObject ( index , null ) ; } else { ps . setObject ( index , parameter ) ; } index ++ ; } } return ps ;


signature:
public class PreparedStatementCreator { /** * Support : name as parameter , and Array or Collection type */
protected static PreparedStatement createByMap ( Connection conn , String sql , Map < String , ? > parameters ) throws SQLException { } }

implementation: StringBuffer sb = new StringBuffer ( ) ; List < Object > params = new ArrayList < Object > ( ) ; Matcher m = namedParameterPattern . matcher ( sql ) ; while ( m . find ( ) ) { String key = m . group ( 1 ) ; Object value = parameters . get ( key ) ; if ( value == null ) { params . add ( null ) ; m . appendReplacement ( sb , "?" ) ; } else if ( value instanceof Object [ ] ) { Object [ ] array = ( Object [ ] ) value ; if ( array . length == 0 ) { params . add ( null ) ; m . appendReplacement ( sb , "?" ) ; } else { for ( Object one : array ) { params . add ( one ) ; } m . appendReplacement ( sb , StringUtils . repeat ( "?" , "," , array . length ) ) ; } } else if ( value instanceof Collection ) { Collection < ? > collection = ( Collection < ? > ) value ; if ( collection . size ( ) == 0 ) { params . add ( null ) ; m . appendReplacement ( sb , "?" ) ; } else { for ( Object one : collection ) { params . add ( one ) ; } m . appendReplacement ( sb , StringUtils . repeat ( "?" , "," , collection . size ( ) ) ) ; } } else { params . add ( value ) ; m . appendReplacement ( sb , "?" ) ; } } m . appendTail ( sb ) ; return createByIterator ( conn , sb . toString ( ) , params . iterator ( ) ) ;


signature:
public class MuffinManager { /** * Creates new MuffinManager .
 * @ param applet The parent object ( ignored ) . */
public void init ( Object applet ) { } }

implementation: try { m_ps = ( PersistenceService ) ServiceManager . lookup ( "javax.jnlp.PersistenceService" ) ; m_bs = ( BasicService ) ServiceManager . lookup ( "javax.jnlp.BasicService" ) ; m_strCodeBase = m_bs . getCodeBase ( ) . toString ( ) ; } catch ( UnavailableServiceException e ) { m_ps = null ; m_bs = null ; }


signature:
public class MuffinManager { /** * Get the current value for this muffin .
 * @ param strParam The key for this muffin parameter .
 * @ return The value for this muffin ( null if none ) . */
public String getMuffin ( String strParam ) { } }

implementation:
try { URL url = new URL ( m_strCodeBase + strParam ) ; FileContents fc = m_ps . get ( url ) ; if ( fc == null ) return null ; // read in the contents of a muffin
byte [ ] buf = new byte [ ( int ) fc . getLength ( ) ] ; InputStream is = fc . getInputStream ( ) ; int pos = 0 ; while ( ( pos = is . read ( buf , pos , buf . length - pos ) ) > 0 ) { // just loop
} is . close ( ) ; String strValue = new String ( buf , ENCODING ) ; return strValue ; } catch ( Exception ex ) { // Return null for any exception
} return null ;


signature:
public class MuffinManager { /** * Set the current value for this muffin .
 * @ param strParam The key for this muffin parameter .
 * @ param strValue The value for this muffin . */
public void setMuffin ( String strParam , String strValue ) { } }

implementation:
FileContents fc = null ; URL url = null ; try { url = new URL ( m_strCodeBase + strParam ) ; } catch ( Exception ex ) { return ; } try { fc = m_ps . get ( url ) ; fc . getMaxLength ( ) ; // This will throw an exception if there is no muffin yet .
} catch ( Exception ex ) { fc = null ; } try { if ( fc == null ) { m_ps . create ( url , 100 ) ; fc = m_ps . get ( url ) ; } // don ' t append
if ( strValue != null ) { OutputStream os = fc . getOutputStream ( false ) ; byte [ ] buf = strValue . getBytes ( ENCODING ) ; os . write ( buf ) ; os . close ( ) ; m_ps . setTag ( url , PersistenceService . DIRTY ) ; } else m_ps . delete ( url ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; // Return null for any exception
}


signature:
public class MuffinManager { /** * Get data from the system clipboard .
 * @ return */
public Transferable getClipboardContents ( ) { } }

implementation:
if ( ( clipboardReadStatus & CLIPBOARD_DISABLED ) == CLIPBOARD_DISABLED ) return null ; // Rejected it last time , don ' t ask again
clipboardReadStatus = CLIPBOARD_DISABLED ; if ( cs == null ) { try { cs = ( ClipboardService ) ServiceManager . lookup ( "javax.jnlp.ClipboardService" ) ; } catch ( UnavailableServiceException e ) { cs = null ; } } if ( cs != null ) { // get the contents of the system clipboard and print them
Transferable tr = cs . getContents ( ) ; if ( tr != null ) clipboardReadStatus = CLIPBOARD_ENABLED ; return tr ; } return null ;


signature:
public class MuffinManager { /** * Set the global clipboard contents .
 * @ param data */
public boolean setClipboardContents ( Transferable data ) { } }

implementation:
if ( data == null ) return false ; if ( ( clipboardWriteStatus & CLIPBOARD_DISABLED ) == CLIPBOARD_DISABLED ) return false ; // Rejected it last time , don ' t ask again
clipboardWriteStatus = CLIPBOARD_ENABLED ; if ( cs == null ) { try { cs = ( ClipboardService ) ServiceManager . lookup ( "javax.jnlp.ClipboardService" ) ; } catch ( UnavailableServiceException e ) { cs = null ; } } if ( cs != null ) { // set the system clipboard contents to a string selection
try { cs . setContents ( data ) ; clipboardWriteStatus = CLIPBOARD_ENABLED ; return true ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } return false ;


signature:
public class MuffinManager { /** * Replace the clipboard cut / cut / paste command with this command .
 * @ param component
 * @ param actionName
 * @ return */
public boolean replaceClipboardAction ( JComponent component , String actionName ) { } }

implementation: Action action = ( Action ) component . getActionMap ( ) . get ( actionName ) ; if ( action != null ) component . getActionMap ( ) . put ( actionName , new LinkedClipboardAction ( actionName , action ) ) ; return ( action != null ) ;


signature:
public class MuffinManager { /** * Open this file .
 * @ return */
public InputStream openFileStream ( String pathHint , String [ ] extensions ) { } }

implementation:
if ( fos == null ) { try { fos = ( FileOpenService ) ServiceManager . lookup ( "javax.jnlp.FileOpenService" ) ; } catch ( UnavailableServiceException e ) { fos = null ; } } if ( fos != null ) { try { // ask user to select a file through this service
FileContents fc = fos . openFileDialog ( pathHint , extensions ) ; return fc . getInputStream ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } return null ;


signature:
public class ServiceManager { /** * Discovers the registered services of the given class .
 * @ param clazz the class of the required services
 * @ return A map that maps the services to their identifiers */
public static < T extends Service > Map < String , T > loadServicesByType ( Class < T > clazz ) { } }

implementation: ServiceLoader < T > loader = ServiceLoader . load ( clazz ) ; Iterator < T > it = loader . iterator ( ) ; Map < String , T > ret = new HashMap < String , T > ( ) ; while ( it . hasNext ( ) ) { T op = it . next ( ) ; ret . put ( op . getId ( ) , op ) ; if ( op instanceof ParametrizedOperation ) addParametrizedService ( op . getId ( ) , ( ParametrizedOperation ) op ) ; if ( op instanceof ScriptObject ) addScriptObject ( ( ( ScriptObject ) op ) . getVarName ( ) , ( ScriptObject ) op ) ; } return ret ;


signature:
public class ServiceManager { /** * Sets the operation parametres based on a map of values .
 * @ param op The operation whose parametres should be set
 * @ param params A map that assigns values to parameter names */
public static void setServiceParams ( ParametrizedOperation op , Map < String , Object > params ) { } }

implementation: if ( params != null ) { for ( Map . Entry < String , Object > entry : params . entrySet ( ) ) { op . setParam ( entry . getKey ( ) , entry . getValue ( ) ) ; } }


signature:
public class ServiceManager { /** * Obtains the values of all the parametres of the given operation .
 * @ param op The operation whose parametres should be set
 * @ return A map that assigns values to parameter names */
public static Map < String , Object > getServiceParams ( ParametrizedOperation op ) { } }

implementation: Map < String , Object > ret = new HashMap < String , Object > ( ) ; for ( Parameter param : op . getParams ( ) ) { ret . put ( param . getName ( ) , op . getParam ( param . getName ( ) ) ) ; } return ret ;


signature:
public class ServiceManager { /** * Finds a parametrized service based on its ID .
 * @ param id the service ID .
 * @ return the parametrized operation object or { @ code null } when the service does not exist . */
public static ParametrizedOperation findParmetrizedService ( String id ) { } }

implementation: if ( parametrizedServices == null ) return null ; else return parametrizedServices . get ( id ) ;


signature:
public class ServiceManager { /** * Finds a service in a collection of services based on its class .
 * @ param services the collection of services to scan
 * @ param clazz the required class of the service
 * @ return the fisrt service in the collection that is instance of the given class or { @ code null } when
 * no such servise is present in the collection . */
public static < T > T findByClass ( Collection < ? > services , Class < T > clazz ) { } }

implementation: for ( Object serv : services ) { if ( clazz . isInstance ( serv ) ) return clazz . cast ( serv ) ; } return null ;


signature:
public class CubeSensorsApiV1 { /** * Rebuilds the { @ code service } object with debug turned on ( defaulted to { @ code System . out } ) */
public static void debug ( ) { } }

implementation: service = new ServiceBuilder ( ) . debug ( ) . provider ( CubeSensorsAuthApi . class ) . apiKey ( CubeSensorsProperties . getAppKey ( ) ) . apiSecret ( CubeSensorsProperties . getAppSecret ( ) ) . signatureType ( SignatureType . QueryString ) . build ( ) ;


signature:
public class CubeSensorsApiV1 { /** * Parses the results of a query and handles any errors . */
private < T > T parseQuery ( final String response , final Class < T > responseClass ) { } }

implementation:
T queryResponse ; try { /* * Possible exceptions :
 * IOException - if the underlying input source has problems during parsing
 * JsonParseException - if parser has problems parsing content
 * JsonMappingException - if the parser does not have any more content to map ( note : Json " null " value is considered content ; enf - of - stream not ) */
queryResponse = MAPPER . readValue ( response , responseClass ) ; } catch ( JsonParseException | JsonMappingException e ) { try { final ErrorResponse error = MAPPER . readValue ( response , ErrorResponse . class ) ; LOGGER . error ( "Query returned an error: {}" , error ) ; return null ; } catch ( final IOException e1 ) { LOGGER . error ( "Failed to read error response." , e1 ) ; } LOGGER . error ( "Error reading response." , e ) ; return null ; } catch ( final IOException e ) { LOGGER . error ( "Error reading response." , e ) ; return null ; } return queryResponse ;


signature:
public class CubeSensorsApiV1 { /** * Converts the { @ link JsonDevice } object into a { @ link Device } and logs any missing / extra fields to debug . */
private Device extractDevice ( final JsonDevice device ) { } }

implementation: final Map < ExtraMapping , String > extras = new EnumMap < > ( ExtraMapping . class ) ; final Set < String > keys = new HashSet < > ( device . extra . keySet ( ) ) ; for ( final ExtraMapping extra : ExtraMapping . values ( ) ) { extras . put ( extra , device . extra . get ( extra . name ( ) ) ) ; if ( keys . contains ( extra . name ( ) ) ) { keys . remove ( extra . name ( ) ) ; } else { LOGGER . debug ( "\"extra\" missing key \"{}\": {}" , extra . name ( ) , device . extra . toString ( ) ) ; } } for ( final String key : keys ) { LOGGER . debug ( "Unexpected key in \"extra\": {}" , key ) ; } return new Device ( device , extras ) ;


signature:
public class CubeSensorsApiV1 { /** * Queries for a list of states over the time span specified . Leaving a field { @ code null } will default to the API defaults .
 * @ param uid
 * the UID of the device to request data for
 * @ param start
 * the query start time
 * @ param end
 * the query end time
 * @ param resolution
 * the resolution in minutes
 * @ return a list of all states returned by the API
 * @ throws CubeSensorsException
 * when a request fails */
public List < State > getSpan ( final String uid , final ZonedDateTime start , final ZonedDateTime end , final Integer resolution ) { } }

implementation: final String queryUrl = RESOURCES_ROOT + DEVICES_PATH + uid + "/span" ; LOGGER . trace ( "Querying: {}" , queryUrl ) ; final OAuthRequest request = new OAuthRequest ( Verb . GET , queryUrl ) ; request . getHeaders ( ) . put ( HTTP_HEADER_ACCEPT , MEDIA_TYPE_APPLICATION_JSON ) ; if ( start != null ) { final ZonedDateTime startUtc = start . withZoneSameInstant ( ZoneId . of ( "Z" ) ) . truncatedTo ( ChronoUnit . SECONDS ) ; request . addQuerystringParameter ( "start" , startUtc . toString ( ) ) ; LOGGER . trace ( "Adding querystring parameter {}={}" , "start" , startUtc ) ; } if ( end != null ) { final ZonedDateTime endUtc = end . withZoneSameInstant ( ZoneId . of ( "Z" ) ) . truncatedTo ( ChronoUnit . SECONDS ) ; request . addQuerystringParameter ( "end" , endUtc . toString ( ) ) ; LOGGER . trace ( "Adding querystring parameter {}={}" , "end" , endUtc ) ; } if ( resolution != null ) { request . addQuerystringParameter ( "resolution" , resolution . toString ( ) ) ; LOGGER . trace ( "Adding querystring parameter {}={}" , "resolution" , resolution ) ; } service . signRequest ( accessToken , request ) ; final Response response = request . send ( ) ; LOGGER . trace ( "Response: {}" , response . getBody ( ) ) ; if ( ! response . isSuccessful ( ) ) { throw new CubeSensorsException ( response . getBody ( ) ) ; } final JsonSpanResponse queryResponse = parseQuery ( response . getBody ( ) , JsonSpanResponse . class ) ; if ( queryResponse == null ) { return new ArrayList < > ( ) ; } final List < State > states = StateParser . parseState ( queryResponse . fieldList , queryResponse . results ) ; LOGGER . debug ( "Retrieved {} states." , states . size ( ) ) ; return states ;


signature:
public class FastBuffer { /** * Prepares next chunk to match new size .
 * The minimal length of new chunk is < code > minChunkLen < / code > . */
private void needNewBuffer ( int newSize ) { } }

implementation:
int delta = newSize - size ; int newBufferSize = Math . max ( minChunkLen , delta ) ; currentBufferIndex ++ ; currentBuffer = ( E [ ] ) new Object [ newBufferSize ] ; offset = 0 ; // add buffer
if ( currentBufferIndex >= buffers . length ) { int newLen = buffers . length << 1 ; E [ ] [ ] newBuffers = ( E [ ] [ ] ) new Object [ newLen ] [ ] ; System . arraycopy ( buffers , 0 , newBuffers , 0 , buffers . length ) ; buffers = newBuffers ; } buffers [ currentBufferIndex ] = currentBuffer ; buffersCount ++ ;


signature:
public class FastBuffer { /** * Appends single < code > E < / code > to buffer . */
public FastBuffer < E > append ( E element ) { } }

implementation: if ( ( currentBuffer == null ) || ( offset == currentBuffer . length ) ) { needNewBuffer ( size + 1 ) ; } currentBuffer [ offset ] = element ; offset ++ ; size ++ ; return this ;


signature:
public class FastBuffer { /** * Appends another fast buffer to this one . */
public FastBuffer < E > append ( FastBuffer < E > buff ) { } }

implementation: if ( buff . size == 0 ) { return this ; } for ( int i = 0 ; i < buff . currentBufferIndex ; i ++ ) { append ( buff . buffers [ i ] ) ; } append ( buff . currentBuffer , 0 , buff . offset ) ; return this ;


signature:
public class FastBuffer { /** * Creates < code > E < / code > array from buffered content . */
public E [ ] toArray ( ) { } }

implementation: int pos = 0 ; E [ ] array = ( E [ ] ) new Object [ size ] ; if ( currentBufferIndex == - 1 ) { return array ; } for ( int i = 0 ; i < currentBufferIndex ; i ++ ) { int len = buffers [ i ] . length ; System . arraycopy ( buffers [ i ] , 0 , array , pos , len ) ; pos += len ; } System . arraycopy ( buffers [ currentBufferIndex ] , 0 , array , pos , offset ) ; return array ;


signature:
public class FastBuffer { /** * Returns an iterator over buffer elements . */
@ Override public Iterator < E > iterator ( ) { } }

implementation:
return new Iterator < E > ( ) { int iteratorIndex ; int iteratorBufferIndex ; int iteratorOffset ; @ Override public boolean hasNext ( ) { return iteratorIndex < size ; } @ Override public E next ( ) { if ( iteratorIndex >= size ) { throw new NoSuchElementException ( ) ; } E [ ] buf = buffers [ iteratorBufferIndex ] ; E result = buf [ iteratorOffset ] ; // increment
iteratorIndex ++ ; iteratorOffset ++ ; if ( iteratorOffset >= buf . length ) { iteratorOffset = 0 ; iteratorBufferIndex ++ ; } return result ; } @ Override public void remove ( ) { throw new UnsupportedOperationException ( ) ; } } ;


signature:
public class XmlUtil { /** * Format xml { @ link OutputFormat # createPrettyPrint ( ) }
 * @ param xmlStr xml String
 * @ param enc encoding
 * @ return pretty String */
public static String formatPretty ( String xmlStr , String enc ) { } }

implementation: return formatPretty ( xmlStr , enc , false ) ;


signature:
public class XmlUtil { /** * Format xml { @ link OutputFormat # createPrettyPrint ( ) }
 * @ param xmlStr xml String
 * @ param enc encoding
 * @ param isSuppressDeclaration set supperss declaration
 * @ return pretty String */
public static String formatPretty ( String xmlStr , String enc , boolean isSuppressDeclaration ) { } }

implementation: if ( CommUtil . isBlank ( xmlStr ) ) return xmlStr ; if ( enc == null ) enc = ENCODING ; OutputFormat formater = OutputFormat . createPrettyPrint ( ) ; formater . setEncoding ( enc ) ; formater . setSuppressDeclaration ( isSuppressDeclaration ) ; return format ( xmlStr , formater ) ;


signature:
public class XmlUtil { /** * Format xml { @ link OutputFormat # createCompactFormat ( ) }
 * @ param xmlStr xml String
 * @ param enc encoding
 * @ return Compact xml String */
public static String formatCompact ( String xmlStr , String enc ) { } }

implementation: return formatCompact ( xmlStr , enc , false ) ;


signature:
public class XmlUtil { /** * Format xml { @ link OutputFormat # createCompactFormat ( ) }
 * @ param xmlStr xml String
 * @ param enc encoding
 * @ param isSuppressDeclaration set supperss declaration
 * @ return Compact xml String */
public static String formatCompact ( String xmlStr , String enc , boolean isSuppressDeclaration ) { } }

implementation: if ( CommUtil . isBlank ( xmlStr ) ) return xmlStr ; if ( enc == null ) enc = ENCODING ; OutputFormat formater = OutputFormat . createCompactFormat ( ) ; formater . setEncoding ( enc ) ; formater . setSuppressDeclaration ( isSuppressDeclaration ) ; return format ( xmlStr , formater ) ;


signature:
public class XmlUtil { /** * Format xml
 * @ param xmlStr xml String
 * @ param formater { @ link OutputFormat }
 * @ return format String */
public static String format ( String xmlStr , OutputFormat formater ) { } }

implementation: if ( CommUtil . isBlank ( xmlStr ) ) return xmlStr ; SAXReader reader = new SAXReader ( ) ; StringReader sr = new StringReader ( xmlStr ) ; Document doc ; XMLWriter writer = null ; StringWriter sw = new StringWriter ( ) ; try { doc = reader . read ( sr ) ; writer = new XMLWriter ( sw , formater ) ; writer . write ( doc ) ; return sw . toString ( ) ; } catch ( DocumentException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } catch ( IOException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } finally { if ( writer != null ) { try { writer . close ( ) ; } catch ( IOException ignored ) { } } } return xmlStr ;


signature:
public class XmlUtil { /** * Obtain xml file encoding attribute
 * @ param xmlStr xml String
 * @ return encoding value */
public static String getEncoding ( String xmlStr ) { } }

implementation: String result ; String xml = xmlStr . trim ( ) ; if ( xml . startsWith ( "<?xml" ) ) { int end = xml . indexOf ( "?>" ) ; int encIndex = xml . indexOf ( "encoding=" ) ; if ( encIndex != - 1 ) { String sub = xml . substring ( encIndex + 9 , end ) ; result = CommUtil . substringBetween ( sub , "\"" , "\"" ) ; return result ; } } return null ;


signature:
public class XmlUtil { /** * Bean to xml .
 * Using XStream library from serialize objects to XML .
 * example :
 * < pre >
 * XAlias [ ] xa = { new XAlias ( " Foo " , Foo . class ) } ;
 * XAliasField [ ] xaf = { new XAliasField ( " Bar " , Bar . class , " bar " ) } ;
 * XAliasAttribute [ ] xaa = { new XAliasAttribute ( " Name " , User . class , " name " ) } ;
 * XOmitField [ ] xf = { new XOmitField ( V . class , " v " ) }
 * then ,
 * toXml ( bean , xa , xaf , xaa , xf ) ;
 * < / pre > < b > Note : XStream Mode is { @ link XStream # NO _ REFERENCES } < / b >
 * @ param obj bean
 * @ param xAlias Alias a Class to a shorter name to be used in XML elements .
 * @ param xAliasFields Create an alias for a field name .
 * @ param xAliasAttributes Create an alias for an attribute .
 * @ param xOmitFields Prevents a field from being serialized .
 * @ param < T > obj
 * @ return xml String
 * @ since XSTREAM 1.4.5 */
public static < T > String toXml ( T obj , XAlias [ ] xAlias , XAliasField [ ] xAliasFields , XAliasAttribute [ ] xAliasAttributes , XOmitField [ ] xOmitFields ) { } }

implementation: return toXml ( obj , xAlias , xAliasFields , xAliasAttributes , xOmitFields , null , null , null ) ;


signature:
public class XmlUtil { /** * Bean to xml .
 * Using XStream library from serialize objects to XML .
 * example :
 * < pre >
 * XAlias [ ] xa = { new XAlias ( " Foo " , Foo . class ) } ;
 * XAliasField [ ] xaf = { new XAliasField ( " Bar " , Bar . class , " bar " ) } ;
 * XAliasAttribute [ ] xaa = { new XAliasAttribute ( " Name " , User . class , " name " ) } ;
 * XOmitField [ ] xf = { new XOmitField ( V . class , " v " ) }
 * XImplicitCollection [ ] xic = null ;
 * XImmutableType [ ] xit = null ;
 * XConverter [ ] xc = null ;
 * then ,
 * toXml ( bean , xa , xaf , xaa , xf , xic , xit , xc ) ;
 * < / pre > < b > Note : XStream Mode is { @ link XStream # NO _ REFERENCES } < / b >
 * @ param obj bean
 * @ param xAlias Alias a Class to a shorter name to be used in XML elements .
 * @ param xAliasFields Create an alias for a field name .
 * @ param xAliasAttributes Create an alias for an attribute .
 * @ param xOmitFields Prevents a field from being serialized .
 * @ param xImplicitCollection Adds implicit collection which is used for all items of the
 * given element name defined by itemFieldName .
 * @ param xImmutableTypes Add immutable types . The value of the instances of these types
 * will always be written into the stream even if they appear
 * multiple times .
 * @ param xConverters register converter
 * @ param < T > obj
 * @ return xml String
 * @ since XSTREAM 1.4.5 */
public static < T > String toXml ( T obj , XAlias [ ] xAlias , XAliasField [ ] xAliasFields , XAliasAttribute [ ] xAliasAttributes , XOmitField [ ] xOmitFields , XImplicitCollection [ ] xImplicitCollection , XImmutableType [ ] xImmutableTypes , XConverter [ ] xConverters ) { } }

implementation: return ( String ) parse ( 0 , XStream . NO_REFERENCES , obj , xAlias , xAliasFields , xAliasAttributes , xOmitFields , xImplicitCollection , xImmutableTypes , xConverters ) ;


signature:
public class XmlUtil { /** * Bean to xml .
 * Using XStream library from xml to serialize objects .
 * example :
 * < pre >
 * XAlias [ ] xa = { new XAlias ( " Foo " , Foo . class ) } ;
 * XAliasField [ ] xaf = { new XAliasField ( " Bar " , Bar . class , " bar " ) } ;
 * XAliasAttribute [ ] xaa = { new XAliasAttribute ( " Name " , User . class , " name " ) } ;
 * XOmitField [ ] xf = { new XOmitField ( V . class , " v " ) }
 * then ,
 * toBean ( xmlStr , xa , xaf , xaa , xf ) ;
 * < / pre > < b > Note : XStream Mode is { @ link XStream # NO _ REFERENCES } < / b >
 * @ param xmlStr xml String
 * xml String
 * @ param xAlias Alias a Class to a shorter name to be used in XML elements .
 * @ param xAliasFields Create an alias for a field name .
 * @ param xAliasAttributes Create an alias for an attribute .
 * @ param xOmitFields Prevents a field from being serialized .
 * @ return Object
 * @ since XSTREAM 1.4.5 */
public static Object toBean ( String xmlStr , XAlias [ ] xAlias , XAliasField [ ] xAliasFields , XAliasAttribute [ ] xAliasAttributes , XOmitField [ ] xOmitFields ) { } }

implementation: return toBean ( xmlStr , xAlias , xAliasFields , xAliasAttributes , xOmitFields , null , null , null ) ;


signature:
public class XmlUtil { /** * Bean to xml .
 * Using XStream library from xml to serialize objects .
 * example :
 * < pre >
 * XAlias [ ] xa = { new XAlias ( " Foo " , Foo . class ) } ;
 * XAliasField [ ] xaf = { new XAliasField ( " Bar " , Bar . class , " bar " ) } ;
 * XAliasAttribute [ ] xaa = { new XAliasAttribute ( " Name " , User . class , " name " ) } ;
 * XOmitField [ ] xf = { new XOmitField ( V . class , " v " ) } ;
 * XImplicitCollection [ ] xic = null ;
 * XImmutableType [ ] xit = null ;
 * XConverter [ ] xc = null ;
 * then ,
 * toBean ( xmlStr , xa , xaf , xaa , xf , xic , xit , xc ) ;
 * < / pre > < b > Note : XStream Mode is { @ link XStream # ID _ REFERENCES } < / b >
 * @ param xmlStr xml String
 * xml String
 * @ param xAlias Alias a Class to a shorter name to be used in XML elements .
 * @ param xAliasFields Create an alias for a field name .
 * @ param xAliasAttributes Create an alias for an attribute .
 * @ param xOmitFields Prevents a field from being serialized .
 * @ param xImplicitCollection Adds implicit collection which is used for all items of the
 * given element name defined by itemFieldName .
 * @ param xImmutableTypes Add immutable types . The value of the instances of these types
 * will always be written into the stream even if they appear
 * multiple times .
 * @ param xConverters register converter
 * @ return Object
 * @ since XSTREAM 1.4.5 */
public static Object toBeanWithIdRef ( String xmlStr , XAlias [ ] xAlias , XAliasField [ ] xAliasFields , XAliasAttribute [ ] xAliasAttributes , XOmitField [ ] xOmitFields , XImplicitCollection [ ] xImplicitCollection , XImmutableType [ ] xImmutableTypes , XConverter [ ] xConverters ) { } }

implementation: return parse ( 1 , XStream . ID_REFERENCES , xmlStr , xAlias , xAliasFields , xAliasAttributes , xOmitFields , xImplicitCollection , xImmutableTypes , xConverters ) ;


signature:
public class XmlUtil { /** * Parser
 * @ param parseMod 0 is toXml
 * @ param mode XStream . ID _ REFERENCES or XStream . NO _ REFERENCES
 * @ param value value
 * @ param xAlias { @ link com . rockagen . commons . util . XmlUtil . XAlias }
 * @ param xAliasFields { @ link com . rockagen . commons . util . XmlUtil . XAliasField }
 * @ param xAliasAttributes { @ link com . rockagen . commons . util . XmlUtil . XAliasAttribute }
 * @ param xOmitFields { @ link com . rockagen . commons . util . XmlUtil . XOmitField }
 * @ param xImplicitCollection { @ link com . rockagen . commons . util . XmlUtil . XImplicitCollection }
 * @ param xImmutableTypes { @ link com . rockagen . commons . util . XmlUtil . XImmutableType }
 * @ param xConverters { @ link com . rockagen . commons . util . XmlUtil . XConverter }
 * @ return Object */
private static Object parse ( int parseMod , int mode , Object value , XAlias [ ] xAlias , XAliasField [ ] xAliasFields , XAliasAttribute [ ] xAliasAttributes , XOmitField [ ] xOmitFields , XImplicitCollection [ ] xImplicitCollection , XImmutableType [ ] xImmutableTypes , XConverter [ ] xConverters ) { } }

implementation: if ( value == null ) { return null ; } if ( value instanceof String ) { if ( value . equals ( "" ) ) { return null ; } } final XStream xstream = new XStream ( ) ; xstream . setMode ( mode ) ; initXstream ( xstream , xAlias , xAliasFields , xAliasAttributes , xOmitFields , xImplicitCollection , xImmutableTypes , xConverters ) ; if ( parseMod == 0 ) { return xstream . toXML ( value ) ; } else { return xstream . fromXML ( ( String ) value ) ; }


signature:
public class XmlUtil { /** * XStream Alias
 * @ param xstream { @ link com . thoughtworks . xstream . XStream }
 * @ param xAlias { @ link com . rockagen . commons . util . XmlUtil . XAlias }
 * @ param xAliasFields { @ link com . rockagen . commons . util . XmlUtil . XAliasField }
 * @ param xAliasAttributes { @ link com . rockagen . commons . util . XmlUtil . XAliasAttribute }
 * @ param xOmitFields { @ link com . rockagen . commons . util . XmlUtil . XOmitField }
 * @ param xImplicitCollection { @ link com . rockagen . commons . util . XmlUtil . XImplicitCollection }
 * @ param xImmutableTypes { @ link com . rockagen . commons . util . XmlUtil . XImmutableType }
 * @ param xConverters { @ link com . rockagen . commons . util . XmlUtil . XConverter } */
protected static void initXstream ( XStream xstream , XAlias [ ] xAlias , XAliasField [ ] xAliasFields , XAliasAttribute [ ] xAliasAttributes , XOmitField [ ] xOmitFields , XImplicitCollection [ ] xImplicitCollection , XImmutableType [ ] xImmutableTypes , XConverter [ ] xConverters ) { } }

implementation: if ( xOmitFields != null ) { for ( XOmitField xof : xOmitFields ) { xstream . omitField ( xof . classType , xof . fieldName ) ; } } if ( xImplicitCollection != null ) { for ( XImplicitCollection xic : xImplicitCollection ) { xstream . addImplicitCollection ( xic . ownerType , xic . fieldName , xic . itemFieldName , xic . itemType ) ; } } if ( xImmutableTypes != null ) { for ( XImmutableType xit : xImmutableTypes ) { xstream . addImmutableType ( xit . type ) ; } } if ( xConverters != null ) { for ( XConverter xc : xConverters ) { xstream . registerConverter ( xc . converter , xc . priority ) ; } } if ( xAlias != null ) { for ( XAlias xa : xAlias ) { xstream . alias ( xa . aliasName , xa . classType ) ; } } if ( xAliasFields != null ) { for ( XAliasField xaf : xAliasFields ) { xstream . aliasField ( xaf . aliasName , xaf . fieldType , xaf . fieldName ) ; } } if ( xAliasAttributes != null ) { for ( XAliasAttribute xaa : xAliasAttributes ) { xstream . useAttributeFor ( xaa . attributeType , xaa . attributeName ) ; xstream . aliasAttribute ( xaa . attributeType , xaa . attributeName , xaa . aliasName ) ; } }


signature:
public class JdbcLogDriver { /** * url pattern = " JdbcLog " " : " [ DriverClassName ] " : " ConnectionUrl */
private String getDriverClassName ( String url ) { } }

implementation:
String driverClassName = null ; if ( url . startsWith ( CONNECTION_URL_SUFFIX ) ) { url = url . substring ( CONNECTION_URL_SUFFIX . length ( ) ) ; driverClassName = url . substring ( 0 , url . indexOf ( ":" ) ) ; if ( driverClassName . length ( ) > 0 ) { return driverClassName ; } url = url . substring ( url . indexOf ( ":" ) + 1 ) ; } if ( url . startsWith ( "jdbc:oracle:thin:" ) ) { driverClassName = "oracle.jdbc.driver.OracleDriver" ; } else if ( url . startsWith ( "jdbc:mysql:" ) ) { driverClassName = "com.mysql.jdbc.Driver" ; } else if ( url . startsWith ( "jdbc:jtds:" ) ) { // SQL Server or SyBase
driverClassName = "net.sourceforge.jtds.jdbc.Driver" ; } else if ( url . startsWith ( "jdbc:db2:" ) ) { driverClassName = "com.ibm.db2.jdbc.net.DB2Driver" ; } else if ( url . startsWith ( "jdbc:microsoft:sqlserver:" ) ) { // SQL Server 7.0/2000
driverClassName = "com.microsoft.jdbc.sqlserver.SQLServerDriver" ; } else if ( url . startsWith ( "jdbc:sqlserver:" ) ) { // SQL Server 2005
driverClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver" ; } else if ( url . startsWith ( "jdbc:postgresql:" ) ) { driverClassName = "org.postgresql.Driver" ; } else if ( url . startsWith ( "jdbc:hsqldb:" ) ) { driverClassName = "org.hsqldb.jdbcDriver" ; } else if ( url . startsWith ( "jdbc:derby://" ) ) { driverClassName = "org.apache.derby.jdbc.ClientDriver" ; } else if ( url . startsWith ( "jdbc:derby:" ) ) { driverClassName = "org.apache.derby.jdbc.EmbeddedDriver" ; } else if ( url . startsWith ( "jdbc:sybase:Tds:" ) ) { driverClassName = "com.sybase.jdbc.SybDriver" ; } else if ( url . startsWith ( "jdbc:informix-sqli:" ) ) { driverClassName = "com.informix.jdbc.IfxDriver" ; } else if ( url . startsWith ( "jdbc:odbc:" ) ) { driverClassName = "sun.jdbc.odbc.JdbcOdbcDriver" ; } else if ( url . startsWith ( "jdbc:timesten:client:" ) ) { driverClassName = "com.timesten.jdbc.TimesTenDriver" ; } else if ( url . startsWith ( "jdbc:as400:" ) ) { driverClassName = "com.ibm.as400.access.AS400JDBCDriver" ; } else if ( url . startsWith ( "jdbc:sapdb:" ) ) { driverClassName = "com.sap.dbtech.jdbc.DriverSapDB" ; } else if ( url . startsWith ( "jdbc:interbase:" ) ) { driverClassName = "interbase.interclient.Driver" ; } return driverClassName ;


signature:
public class JdbcLogDriver { /** * JDK 1.7 */
@ Override public java . util . logging . Logger getParentLogger ( ) throws SQLFeatureNotSupportedException { } }

implementation: if ( drivers . size ( ) == 1 ) { return getFirstDriver ( ) . getParentLogger ( ) ; } return null ;


signature:
public class PathVariables { /** * 返回最终的 map */
public Map < String , String > map ( ) { } }

implementation: Map < String , String > map = new HashMap < String , String > ( ) ; int i = 0 ; while ( i < size ) { map . put ( items [ i ] , items [ i + 1 ] ) ; i += 2 ; } return map ;


signature:
public class ZipPathNode { /** * ( non - Javadoc )
 * @ see org . wymiwyg . commons . util . dirbrowser . PathNode # getLastModified ( ) */
public Date getLastModified ( ) { } }

implementation: try { long time = file . getEntry ( entryName ) . getTime ( ) ; if ( time > - 1 ) { return new Date ( time ) ; } else { return null ; } } catch ( NullPointerException ex ) { return null ; }


signature:
public class MessageHelper { /** * Post a message queue event ( during a login workflow ) .
 * If { @ code messageQ } is { @ code null } , then messaging is considered disabled .
 * @ param messageQ The message queue object to use for posting the message
 * @ param domain The user ' s domain
 * @ param username The user ' s username
 * @ param event The event to post
 * @ param error The error message to be logged in the application log if the message queue post fails ( i . e . no
 * message queue event can be created )
 * @ throws LoginException If posting to the message queue fails ( i . e . no message can be created )
 * @ throws NullPointerException When the { @ code domain } , { @ code username } , { @ code event } , or { @ code error } are
 * { @ code null }
 * @ throws IllegalArgumentException When { @ code domain } , { @ code username } , or { @ code error } are empty */
public static void postMessage ( final MessageQ messageQ , final String domain , final String username , final Events event , final String error ) throws LoginException { } }

implementation:
// " messageQ " may be null , not validating here ( see below )
Validate . notBlank ( domain , "The validated character sequence 'domain' is null or empty" ) ; Validate . notBlank ( username , "The validated character sequence 'username' is null or empty" ) ; Validate . notNull ( event , "The validated object 'event' is null" ) ; Validate . notBlank ( error , "The validated character sequence 'error' is null or empty" ) ; // if message queues are disabled , the messageQ object will not have been initialized
if ( messageQ == null ) { // string concatenation is only executed if log level is actually enabled
if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Messages queues have been disabled, not creating event '" + event . getValue ( ) + "' for '" + username + "@" + domain + "'" ) ; } } else { try { messageQ . create ( event , domain , username ) ; } catch ( MessageQException e ) { LOG . warn ( error , e ) ; throw Util . newLoginException ( error , e ) ; } }


signature:
public class PasswordCallbackHandler { /** * Retrieve or display the information requested in the provided Callbacks .
 * The { @ code handle } method implementation checks the
 * instance ( s ) of the { @ code Callback } object ( s ) passed in
 * to retrieve or display the requested information .
 * @ param callbacks an array of { @ code Callback } objects provided by an underlying security service which contains
 * the information requested to be retrieved or displayed .
 * @ throws java . io . IOException if an input or output error occurs . < p >
 * @ throws UnsupportedCallbackException if the implementation of this method does not support one or more of the
 * Callbacks specified in the { @ code callbacks } parameter .
 * @ throws NullPointerException When { @ code callbacks } is { @ code null } */
@ Override // Cannot change the interface to use varags , this interface is owned by javax . security
@ SuppressWarnings ( "PMD.UseVarargs" ) public final void handle ( final Callback [ ] callbacks ) throws IOException , UnsupportedCallbackException { } }

implementation: Validate . notNull ( callbacks , "The validated object 'callbacks' is null" ) ; for ( final Callback callback : callbacks ) { if ( callback instanceof NameCallback ) { final NameCallback nameCallback = ( NameCallback ) callback ; nameCallback . setName ( username ) ; } else if ( callback instanceof PasswordCallback ) { final PasswordCallback passwordCallback = ( PasswordCallback ) callback ; passwordCallback . setPassword ( password ) ; } else if ( callback instanceof TextInputCallback ) { final TextInputCallback textInputCallback = ( TextInputCallback ) callback ; textInputCallback . setText ( domain ) ; } else { final String error = "Unsupported callback: " + callback . getClass ( ) . getCanonicalName ( ) + " Allowed callbacks are: " + NameCallback . class . getCanonicalName ( ) + " OR " + PasswordCallback . class . getCanonicalName ( ) + " OR " + TextInputCallback . class . getCanonicalName ( ) ; LOG . warn ( error ) ; throw new UnsupportedCallbackException ( callback , error ) ; } }


signature:
public class SrvEntityWriterXml { /** * Write entity into a stream ( writer - file or pass it through network ) .
 * @ param pAddParam additional params ( e . g . exclude fields set )
 * @ param pEntity object
 * @ param pWriter writer
 * @ throws Exception - an exception */
@ Override public final void write ( final Map < String , Object > pAddParam , final Object pEntity , final Writer pWriter ) throws Exception { } }

implementation: Map < String , Map < String , String > > fieldsSettingsMap = getMngSettings ( ) . lazFldsSts ( pEntity . getClass ( ) ) ; pWriter . write ( "<entity class=\"" + pEntity . getClass ( ) . getCanonicalName ( ) + "\"\n" ) ; for ( Map . Entry < String , Map < String , String > > entry : fieldsSettingsMap . entrySet ( ) ) { if ( "true" . equals ( entry . getValue ( ) . get ( "isEnabled" ) ) ) { Field field = getUtlReflection ( ) . retrieveField ( pEntity . getClass ( ) , entry . getKey ( ) ) ; field . setAccessible ( true ) ; Object fieldValue = field . get ( pEntity ) ; ISrvFieldWriter srvFieldWriter = getFieldsWritersMap ( ) . get ( entry . getValue ( ) . get ( "ISrvFieldWriter" ) ) ; if ( srvFieldWriter == null ) { throw new ExceptionWithCode ( ExceptionWithCode . CONFIGURATION_MISTAKE , "There is no ISrvFieldWriter " + entry . getValue ( ) . get ( "ISrvFieldWriter" ) + " for " + pEntity . getClass ( ) + " / " + field . getName ( ) ) ; } srvFieldWriter . write ( pAddParam , fieldValue , field . getName ( ) , pWriter ) ; } } pWriter . write ( "/>\n" ) ;


signature:
public class ClassUtils { /** * 判断一个 Class 是否存在并且可用 . */
public static boolean available ( String qualifiedClassName , ClassLoader loader ) { } }

implementation: return ClassLoaderUtils . loadClass ( qualifiedClassName , loader ) != null ;


signature:
public class ClassUtils { /** * Class . isAssignableFrom ( ) 的增强版本 。 支持 null , 自动装箱 ,
 * 以及数字类型的隐私转换 . */
public static boolean isAssignable ( Class < ? > lhs , Class < ? > rhs ) { } }

implementation: if ( lhs == null ) return false ; if ( rhs == null ) return ( ! ( lhs . isPrimitive ( ) ) ) ; if ( unboxed_class_set . contains ( lhs ) ) { lhs = boxed_class_map . get ( lhs ) ; } if ( unboxed_class_set . contains ( rhs ) ) { rhs = boxed_class_map . get ( rhs ) ; } if ( lhs . isAssignableFrom ( rhs ) ) { return true ; } lhs = unboxed_class_map . get ( lhs ) ; rhs = unboxed_class_map . get ( rhs ) ; if ( lhs == null || rhs == null ) { return false ; } if ( Integer . TYPE . equals ( rhs ) ) { return ( Long . TYPE . equals ( lhs ) || Float . TYPE . equals ( lhs ) || Double . TYPE . equals ( lhs ) ) ; } if ( Long . TYPE . equals ( rhs ) ) { return ( Float . TYPE . equals ( lhs ) || Double . TYPE . equals ( lhs ) ) ; } if ( Float . TYPE . equals ( rhs ) ) { return Double . TYPE . equals ( lhs ) ; } if ( Double . TYPE . equals ( rhs ) ) { return false ; } if ( Boolean . TYPE . equals ( rhs ) ) { return false ; } if ( Byte . TYPE . equals ( rhs ) ) { return ( Short . TYPE . equals ( lhs ) || Integer . TYPE . equals ( lhs ) || Long . TYPE . equals ( lhs ) || Float . TYPE . equals ( lhs ) || Double . TYPE . equals ( lhs ) ) ; } if ( Short . TYPE . equals ( rhs ) ) { return ( Integer . TYPE . equals ( lhs ) || Long . TYPE . equals ( lhs ) || Float . TYPE . equals ( lhs ) || Double . TYPE . equals ( lhs ) ) ; } if ( Character . TYPE . equals ( rhs ) ) { return ( Integer . TYPE . equals ( lhs ) || Long . TYPE . equals ( lhs ) || Float . TYPE . equals ( lhs ) || Double . TYPE . equals ( lhs ) ) ; } return false ;


signature:
public class JdbcLogConnection { /** * Creates a logging version of a connection
 * @ param conn - the original connection
 * @ return - the connection with logging */
public static Connection getInstance ( Connection conn ) { } }

implementation: InvocationHandler handler = new JdbcLogConnection ( conn ) ; ClassLoader cl = Connection . class . getClassLoader ( ) ; return ( Connection ) Proxy . newProxyInstance ( cl , new Class [ ] { Connection . class } , handler ) ;


signature:
public class ConsoleAuthProvider { /** * Prints the authorizationUrl , the user will open the url and obtain an
 * authorization key . When prompted , the user should provide the authorization
 * key . */
@ Override public String getAuthorization ( String authorizationUrl ) throws CubeSensorsException { } }

implementation: System . out . println ( "authorizationUrl:" + authorizationUrl ) ; System . out . print ( "provide authorization code:" ) ; try ( Scanner in = new Scanner ( System . in ) ) { String authorization = in . nextLine ( ) ; return authorization ; }


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

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


signature:
public class ListOrderedMap { /** * OrderedMap interface */
public Entry < K , V > getEntry ( int index ) { } }

implementation: if ( index < 0 || index >= size ( ) ) { throw new IndexOutOfBoundsException ( ) ; } LinkedEntry < K , V > entry = header . next ; for ( int i = 0 ; i < index ; i ++ ) { entry = entry . next ; } return entry ;


signature:
public class DatabaseWriterXml { /** * Retrieve requested entities from DB then write them into a stream
 * by given writer .
 * @ param T Entity Class
 * @ param pAddParam additional params ( e . g . where and order clause )
 * @ param pEntityClass Entity Class
 * @ param pWriter writer
 * @ return entities count
 * @ throws Exception - an exception */
@ Override public final < T > int retrieveAndWriteEntities ( final Map < String , Object > pAddParam , final Class < T > pEntityClass , final Writer pWriter ) throws Exception { } }

implementation:
// e . g . " limit 20 offset 19 " :
// e . g . " where ( ITSID > 0 and IDDATABASEBIRTH = 2135 ) limit 20 offset 19 " :
String conditions = ( String ) pAddParam . get ( "conditions" ) ; int requestingDatabaseVersion = Integer . parseInt ( ( String ) pAddParam . get ( "requestingDatabaseVersion" ) ) ; int databaseVersion = this . srvDatabase . getVersionDatabase ( ) ; List < T > entities = null ; int entitiesCount = 0 ; DatabaseInfo di ; if ( requestingDatabaseVersion == databaseVersion ) { try { this . srvDatabase . setIsAutocommit ( false ) ; this . srvDatabase . setTransactionIsolation ( ISrvDatabase . TRANSACTION_READ_UNCOMMITTED ) ; this . srvDatabase . beginTransaction ( ) ; di = getSrvOrm ( ) . retrieveEntityWithConditions ( pAddParam , DatabaseInfo . class , "" ) ; String requestedDatabaseIdStr = ( String ) pAddParam . get ( "requestedDatabaseId" ) ; if ( requestedDatabaseIdStr != null ) { int requestedDatabaseId = Integer . parseInt ( requestedDatabaseIdStr ) ; if ( requestedDatabaseId != di . getDatabaseId ( ) ) { String error = "Different requested database ID! required/is: " + requestedDatabaseId + "/" + di . getDatabaseId ( ) ; this . logger . error ( null , DatabaseWriterXml . class , error ) ; pWriter . write ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ) ; pWriter . write ( "<message error=\"" + error + "\">\n" ) ; pWriter . write ( "</message>\n" ) ; return entitiesCount ; } } if ( conditions == null ) { entities = getSrvOrm ( ) . retrieveList ( pAddParam , pEntityClass ) ; } else { entities = getSrvOrm ( ) . retrieveListWithConditions ( pAddParam , pEntityClass , conditions ) ; } entitiesCount = entities . size ( ) ; this . srvDatabase . commitTransaction ( ) ; } catch ( Exception ex ) { this . srvDatabase . rollBackTransaction ( ) ; throw ex ; } finally { this . srvDatabase . releaseResources ( ) ; } this . logger . info ( null , DatabaseWriterXml . class , "Start write entities of " + pEntityClass . getCanonicalName ( ) + " count=" + entitiesCount ) ; pWriter . write ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ) ; pWriter . write ( "<message databaseId=\"" + di . getDatabaseId ( ) + "\" databaseVersion=\"" + di . getDatabaseVersion ( ) + "\" description=\"" + di . getDescription ( ) + "\" entitiesCount=\"" + entitiesCount + "\">\n" ) ; for ( T entity : entities ) { this . srvEntityWriter . write ( pAddParam , entity , pWriter ) ; } pWriter . write ( "</message>\n" ) ; this . logger . info ( null , DatabaseWriterXml . class , "Entities has been wrote" ) ; } else { this . logger . error ( null , DatabaseWriterXml . class , "Send error message - Different database version!" ) ; pWriter . write ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ) ; pWriter . write ( "<message error=\"Different database version!\">\n" ) ; pWriter . write ( "</message>\n" ) ; } return entitiesCount ;


signature:
public class AuditFactory { /** * Return a singleton , fully initialized instance of an { @ link Audit } class to use for JAAS event auditing .
 * Retrieving a singleton by this method will cause the factory to keep state , and store a reference to the
 * singleton for later use . You may reset the factory state using the { @ code reset ( ) } method to retrieve a new
 * / different singleton the next time this method is called . .
 * Note that any properties of the singleton ( e . g . configuration ) cannot necessarily be changed easily . You may call
 * the singleton ' s { @ code init ( ) } method , but depending on the implementation provided by the respective class , this
 * may or may not have the expected effect .
 * If you need tight control over the singleton , including its lifecycle and configuration , or you require more than
 * one singleton that are different in their internal state ( e . g . with different configurations ) , then you should
 * create such objects with the { @ code getInstance ( ) } method and maintain their state as " singletons " in your
 * application ' s business logic .
 * Classes implementing the { @ link Audit } interface < b > must < / b > be thread safe .
 * @ param className The name of a class that implements the Audit interface
 * @ param properties The properties to initialize the instance with
 * @ return An instance of a class implementing the { @ link Audit } interface
 * @ throws FactoryException When the class cannot be instantiated
 * @ throws NullPointerException When the { @ code className } or { @ code properties } are { @ code null }
 * @ throws IllegalArgumentException When { @ code className } is empty */
@ SuppressWarnings ( "PMD.NonThreadSafeSingleton" ) public static Audit getSingleton ( final String className , final CommonProperties properties ) throws FactoryException { } }

implementation:
Validate . notBlank ( className , "The validated character sequence 'className' is null or empty" ) ; Validate . notNull ( properties , "The validated object 'properties' is null" ) ; // The double - check idiom is safe and acceptable here ( Bloch , 2nd ed . p 284)
if ( auditInstance == null ) { synchronized ( AuditFactory . class ) { if ( auditInstance == null ) { auditInstance = getInstance ( className , properties ) ; } } } return auditInstance ;


signature:
public class PrepareDbAfterGetCopyPostgresql { /** * < p > It prepares database after import . < / p >
 * @ param pAddParams additional params
 * @ throws Exception - an exception */
@ Override public final void make ( final Map < String , Object > pAddParams ) throws Exception { } }

implementation: int preparedEntitiesCount = 0 ; try { this . srvDatabase . setIsAutocommit ( false ) ; this . srvDatabase . setTransactionIsolation ( ISrvDatabase . TRANSACTION_READ_UNCOMMITTED ) ; this . srvDatabase . beginTransaction ( ) ; for ( Class < ? > entityClass : this . classes ) { if ( APersistableBase . class . isAssignableFrom ( entityClass ) ) { preparedEntitiesCount ++ ; String queryMaxId = "select max(ITSID) as MAXID from " + entityClass . getSimpleName ( ) . toUpperCase ( ) + ";" ; Integer maxId = this . srvDatabase . evalIntegerResult ( queryMaxId , "MAXID" ) ; if ( maxId != null ) { maxId ++ ; String querySec = "alter sequence " + entityClass . getSimpleName ( ) . toUpperCase ( ) + "_ITSID_SEQ restart with " + maxId + ";" ; this . srvDatabase . executeQuery ( querySec ) ; } } } this . srvDatabase . commitTransaction ( ) ; } catch ( Exception ex ) { this . srvDatabase . rollBackTransaction ( ) ; throw ex ; } finally { this . srvDatabase . releaseResources ( ) ; } this . factoryAppBeans . releaseBeans ( ) ; Writer htmlWriter = ( Writer ) pAddParams . get ( "htmlWriter" ) ; if ( htmlWriter != null ) { htmlWriter . write ( "<h4>" + new Date ( ) . toString ( ) + ", " + PrepareDbAfterGetCopyPostgresql . class . getSimpleName ( ) + ", app-factory beans has released" + "</h4>" ) ; } this . logger . info ( null , PrepareDbAfterGetCopyPostgresql . class , "Total sequence prepared: " + preparedEntitiesCount + ", app-factory beans has released" ) ;


signature:
public class DeclarationScanner { /** * Visits a package declaration .
 * @ param d the declaration to visit */
public void visitPackageDeclaration ( PackageDeclaration d ) { } }

implementation: d . accept ( pre ) ; for ( ClassDeclaration classDecl : d . getClasses ( ) ) { classDecl . accept ( this ) ; } for ( InterfaceDeclaration interfaceDecl : d . getInterfaces ( ) ) { interfaceDecl . accept ( this ) ; } d . accept ( post ) ;


signature:
public class DeclarationScanner { /** * Visits a type declaration .
 * @ param d the declaration to visit */
public void visitTypeDeclaration ( TypeDeclaration d ) { } }

implementation: d . accept ( pre ) ; for ( TypeParameterDeclaration tpDecl : d . getFormalTypeParameters ( ) ) { tpDecl . accept ( this ) ; } for ( FieldDeclaration fieldDecl : d . getFields ( ) ) { fieldDecl . accept ( this ) ; } for ( MethodDeclaration methodDecl : d . getMethods ( ) ) { methodDecl . accept ( this ) ; } for ( TypeDeclaration typeDecl : d . getNestedTypes ( ) ) { typeDecl . accept ( this ) ; } d . accept ( post ) ;


signature:
public class DeclarationScanner { /** * Visits a class declaration .
 * @ param d the declaration to visit */
public void visitClassDeclaration ( ClassDeclaration d ) { } }

implementation: d . accept ( pre ) ; for ( TypeParameterDeclaration tpDecl : d . getFormalTypeParameters ( ) ) { tpDecl . accept ( this ) ; } for ( FieldDeclaration fieldDecl : d . getFields ( ) ) { fieldDecl . accept ( this ) ; } for ( MethodDeclaration methodDecl : d . getMethods ( ) ) { methodDecl . accept ( this ) ; } for ( TypeDeclaration typeDecl : d . getNestedTypes ( ) ) { typeDecl . accept ( this ) ; } for ( ConstructorDeclaration ctorDecl : d . getConstructors ( ) ) { ctorDecl . accept ( this ) ; } d . accept ( post ) ;


signature:
public class DeclarationScanner { /** * Visits a method or constructor declaration .
 * @ param d the declaration to visit */
public void visitExecutableDeclaration ( ExecutableDeclaration d ) { } }

implementation: d . accept ( pre ) ; for ( TypeParameterDeclaration tpDecl : d . getFormalTypeParameters ( ) ) { tpDecl . accept ( this ) ; } for ( ParameterDeclaration pDecl : d . getParameters ( ) ) { pDecl . accept ( this ) ; } d . accept ( post ) ;


signature:
public class MainPropertyView { /** * 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 ( 2 , 3 ) ) ; String strSource = m_properties . getProperty ( SOURCE_PARAM ) ; if ( strSource == null ) strSource = m_rgstrSources [ 0 ] ; panelMain . add ( new JLabel ( "Source: " , JLabel . RIGHT ) ) ; panelMain . add ( m_comboSource = ( JComboBox ) this . makeControlPopup ( m_rgstrSources , strSource ) ) ; panelMain . add ( m_buttonSource = ( JButton ) new JButton ( "Change settings..." ) ) ; String strDestination = m_properties . getProperty ( DESTINATION_PARAM ) ; if ( strDestination == null ) strDestination = m_rgstrDestinations [ 0 ] ; panelMain . add ( new JLabel ( "Destination: " , JLabel . RIGHT ) ) ; panelMain . add ( m_comboDestination = ( JComboBox ) this . makeControlPopup ( m_rgstrDestinations , strDestination ) ) ; panelMain . add ( m_buttonDestination = ( JButton ) new JButton ( "Change settings..." ) ) ; JPanel panelSub = this . makeNewPanel ( panel , BorderLayout . SOUTH ) ; super . addControlsToView ( panelSub ) ;


signature:
public class MainPropertyView { /** * Add listeners to the controls . */
public void addListeners ( ) { } }

implementation: super . addListeners ( ) ; m_buttonSource . addActionListener ( this ) ; m_comboSource . addItemListener ( this ) ; m_buttonDestination . addActionListener ( this ) ; m_comboDestination . addItemListener ( this ) ;


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

implementation: String strSelection = ( String ) m_comboSource . getSelectedItem ( ) ; m_properties . setProperty ( SOURCE_PARAM , strSelection ) ; strSelection = ( String ) m_comboDestination . getSelectedItem ( ) ; m_properties . setProperty ( DESTINATION_PARAM , strSelection ) ; super . controlsToProperties ( ) ;


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

implementation: m_comboSource . setSelectedItem ( m_properties . getProperty ( SOURCE_PARAM ) ) ; if ( m_comboSource . getSelectedIndex ( ) == - 1 ) { m_comboSource . setSelectedIndex ( 0 ) ; m_properties . setProperty ( SOURCE_PARAM , m_comboSource . getSelectedItem ( ) . toString ( ) ) ; } m_comboDestination . setSelectedItem ( m_properties . getProperty ( DESTINATION_PARAM ) ) ; if ( m_comboDestination . getSelectedIndex ( ) == - 1 ) { m_comboDestination . setSelectedIndex ( 0 ) ; m_properties . setProperty ( DESTINATION_PARAM , m_comboDestination . getSelectedItem ( ) . toString ( ) ) ; } super . propertiesToControls ( ) ;


signature:
public class MainPropertyView { /** * User pressed a button . */
public void actionPerformed ( ActionEvent e ) { } }

implementation:
PropertyOwner propOwner = null ; String strClass = null ; Object objClass = null ; if ( e . getSource ( ) == m_buttonSource ) { strClass = m_properties . getProperty ( Scanner . SOURCE_PARAM ) ; objClass = Util . makeObjectFromClassName ( Object . class . getName ( ) , SOURCE_PARAM , strClass ) ; if ( objClass instanceof BaseSource ) // Always
( ( BaseSource ) objClass ) . init ( m_properties ) ; } else if ( e . getSource ( ) == m_buttonDestination ) { strClass = m_properties . getProperty ( Scanner . DESTINATION_PARAM ) ; objClass = Util . makeObjectFromClassName ( Object . class . getName ( ) , DESTINATION_PARAM , strClass ) ; if ( objClass instanceof BaseDestination ) // Always
( ( BaseDestination ) objClass ) . init ( m_properties ) ; } if ( objClass instanceof PropertyOwner ) propOwner = ( PropertyOwner ) objClass ; if ( propOwner != null ) { this . controlsToProperties ( ) ; PropertyView panel = propOwner . getPropertyView ( m_properties ) ; if ( panel == null ) // Default
panel = new PropertyView ( m_propOwner , m_properties ) ; if ( JOptionPane . showConfirmDialog ( null , panel , panel . getDescription ( ) , JOptionPane . OK_CANCEL_OPTION ) == JOptionPane . OK_OPTION ) { panel . controlsToProperties ( ) ; propOwner . setProperties ( m_properties ) ; // Send the property owner the new settings
} }


signature:
public class JaasBasedCommonPropsBuilder { /** * suppress warnings about this method being too complex ( can ' t extract a generic subroutine to reduce exec paths ) */
@ SuppressWarnings ( { } }

implementation:
"PMD.ExcessiveMethodLength" , "PMD.NPathComplexity" , "PMD.CyclomaticComplexity" , "PMD.StdCyclomaticComplexity" , "PMD.ModifiedCyclomaticComplexity" } ) // CHECKSTYLE : ON
public static CommonProperties build ( final Map < String , ? > properties ) { Validate . notNull ( properties , "The validated object 'properties' is null" ) ; final CommonProperties commonProps = new CommonProperties ( ) ; String tmp = getOption ( KEY_AUDIT_CLASS_NAME , properties ) ; if ( StringUtils . isNotEmpty ( tmp ) ) { commonProps . setAuditClassName ( tmp ) ; logValue ( KEY_AUDIT_CLASS_NAME , tmp ) ; } else { commonProps . setAuditClassName ( DEFAULT_AUDIT_CLASS_NAME ) ; logDefault ( KEY_AUDIT_CLASS_NAME , DEFAULT_AUDIT_CLASS_NAME ) ; } tmp = getOption ( KEY_AUDIT_IS_ENABLED , properties ) ; if ( StringUtils . isNotEmpty ( tmp ) ) { commonProps . setAuditEnabled ( Boolean . parseBoolean ( tmp ) ) ; logValue ( KEY_AUDIT_IS_ENABLED , tmp ) ; } else { commonProps . setAuditEnabled ( DEFAULT_AUDIT_IS_ENABLED ) ; logDefault ( KEY_AUDIT_IS_ENABLED , String . valueOf ( DEFAULT_AUDIT_IS_ENABLED ) ) ; } tmp = getOption ( KEY_AUDIT_IS_SINGLETON , properties ) ; if ( StringUtils . isNotEmpty ( tmp ) ) { commonProps . setAuditSingleton ( Boolean . parseBoolean ( tmp ) ) ; logValue ( KEY_AUDIT_IS_SINGLETON , tmp ) ; } else { commonProps . setAuditSingleton ( DEFAULT_AUDIT_IS_SINGLETON ) ; logDefault ( KEY_AUDIT_IS_SINGLETON , String . valueOf ( DEFAULT_AUDIT_IS_SINGLETON ) ) ; } tmp = getOption ( KEY_MESSAGEQ_CLASS_NAME , properties ) ; if ( StringUtils . isNotEmpty ( tmp ) ) { commonProps . setMessageQueueClassName ( tmp ) ; logValue ( KEY_MESSAGEQ_CLASS_NAME , tmp ) ; } else { commonProps . setMessageQueueClassName ( DEFAULT_MESSAGEQ_CLASS_NAME ) ; logDefault ( KEY_MESSAGEQ_CLASS_NAME , DEFAULT_MESSAGEQ_CLASS_NAME ) ; } tmp = getOption ( KEY_MESSAGEQ_IS_ENABLED , properties ) ; if ( StringUtils . isNotEmpty ( tmp ) ) { commonProps . setMessageQueueEnabled ( Boolean . parseBoolean ( tmp ) ) ; logValue ( KEY_MESSAGEQ_IS_ENABLED , tmp ) ; } else { commonProps . setMessageQueueEnabled ( DEFAULT_MESSAGEQ_IS_ENABLED ) ; logDefault ( KEY_MESSAGEQ_IS_ENABLED , String . valueOf ( DEFAULT_MESSAGEQ_IS_ENABLED ) ) ; } tmp = getOption ( KEY_MESSAGEQ_IS_SINGLETON , properties ) ; if ( StringUtils . isNotEmpty ( tmp ) ) { commonProps . setMessageQueueSingleton ( Boolean . parseBoolean ( tmp ) ) ; logValue ( KEY_MESSAGEQ_IS_SINGLETON , tmp ) ; } else { commonProps . setMessageQueueSingleton ( DEFAULT_MESSAGEQ_IS_SINGLETON ) ; logDefault ( KEY_MESSAGEQ_IS_SINGLETON , String . valueOf ( DEFAULT_MESSAGEQ_IS_SINGLETON ) ) ; } tmp = getOption ( KEY_PASSWORD_AUTHENTICATOR_CLASS_NAME , properties ) ; if ( StringUtils . isNotEmpty ( tmp ) ) { commonProps . setPasswordAuthenticatorClassName ( tmp ) ; logValue ( KEY_PASSWORD_AUTHENTICATOR_CLASS_NAME , tmp ) ; } else { commonProps . setPasswordAuthenticatorClassName ( DEFAULT_PASSWORD_AUTHENTICATOR_CLASS_NAME ) ; logDefault ( KEY_PASSWORD_AUTHENTICATOR_CLASS_NAME , DEFAULT_PASSWORD_AUTHENTICATOR_CLASS_NAME ) ; } tmp = getOption ( KEY_PASSWORD_AUTHENTICATOR_IS_SINGLETON , properties ) ; if ( StringUtils . isNotEmpty ( tmp ) ) { commonProps . setPasswordAuthenticatorSingleton ( Boolean . parseBoolean ( tmp ) ) ; logValue ( KEY_PASSWORD_AUTHENTICATOR_IS_SINGLETON , tmp ) ; } else { commonProps . setPasswordAuthenticatorSingleton ( DEFAULT_PASSWORD_AUTHENTICATOR_IS_SINGLETON ) ; logDefault ( KEY_PASSWORD_AUTHENTICATOR_IS_SINGLETON , String . valueOf ( DEFAULT_PASSWORD_AUTHENTICATOR_IS_SINGLETON ) ) ; } tmp = getOption ( KEY_PASSWORD_VALIDATOR_CLASS_NAME , properties ) ; if ( StringUtils . isNotEmpty ( tmp ) ) { commonProps . setPasswordValidatorClassName ( tmp ) ; logValue ( KEY_PASSWORD_VALIDATOR_CLASS_NAME , tmp ) ; } else { commonProps . setPasswordValidatorClassName ( DEFAULT_PASSWORD_VALIDATOR_CLASS_NAME ) ; logDefault ( KEY_PASSWORD_VALIDATOR_CLASS_NAME , DEFAULT_PASSWORD_VALIDATOR_CLASS_NAME ) ; } tmp = getOption ( KEY_PASSWORD_VALIDATOR_IS_SINGLETON , properties ) ; if ( StringUtils . isNotEmpty ( tmp ) ) { commonProps . setPasswordValidatorSingleton ( Boolean . parseBoolean ( tmp ) ) ; logValue ( KEY_PASSWORD_VALIDATOR_IS_SINGLETON , tmp ) ; } else { commonProps . setPasswordValidatorSingleton ( DEFAULT_PASSWORD_VALIDATOR_IS_SINGLETON ) ; logDefault ( KEY_PASSWORD_VALIDATOR_IS_SINGLETON , String . valueOf ( DEFAULT_PASSWORD_VALIDATOR_IS_SINGLETON ) ) ; } // set the additional properties , preserving the originally provided properties
// create a defensive copy of the map and all its properties
// the code looks a little more complicated than a simple " putAll ( ) " , but it catches situations
// where a Map is provided that supports null values ( e . g . a HashMap ) vs Map implementations
// that do not ( e . g . ConcurrentHashMap ) .
final Map < String , String > tempMap = new ConcurrentHashMap < > ( ) ; try { for ( final Map . Entry < String , ? > entry : properties . entrySet ( ) ) { final String key = entry . getKey ( ) ; final String value = ( String ) entry . getValue ( ) ; if ( value != null ) { tempMap . put ( key , value ) ; } } } catch ( ClassCastException e ) { final String error = "The values of the configured JAAS properties must be Strings. " + "Sorry, but we do not support anything else here!" ; throw new IllegalArgumentException ( error , e ) ; } commonProps . setAdditionalProperties ( tempMap ) ; return commonProps ;


signature:
public class JaasBasedCommonPropsBuilder { /** * Return the value of a JAAS configuration parameter .
 * @ param < T > The type of the element
 * @ param key The key to retrieve from the options
 * @ param properties The properties to retrieve values from
 * @ return The configuration value for the provided key */
@ SuppressWarnings ( "unchecked" ) private static < T > T getOption ( final String key , final Map < String , ? > properties ) { } }

implementation:
// private method asserts
assert key != null : "The key cannot be null" ; return ( T ) properties . get ( key ) ;


signature:
public class SrvEntitySyncHasVersion { /** * Synchronize IHasVersion .
 * @ 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: IHasVersion entityPb = ( IHasVersion ) pEntity ; IHasVersion entityPbDb = getSrvOrm ( ) . retrieveEntity ( pAddParam , entityPb ) ; boolean isNew = true ; if ( entityPbDb != null ) { entityPb . setItsVersion ( entityPbDb . getItsVersion ( ) ) ; isNew = false ; } return isNew ;


signature:
public class DeclarationFilter { /** * Returns a filter that selects declarations containing all of a
 * collection of modifiers .
 * @ param mods the modifiers to match ( non - null )
 * @ return a filter that matches declarations containing < tt > mods < / tt > */
public static DeclarationFilter getFilter ( final Collection < Modifier > mods ) { } }

implementation: return new DeclarationFilter ( ) { public boolean matches ( Declaration d ) { return d . getModifiers ( ) . containsAll ( mods ) ; } } ;


signature:
public class DeclarationFilter { /** * Returns a filter that selects declarations of a particular kind .
 * For example , there may be a filter that selects only class
 * declarations , or only fields .
 * The filter will select declarations of the specified kind ,
 * and also any subtypes of that kind ; for example , a field filter
 * will also select enum constants .
 * @ param kind the kind of declarations to select
 * @ return a filter that selects declarations of a particular kind */
public static DeclarationFilter getFilter ( final Class < ? extends Declaration > kind ) { } }

implementation: return new DeclarationFilter ( ) { public boolean matches ( Declaration d ) { return kind . isInstance ( d ) ; } } ;