signature:
public class ClassWriter { /** * Returns the common super type of the two given types . The default implementation of this method
 * < i > loads < / i > the two given classes and uses the java . lang . Class methods to find the common
 * super class . It can be overridden to compute this common super type in other ways , in
 * particular without actually loading any class , or to take into account the class that is
 * currently being generated by this ClassWriter , which can of course not be loaded since it is
 * under construction .
 * @ param type1 the internal name of a class .
 * @ param type2 the internal name of another class .
 * @ return the internal name of the common super class of the two given classes . */
protected String getCommonSuperClass ( final String type1 , final String type2 ) { } }

implementation: ClassLoader classLoader = getClassLoader ( ) ; Class < ? > class1 ; try { class1 = Class . forName ( type1 . replace ( '/' , '.' ) , false , classLoader ) ; } catch ( ClassNotFoundException e ) { throw new TypeNotPresentException ( type1 , e ) ; } Class < ? > class2 ; try { class2 = Class . forName ( type2 . replace ( '/' , '.' ) , false , classLoader ) ; } catch ( ClassNotFoundException e ) { throw new TypeNotPresentException ( type2 , e ) ; } if ( class1 . isAssignableFrom ( class2 ) ) { return type1 ; } if ( class2 . isAssignableFrom ( class1 ) ) { return type2 ; } if ( class1 . isInterface ( ) || class2 . isInterface ( ) ) { return "java/lang/Object" ; } else { do { class1 = class1 . getSuperclass ( ) ; } while ( ! class1 . isAssignableFrom ( class2 ) ) ; return class1 . getName ( ) . replace ( '.' , '/' ) ; }


signature:
public class SqlTypeManager { /** * Registers default set of SQL types . */
public void registerDefaults ( ) { } }

implementation: register ( Integer . class , IntegerSqlType . class ) ; register ( int . class , IntegerSqlType . class ) ; register ( MutableInteger . class , IntegerSqlType . class ) ; register ( Float . class , FloatSqlType . class ) ; register ( float . class , FloatSqlType . class ) ; register ( MutableFloat . class , FloatSqlType . class ) ; register ( Double . class , DoubleSqlType . class ) ; register ( double . class , DoubleSqlType . class ) ; register ( MutableDouble . class , DoubleSqlType . class ) ; register ( Byte . class , ByteSqlType . class ) ; register ( byte . class , ByteSqlType . class ) ; register ( MutableByte . class , ByteSqlType . class ) ; register ( Boolean . class , BooleanSqlType . class ) ; register ( boolean . class , BooleanSqlType . class ) ; register ( MutableBoolean . class , BooleanSqlType . class ) ; register ( Long . class , LongSqlType . class ) ; register ( long . class , LongSqlType . class ) ; register ( MutableLong . class , LongSqlType . class ) ; register ( Short . class , ShortSqlType . class ) ; register ( short . class , ShortSqlType . class ) ; register ( MutableShort . class , ShortSqlType . class ) ; register ( Character . class , CharacterSqlType . class ) ; register ( char . class , CharacterSqlType . class ) ; register ( BigDecimal . class , BigDecimalSqlType . class ) ; register ( BigInteger . class , BigIntegerSqlType . class ) ; register ( String . class , StringSqlType . class ) ; register ( LocalDateTime . class , LocalDateTimeSqlType . class ) ; register ( LocalDate . class , LocalDateSqlType . class ) ; register ( LocalTime . class , LocalTimeSqlType . class ) ; register ( Date . class , SqlDateSqlType . class ) ; register ( Timestamp . class , TimestampSqlType . class ) ; register ( Time . class , TimeSqlType . class ) ; register ( java . util . Date . class , DateSqlType . class ) ; register ( JulianDate . class , JulianDateSqlType . class ) ; register ( byte [ ] . class , ByteArraySqlType . class ) ; register ( URL . class , URLSqlType . class ) ; register ( Blob . class , BlobSqlType . class ) ; register ( Clob . class , ClobSqlType . class ) ; register ( Array . class , SqlArraySqlType . class ) ; register ( Ref . class , SqlRefSqlType . class ) ;


signature:
public class SqlTypeManager { /** * Registers sql type for provided type . */
public void register ( final Class type , final Class < ? extends SqlType > sqlTypeClass ) { } }

implementation: types . put ( type , lookupSqlType ( sqlTypeClass ) ) ;


signature:
public class SqlTypeManager { /** * Retrieves SQL type for provided type . All subclasses and interfaces are examined
 * for matching sql type . */
public SqlType lookup ( final Class clazz ) { } }

implementation: SqlType sqlType ; for ( Class x = clazz ; x != null ; x = x . getSuperclass ( ) ) { sqlType = types . get ( clazz ) ; if ( sqlType != null ) { return sqlType ; } Class [ ] interfaces = x . getInterfaces ( ) ; for ( Class i : interfaces ) { sqlType = types . get ( i ) ; if ( sqlType != null ) { return sqlType ; } } } return null ;


signature:
public class SqlTypeManager { /** * Returns sql type instance . Instances are stored for better performances . */
public SqlType lookupSqlType ( final Class < ? extends SqlType > sqlTypeClass ) { } }

implementation: SqlType sqlType = sqlTypes . get ( sqlTypeClass ) ; if ( sqlType == null ) { try { sqlType = ClassUtil . newInstance ( sqlTypeClass ) ; } catch ( Exception ex ) { throw new DbSqlException ( "SQL type not found: " + sqlTypeClass . getSimpleName ( ) , ex ) ; } sqlTypes . put ( sqlTypeClass , sqlType ) ; } return sqlType ;


signature:
public class ProxyInfo { /** * Creates SOCKS4 proxy . */
public static ProxyInfo socks4Proxy ( final String proxyAddress , final int proxyPort , final String proxyUser ) { } }

implementation: return new ProxyInfo ( ProxyType . SOCKS4 , proxyAddress , proxyPort , proxyUser , null ) ;


signature:
public class ProxyInfo { /** * Creates SOCKS5 proxy . */
public static ProxyInfo socks5Proxy ( final String proxyAddress , final int proxyPort , final String proxyUser , final String proxyPassword ) { } }

implementation: return new ProxyInfo ( ProxyType . SOCKS5 , proxyAddress , proxyPort , proxyUser , proxyPassword ) ;


signature:
public class ProxyInfo { /** * Creates HTTP proxy . */
public static ProxyInfo httpProxy ( final String proxyAddress , final int proxyPort , final String proxyUser , final String proxyPassword ) { } }

implementation: return new ProxyInfo ( ProxyType . HTTP , proxyAddress , proxyPort , proxyUser , proxyPassword ) ;


signature:
public class JtxTransactionManager { /** * Returns total number of transactions associated with current thread . */
public int totalThreadTransactions ( ) { } }

implementation: ArrayList < JtxTransaction > txList = txStack . get ( ) ; if ( txList == null ) { return 0 ; } return txList . size ( ) ;


signature:
public class JtxTransactionManager { /** * Returns total number of transactions of the specified status associated with current thread . */
public int totalThreadTransactionsWithStatus ( final JtxStatus status ) { } }

implementation: ArrayList < JtxTransaction > txlist = txStack . get ( ) ; if ( txlist == null ) { return 0 ; } int count = 0 ; for ( JtxTransaction tx : txlist ) { if ( tx . getStatus ( ) == status ) { count ++ ; } } return count ;


signature:
public class JtxTransactionManager { /** * Returns < code > true < / code > if provided transaction
 * is associated with current thread . */
public boolean isAssociatedWithThread ( final JtxTransaction tx ) { } }

implementation: ArrayList < JtxTransaction > txList = txStack . get ( ) ; if ( txList == null ) { return false ; } return txList . contains ( tx ) ;


signature:
public class JtxTransactionManager { /** * Removes transaction association with current thread .
 * Transaction should be properly handled ( committed or rolledback )
 * before removing from current thread .
 * Also removes thread list from this thread . */
protected boolean removeTransaction ( final JtxTransaction tx ) { } }

implementation: ArrayList < JtxTransaction > txList = txStack . get ( ) ; if ( txList == null ) { return false ; } boolean removed = txList . remove ( tx ) ; if ( removed ) { totalTransactions -- ; } if ( txList . isEmpty ( ) ) { txStack . remove ( ) ; } return removed ;


signature:
public class JtxTransactionManager { /** * Returns last transaction associated with current thread or
 * < code > null < / code > when thread has no associated transactions created
 * by this transaction manager . */
public JtxTransaction getTransaction ( ) { } }

implementation: ArrayList < JtxTransaction > txlist = txStack . get ( ) ; if ( txlist == null ) { return null ; } if ( txlist . isEmpty ( ) ) { return null ; } return txlist . get ( txlist . size ( ) - 1 ) ; // get last


signature:
public class JtxTransactionManager { /** * Associate transaction to current thread . */
protected void associateTransaction ( final JtxTransaction tx ) { } }

implementation: totalTransactions ++ ; ArrayList < JtxTransaction > txList = txStack . get ( ) ; if ( txList == null ) { txList = new ArrayList < > ( ) ; txStack . set ( txList ) ; } txList . add ( tx ) ; // add last


signature:
public class JtxTransactionManager { /** * Creates new { @ link jodd . jtx . JtxTransaction } instance .
 * Custom implementations of manager may override this method for
 * creating custom transaction instances . */
protected JtxTransaction createNewTransaction ( final JtxTransactionMode tm , final Object scope , final boolean active ) { } }

implementation: return new JtxTransaction ( this , tm , scope , active ) ;


signature:
public class JtxTransactionManager { /** * Requests transaction with specified { @ link JtxTransactionMode mode } .
 * Depending on propagation behavior , it will return either < b > existing < / b > or < b > new < / b > transaction .
 * Only one transaction can be opened over one scope .
 * The exception may be thrown indicating propagation mismatch . */
public JtxTransaction requestTransaction ( final JtxTransactionMode mode , final Object scope ) { } }

implementation: if ( log . isDebugEnabled ( ) ) { log . debug ( "Requesting TX " + mode . toString ( ) ) ; } JtxTransaction currentTx = getTransaction ( ) ; if ( ! isNewTxScope ( currentTx , scope ) ) { return currentTx ; } switch ( mode . getPropagationBehavior ( ) ) { case PROPAGATION_REQUIRED : return propRequired ( currentTx , mode , scope ) ; case PROPAGATION_SUPPORTS : return propSupports ( currentTx , mode , scope ) ; case PROPAGATION_MANDATORY : return propMandatory ( currentTx , mode , scope ) ; case PROPAGATION_REQUIRES_NEW : return propRequiresNew ( currentTx , mode , scope ) ; case PROPAGATION_NOT_SUPPORTED : return propNotSupported ( currentTx , mode , scope ) ; case PROPAGATION_NEVER : return propNever ( currentTx , mode , scope ) ; } throw new JtxException ( "Invalid TX propagation value: " + mode . getPropagationBehavior ( ) . value ( ) ) ;


signature:
public class JtxTransactionManager { /** * Returns < code > true < / code > if scope is specified and it is different then of existing transaction . */
protected boolean isNewTxScope ( final JtxTransaction currentTx , final Object destScope ) { } }

implementation: if ( ignoreScope ) { return true ; } if ( currentTx == null ) { return true ; } if ( destScope == null ) { return true ; } if ( currentTx . getScope ( ) == null ) { return true ; } return ! destScope . equals ( currentTx . getScope ( ) ) ;


signature:
public class JtxTransactionManager { /** * Check if propagation of a transaction is possible , due to source and destination transaction modes .
 * @ see # setValidateExistingTransaction ( boolean ) */
protected void continueTx ( final JtxTransaction sourceTx , final JtxTransactionMode destMode ) { } }

implementation: if ( ! validateExistingTransaction ) { return ; } JtxTransactionMode sourceMode = sourceTx . getTransactionMode ( ) ; JtxIsolationLevel destIsolationLevel = destMode . getIsolationLevel ( ) ; if ( destIsolationLevel != ISOLATION_DEFAULT ) { JtxIsolationLevel currentIsolationLevel = sourceMode . getIsolationLevel ( ) ; if ( currentIsolationLevel != destIsolationLevel ) { throw new JtxException ( "Participating TX specifies isolation level: " + destIsolationLevel + " which is incompatible with existing TX: " + currentIsolationLevel ) ; } } if ( ( ! destMode . isReadOnly ( ) ) && ( sourceMode . isReadOnly ( ) ) ) { throw new JtxException ( "Participating TX is not marked as read-only, but existing TX is" ) ; }


signature:
public class JtxTransactionManager { /** * Propagation : REQUIRED
 * < pre > { @ code
 * None - > T2
 * T1 - > T1 ( cont . )
 * } < / pre > */
protected JtxTransaction propRequired ( JtxTransaction currentTx , final JtxTransactionMode mode , final Object scope ) { } }

implementation: if ( ( currentTx == null ) || ( currentTx . isNoTransaction ( ) ) ) { currentTx = createNewTransaction ( mode , scope , true ) ; } else { continueTx ( currentTx , mode ) ; } return currentTx ;


signature:
public class JtxTransactionManager { /** * Propagation : REQUIRES _ NEW
 * < pre > { @ code
 * None - > T2
 * T1 - > T2
 * } < / pre > */
@ SuppressWarnings ( { } }

implementation: "UnusedDeclaration" } ) protected JtxTransaction propRequiresNew ( final JtxTransaction currentTx , final JtxTransactionMode mode , final Object scope ) { return createNewTransaction ( mode , scope , true ) ;


signature:
public class JtxTransactionManager { /** * Propagation : SUPPORTS
 * < pre > { @ code
 * None - > None
 * T1 - > T1 ( cont . )
 * } < / pre > */
protected JtxTransaction propSupports ( JtxTransaction currentTx , final JtxTransactionMode mode , final Object scope ) { } }

implementation: if ( ( currentTx != null ) && ( ! currentTx . isNoTransaction ( ) ) ) { continueTx ( currentTx , mode ) ; } if ( currentTx == null ) { currentTx = createNewTransaction ( mode , scope , false ) ; } return currentTx ;


signature:
public class JtxTransactionManager { /** * Propagation : MANDATORY
 * < pre > { @ code
 * None - > Error
 * T1 - > T1 ( cont . )
 * } < / pre > */
@ SuppressWarnings ( { } }

implementation: "UnusedDeclaration" } ) protected JtxTransaction propMandatory ( final JtxTransaction currentTx , final JtxTransactionMode mode , final Object scope ) { if ( ( currentTx == null ) || ( currentTx . isNoTransaction ( ) ) ) { throw new JtxException ( "No existing TX found for TX marked with propagation 'mandatory'" ) ; } continueTx ( currentTx , mode ) ; return currentTx ;


signature:
public class JtxTransactionManager { /** * Propagation : NOT _ SUPPORTED
 * < pre > { @ code
 * None - > None
 * T1 - > None
 * } < / pre > */
protected JtxTransaction propNotSupported ( final JtxTransaction currentTx , final JtxTransactionMode mode , final Object scope ) { } }

implementation: if ( currentTx == null ) { return createNewTransaction ( mode , scope , false ) ; } if ( currentTx . isNoTransaction ( ) ) { return currentTx ; } return createNewTransaction ( mode , scope , false ) ;


signature:
public class JtxTransactionManager { /** * Propagation : NEVER
 * < pre > { @ code
 * None - > None
 * T1 - > Error
 * } < / pre > */
protected JtxTransaction propNever ( JtxTransaction currentTx , final JtxTransactionMode mode , final Object scope ) { } }

implementation: if ( ( currentTx != null ) && ( ! currentTx . isNoTransaction ( ) ) ) { throw new JtxException ( "Existing TX found for TX marked with propagation 'never'" ) ; } if ( currentTx == null ) { currentTx = createNewTransaction ( mode , scope , false ) ; } return currentTx ;


signature:
public class JtxTransactionManager { /** * Registers new { @ link JtxResourceManager resource manager } . */
public void registerResourceManager ( final JtxResourceManager resourceManager ) { } }

implementation: if ( ( oneResourceManager ) && ( ! resourceManagers . isEmpty ( ) ) ) { throw new JtxException ( "TX manager allows only one resource manager" ) ; } this . resourceManagers . put ( resourceManager . getResourceType ( ) , resourceManager ) ;


signature:
public class JtxTransactionManager { /** * Lookups resource manager for provided type . Throws an exception if provider doesn ' t exists . */
protected < E > JtxResourceManager < E > lookupResourceManager ( final Class < E > resourceType ) { } }

implementation:
// noinspection unchecked
JtxResourceManager < E > resourceManager = this . resourceManagers . get ( resourceType ) ; if ( resourceManager == null ) { throw new JtxException ( "No registered resource manager for resource type: " + resourceType . getSimpleName ( ) ) ; } return resourceManager ;


signature:
public class JtxTransactionManager { /** * Closes transaction manager . All registered { @ link JtxResourceManager }
 * will be closed . */
public void close ( ) { } }

implementation:
this . resourceManagers . forEachValue ( resourceManager -> { try { resourceManager . close ( ) ; } catch ( Exception ex ) { // ignore
} } ) ; resourceManagers . clear ( ) ;


signature:
public class Pathref { /** * Creates proxy object . */
protected C createProxyObject ( Class < C > target ) { } }

implementation: target = ProxettaUtil . resolveTargetClass ( target ) ; Class proxyClass = cache . get ( target ) ; if ( proxyClass == null ) { proxyClass = proxetta . defineProxy ( target ) ; cache . put ( target , proxyClass ) ; } C proxy ; try { proxy = ( C ) ClassUtil . newInstance ( proxyClass ) ; } catch ( Exception ex ) { throw new PathrefException ( ex ) ; } return proxy ;


signature:
public class Pathref { /** * Appends method name to existing path . */
protected void append ( final String methodName ) { } }

implementation: if ( path . length ( ) != 0 ) { path += StringPool . DOT ; } if ( methodName . startsWith ( StringPool . LEFT_SQ_BRACKET ) ) { path = StringUtil . substring ( path , 0 , - 1 ) ; } path += methodName ;


signature:
public class Pathref { /** * Static factory of next target . It handles special cases of maps , sets
 * and lists . In case target can not be proxified ( like for Java classes )
 * it returns < code > null < / code > . */
@ SuppressWarnings ( "unchecked" ) public < T > T continueWith ( final Object currentInstance , final String methodName , final Class < T > target ) { } }

implementation: Class currentClass = currentInstance . getClass ( ) ; Method method ; try { method = currentClass . getDeclaredMethod ( methodName ) ; } catch ( NoSuchMethodException e ) { throw new PathrefException ( "Not a getter: " + methodName , e ) ; } if ( ! ClassUtil . isBeanPropertyGetter ( method ) ) { throw new PathrefException ( "Not a getter: " + methodName ) ; } String getterName = ClassUtil . getBeanPropertyGetterName ( method ) ; append ( getterName ) ; if ( ClassUtil . isTypeOf ( target , List . class ) ) { final Class componentType = ClassUtil . getComponentType ( method . getGenericReturnType ( ) , currentClass , 0 ) ; if ( componentType == null ) { throw new PathrefException ( "Unknown component name for: " + methodName ) ; } return ( T ) new ArrayList ( ) { @ Override public Object get ( final int index ) { if ( index >= 0 ) { append ( "[" + index + "]" ) ; } return new Pathref < > ( componentType , Pathref . this ) . to ( ) ; } } ; } try { return new Pathref < > ( target , this ) . to ( ) ; } catch ( Exception ex ) { return null ; }


signature:
public class Base64Benchmark { /** * - - - - - Apache Commons Codec - Base64 */
@ Benchmark public String encode_Apache_Base64 ( ) { } }

implementation: return org . apache . commons . codec . binary . Base64 . encodeBase64String ( to_be_encoded ) ;


signature:
public class Format { /** * Puts the text to the left and pads with spaces until the size is reached . */
public static String alignLeftAndPad ( final String text , final int size ) { } }

implementation: int textLength = text . length ( ) ; if ( textLength > size ) { return text . substring ( 0 , size ) ; } final StringBuilder sb = new StringBuilder ( size ) ; sb . append ( text ) ; while ( textLength ++ < size ) { sb . append ( ' ' ) ; } return sb . toString ( ) ;


signature:
public class Format { /** * Formats byte size to human readable bytecount .
 * https : / / stackoverflow . com / questions / 3758606 / how - to - convert - byte - size - into - human - readable - format - in - java / 3758880#3758880 */
public static String humanReadableByteCount ( final long bytes , final boolean useSi ) { } }

implementation: final int unit = useSi ? 1000 : 1024 ; if ( bytes < unit ) return bytes + " B" ; final int exp = ( int ) ( Math . log ( bytes ) / Math . log ( unit ) ) ; final String pre = ( useSi ? "kMGTPE" : "KMGTPE" ) . charAt ( exp - 1 ) + ( useSi ? "" : "i" ) ; return String . format ( "%.1f %sB" , bytes / Math . pow ( unit , exp ) , pre ) ;


signature:
public class Format { /** * Converts object into pretty string . All arrays are iterated . */
public static String toPrettyString ( final Object value ) { } }

implementation: if ( value == null ) { return StringPool . NULL ; } final Class < ? > type = value . getClass ( ) ; if ( type . isArray ( ) ) { final Class componentType = type . getComponentType ( ) ; if ( componentType . isPrimitive ( ) ) { final StringBuilder sb = new StringBuilder ( ) ; sb . append ( '[' ) ; if ( componentType == int . class ) { sb . append ( ArraysUtil . toString ( ( int [ ] ) value ) ) ; } else if ( componentType == long . class ) { sb . append ( ArraysUtil . toString ( ( long [ ] ) value ) ) ; } else if ( componentType == double . class ) { sb . append ( ArraysUtil . toString ( ( double [ ] ) value ) ) ; } else if ( componentType == float . class ) { sb . append ( ArraysUtil . toString ( ( float [ ] ) value ) ) ; } else if ( componentType == boolean . class ) { sb . append ( ArraysUtil . toString ( ( boolean [ ] ) value ) ) ; } else if ( componentType == short . class ) { sb . append ( ArraysUtil . toString ( ( short [ ] ) value ) ) ; } else if ( componentType == byte . class ) { sb . append ( ArraysUtil . toString ( ( byte [ ] ) value ) ) ; } else { throw new IllegalArgumentException ( ) ; } sb . append ( ']' ) ; return sb . toString ( ) ; } else { final StringBuilder sb = new StringBuilder ( ) ; sb . append ( '[' ) ; final Object [ ] array = ( Object [ ] ) value ; for ( int i = 0 ; i < array . length ; i ++ ) { if ( i > 0 ) { sb . append ( ',' ) ; } sb . append ( toPrettyString ( array [ i ] ) ) ; } sb . append ( ']' ) ; return sb . toString ( ) ; } } else if ( value instanceof Iterable ) { final Iterable iterable = ( Iterable ) value ; final StringBuilder sb = new StringBuilder ( ) ; sb . append ( '{' ) ; int i = 0 ; for ( final Object o : iterable ) { if ( i > 0 ) { sb . append ( ',' ) ; } sb . append ( toPrettyString ( o ) ) ; i ++ ; } sb . append ( '}' ) ; return sb . toString ( ) ; } return value . toString ( ) ;


signature:
public class Format { /** * Changes CamelCase string to lower case words separated by provided
 * separator character . The following translations are applied :
 * < ul >
 * < li > Every upper case letter in the CamelCase name is translated into
 * two characters , a separator and the lower case equivalent of the target character ,
 * with three exceptions .
 * < ol > < li > For contiguous sequences of upper case letters , characters after the first
 * character are replaced only by their lower case equivalent , and are not
 * preceded by a separator ( < code > theFOO < / code > to < code > the _ foo < / code > ) .
 * < li > An upper case character in the first position of the CamelCase name
 * is not preceded by a separator character , and is translated only to its
 * lower case equivalent . ( < code > Foo < / code > to < code > foo < / code > and not < code > _ foo < / code > )
 * < li > An upper case character in the CamelCase name that is already preceded
 * by a separator character is translated only to its lower case equivalent ,
 * and is not preceded by an additional separator . ( < code > user _ Name < / code >
 * to < code > user _ name < / code > and not < code > user _ _ name < / code > .
 * < / ol >
 * < li > If the CamelCase name starts with a separator , then that
 * separator is not included in the translated name , unless the CamelCase
 * name is just one character in length , i . e . , it is the separator character .
 * This applies only to the first character of the CamelCase name .
 * < / ul > */
public static String fromCamelCase ( final String input , final char separator ) { } }

implementation:
final int length = input . length ( ) ; final StringBuilder result = new StringBuilder ( length * 2 ) ; int resultLength = 0 ; boolean prevTranslated = false ; for ( int i = 0 ; i < length ; i ++ ) { char c = input . charAt ( i ) ; if ( i > 0 || c != separator ) { // skip first starting separator
if ( Character . isUpperCase ( c ) ) { if ( ! prevTranslated && resultLength > 0 && result . charAt ( resultLength - 1 ) != separator ) { result . append ( separator ) ; resultLength ++ ; } c = Character . toLowerCase ( c ) ; prevTranslated = true ; } else { prevTranslated = false ; } result . append ( c ) ; resultLength ++ ; } } return resultLength > 0 ? result . toString ( ) : input ;


signature:
public class Format { /** * Converts separated string value to CamelCase . */
public static String toCamelCase ( final String input , final boolean firstCharUppercase , final char separator ) { } }

implementation: final int length = input . length ( ) ; final StringBuilder sb = new StringBuilder ( length ) ; boolean upperCase = firstCharUppercase ; for ( int i = 0 ; i < length ; i ++ ) { final char ch = input . charAt ( i ) ; if ( ch == separator ) { upperCase = true ; } else if ( upperCase ) { sb . append ( Character . toUpperCase ( ch ) ) ; upperCase = false ; } else { sb . append ( ch ) ; } } return sb . toString ( ) ;


signature:
public class Format { /** * Formats provided string as paragraph . */
public static String formatParagraph ( final String src , final int len , final boolean breakOnWhitespace ) { } }

implementation: StringBuilder str = new StringBuilder ( ) ; int total = src . length ( ) ; int from = 0 ; while ( from < total ) { int to = from + len ; if ( to >= total ) { to = total ; } else if ( breakOnWhitespace ) { int ndx = StringUtil . lastIndexOfWhitespace ( src , to - 1 , from ) ; if ( ndx != - 1 ) { to = ndx + 1 ; } } int cutFrom = StringUtil . indexOfNonWhitespace ( src , from , to ) ; if ( cutFrom != - 1 ) { int cutTo = StringUtil . lastIndexOfNonWhitespace ( src , to - 1 , from ) + 1 ; str . append ( src , cutFrom , cutTo ) ; } str . append ( '\n' ) ; from = to ; } return str . toString ( ) ;


signature:
public class Format { /** * Converts all tabs on a line to spaces according to the provided tab width .
 * This is not a simple tab to spaces replacement , since the resulting
 * indentation remains the same . */
public static String convertTabsToSpaces ( final String line , final int tabWidth ) { } }

implementation: int tab_index , tab_size ; int last_tab_index = 0 ; int added_chars = 0 ; if ( tabWidth == 0 ) { return StringUtil . remove ( line , '\t' ) ; } StringBuilder result = new StringBuilder ( ) ; while ( ( tab_index = line . indexOf ( '\t' , last_tab_index ) ) != - 1 ) { tab_size = tabWidth - ( ( tab_index + added_chars ) % tabWidth ) ; if ( tab_size == 0 ) { tab_size = tabWidth ; } added_chars += tab_size - 1 ; result . append ( line , last_tab_index , tab_index ) ; result . append ( StringUtil . repeat ( ' ' , tab_size ) ) ; last_tab_index = tab_index + 1 ; } if ( last_tab_index == 0 ) { return line ; } result . append ( line . substring ( last_tab_index ) ) ; return result . toString ( ) ;


signature:
public class Format { /** * Escapes a string using java rules . */
public static String escapeJava ( final String string ) { } }

implementation: int strLen = string . length ( ) ; StringBuilder sb = new StringBuilder ( strLen ) ; for ( int i = 0 ; i < strLen ; i ++ ) { char c = string . charAt ( i ) ; switch ( c ) { case '\b' : sb . append ( "\\b" ) ; break ; case '\t' : sb . append ( "\\t" ) ; break ; case '\n' : sb . append ( "\\n" ) ; break ; case '\f' : sb . append ( "\\f" ) ; break ; case '\r' : sb . append ( "\\r" ) ; break ; case '\"' : sb . append ( "\\\"" ) ; break ; case '\\' : sb . append ( "\\\\" ) ; break ; default : if ( ( c < 32 ) || ( c > 127 ) ) { String hex = Integer . toHexString ( c ) ; sb . append ( "\\u" ) ; for ( int k = hex . length ( ) ; k < 4 ; k ++ ) { sb . append ( '0' ) ; } sb . append ( hex ) ; } else { sb . append ( c ) ; } } } return sb . toString ( ) ;


signature:
public class Format { /** * Unescapes a string using java rules . */
public static String unescapeJava ( final String str ) { } }

implementation: char [ ] chars = str . toCharArray ( ) ; StringBuilder sb = new StringBuilder ( str . length ( ) ) ; for ( int i = 0 ; i < chars . length ; i ++ ) { char c = chars [ i ] ; if ( c != '\\' ) { sb . append ( c ) ; continue ; } i ++ ; c = chars [ i ] ; switch ( c ) { case 'b' : sb . append ( '\b' ) ; break ; case 't' : sb . append ( '\t' ) ; break ; case 'n' : sb . append ( '\n' ) ; break ; case 'f' : sb . append ( '\f' ) ; break ; case 'r' : sb . append ( '\r' ) ; break ; case '"' : sb . append ( '\"' ) ; break ; case '\\' : sb . append ( '\\' ) ; break ; case 'u' : char hex = ( char ) Integer . parseInt ( new String ( chars , i + 1 , 4 ) , 16 ) ; sb . append ( hex ) ; i += 4 ; break ; default : throw new IllegalArgumentException ( "Invalid escaping character: " + c ) ; } } return sb . toString ( ) ;


signature:
public class TransactionAnnotationValues { /** * Shortcut for checking the annotation on annotated element and returning either the values or { @ code null } . */
public static TransactionAnnotationValues of ( final AnnotationParser annotationParser , final AnnotatedElement annotatedElement ) { } }

implementation: if ( ! annotationParser . hasAnnotationOn ( annotatedElement ) ) { return null ; } return new TransactionAnnotationValues ( annotationParser . of ( annotatedElement ) ) ;


signature:
public class PetiteContainer { /** * - - - - - core */
protected Object lookupMixingScopedBean ( final BeanDefinition def , final BeanReferences refNames ) { } }

implementation: final boolean mixing = petiteConfig . wireScopedProxy || petiteConfig . detectMixedScopes ; Object value = null ; if ( mixing ) { final BeanDefinition refBeanDefinition = lookupBeanDefinitions ( refNames ) ; if ( refBeanDefinition != null ) { value = scopedProxyManager . lookupValue ( PetiteContainer . this , def , refBeanDefinition ) ; } } if ( value == null ) { value = PetiteContainer . this . getBean ( refNames ) ; } return value ;


signature:
public class PetiteContainer { /** * Returns Petite bean instance . Bean name will be resolved from provided type . */
@ SuppressWarnings ( { } }

implementation: "unchecked" } ) public < T > T getBean ( final Class < T > type ) { String name = resolveBeanName ( type ) ; return ( T ) getBean ( name ) ;


signature:
public class PetiteContainer { /** * Returns Petite bean instance named as one of the provided names .
 * Returns { @ code null } if bean is not found . */
protected Object getBean ( final BeanReferences beanReferences ) { } }

implementation: final int total = beanReferences . size ( ) ; for ( int i = 0 ; i < total ; i ++ ) { String name = beanReferences . name ( i ) ; if ( name != null ) { Object bean = getBean ( name ) ; if ( bean != null ) { return bean ; } } } return null ;


signature:
public class PetiteContainer { /** * Returns Petite bean instance .
 * Petite container will find the bean in corresponding scope and all its dependencies ,
 * either by constructor or property injection . When using constructor injection , cyclic dependencies
 * can not be prevented , but at least they are detected .
 * @ see PetiteContainer # createBean ( Class ) */
public < T > T getBean ( final String name ) { } }

implementation:
// Lookup for registered bean definition .
BeanDefinition def = lookupBeanDefinition ( name ) ; if ( def == null ) { // try provider
ProviderDefinition providerDefinition = providers . get ( name ) ; if ( providerDefinition != null ) { return ( T ) invokeProvider ( providerDefinition ) ; } return null ; } // Find the bean in its scope
Object bean = def . scopeLookup ( ) ; if ( bean == null ) { // Create new bean in the scope
initBeanDefinition ( def ) ; final BeanData beanData = new BeanData ( this , def ) ; registerBeanAndWireAndInjectParamsAndInvokeInitMethods ( beanData ) ; bean = beanData . bean ( ) ; } return ( T ) bean ;


signature:
public class PetiteContainer { /** * Resolves and initializes bean definition . May be called multiple times . */
protected void initBeanDefinition ( final BeanDefinition def ) { } }

implementation:
// init methods
if ( def . initMethods == null ) { def . initMethods = petiteResolvers . resolveInitMethodPoint ( def . type ) ; } // destroy methods
if ( def . destroyMethods == null ) { def . destroyMethods = petiteResolvers . resolveDestroyMethodPoint ( def . type ) ; } // properties
if ( def . properties == null ) { def . properties = petiteResolvers . resolvePropertyInjectionPoint ( def . type , def . wiringMode == WiringMode . AUTOWIRE ) ; } // methods
if ( def . methods == null ) { def . methods = petiteResolvers . resolveMethodInjectionPoint ( def . type ) ; } // ctors
if ( def . ctor == null ) { def . ctor = petiteResolvers . resolveCtorInjectionPoint ( def . type ) ; } // values
if ( def . values == null ) { def . values = paramManager . resolveParamInjectionPoints ( def . type ) ; } // sets
if ( def . sets == null ) { def . sets = petiteResolvers . resolveSetInjectionPoint ( def . type , def . wiringMode == WiringMode . AUTOWIRE ) ; } // params
if ( def . params == null ) { def . params = paramManager . filterParametersForBeanName ( def . name , petiteConfig . getResolveReferenceParameters ( ) ) ; }


signature:
public class PetiteContainer { /** * Wires bean , injects parameters and invokes init methods .
 * Such a loooong name : ) */
protected void registerBeanAndWireAndInjectParamsAndInvokeInitMethods ( final BeanData beanData ) { } }

implementation: initBeanDefinition ( beanData . definition ( ) ) ; beanData . scopeRegister ( ) ; beanData . invokeInitMethods ( InitMethodInvocationStrategy . POST_CONSTRUCT ) ; beanData . wireBean ( ) ; beanData . invokeInitMethods ( InitMethodInvocationStrategy . POST_DEFINE ) ; beanData . injectParams ( paramManager , petiteConfig . isImplicitParamInjection ( ) ) ; beanData . invokeInitMethods ( InitMethodInvocationStrategy . POST_INITIALIZE ) ; beanData . invokeConsumerIfRegistered ( ) ;


signature:
public class PetiteContainer { /** * Wires provided bean with the container and optionally invokes init methods .
 * Bean is < b > not < / b > registered withing container . */
public void wire ( final Object bean , final WiringMode wiringMode ) { } }

implementation: final WiringMode finalWiringMode = petiteConfig . resolveWiringMode ( wiringMode ) ; final BeanDefinition def = externalsCache . get ( bean . getClass ( ) , ( ) -> { final BeanDefinition beanDefinition = createBeandDefinitionForExternalBeans ( bean . getClass ( ) , finalWiringMode ) ; initBeanDefinition ( beanDefinition ) ; return beanDefinition ; } ) ; registerBeanAndWireAndInjectParamsAndInvokeInitMethods ( new BeanData ( this , def , bean ) ) ;


signature:
public class PetiteContainer { /** * Invokes the method of some bean with the container , when its parameters requires to be injected into .
 * The bean is < b > not < / b > registered within container . */
public < T > T invokeMethod ( final Object bean , final Method method ) { } }

implementation: final WiringMode wiringMode = petiteConfig . resolveWiringMode ( null ) ; final BeanDefinition def = externalsCache . get ( bean . getClass ( ) , ( ) -> { final BeanDefinition beanDefinition = createBeandDefinitionForExternalBeans ( bean . getClass ( ) , wiringMode ) ; initBeanDefinition ( beanDefinition ) ; return beanDefinition ; } ) ; final BeanData beanData = new BeanData ( this , def , bean ) ; for ( MethodInjectionPoint methodInjectionPoint : def . methods ) { if ( methodInjectionPoint . method . equals ( method ) ) { return ( T ) beanData . invokeMethodInjectionPoint ( methodInjectionPoint ) ; } } try { return ( T ) method . invoke ( bean ) ; } catch ( Exception e ) { throw new PetiteException ( e ) ; }


signature:
public class PetiteContainer { /** * Creates and wires a bean within the container and optionally invokes init methods . However , bean is
 * < b > not < / b > registered . */
@ SuppressWarnings ( { } }

implementation: "unchecked" } ) public < E > E createBean ( final Class < E > type , final WiringMode wiringMode ) { final WiringMode finalWiringMode = petiteConfig . resolveWiringMode ( wiringMode ) ; final BeanDefinition def = externalsCache . get ( type , ( ) -> { final BeanDefinition beanDefinition = createBeandDefinitionForExternalBeans ( type , finalWiringMode ) ; initBeanDefinition ( beanDefinition ) ; return beanDefinition ; } ) ; final BeanData < E > beanData = new BeanData ( this , def ) ; registerBeanAndWireAndInjectParamsAndInvokeInitMethods ( beanData ) ; return beanData . bean ( ) ;


signature:
public class PetiteContainer { /** * Invokes provider to get a bean . */
protected Object invokeProvider ( final ProviderDefinition provider ) { } }

implementation:
if ( provider . method != null ) { final Object bean ; if ( provider . beanName != null ) { // instance factory method
bean = getBean ( provider . beanName ) ; } else { // static factory method
bean = null ; } try { return provider . method . invoke ( bean ) ; } catch ( Exception ex ) { throw new PetiteException ( "Invalid provider method: " + provider . method . getName ( ) , ex ) ; } } throw new PetiteException ( "Invalid provider" ) ;


signature:
public class PetiteContainer { /** * Adds object instance to the container as singleton bean . */
public void addBean ( final String name , final Object bean , WiringMode wiringMode ) { } }

implementation: wiringMode = petiteConfig . resolveWiringMode ( wiringMode ) ; registerPetiteBean ( bean . getClass ( ) , name , SingletonScope . class , wiringMode , false , null ) ; BeanDefinition def = lookupExistingBeanDefinition ( name ) ; registerBeanAndWireAndInjectParamsAndInvokeInitMethods ( new BeanData ( this , def , bean ) ) ;


signature:
public class PetiteContainer { /** * Sets petite bean property . */
public void setBeanProperty ( final String name , final Object value ) { } }

implementation: Object bean = null ; int ndx = name . length ( ) ; while ( true ) { ndx = name . lastIndexOf ( '.' , ndx ) ; if ( ndx == - 1 ) { break ; } String beanName = name . substring ( 0 , ndx ) ; bean = getBean ( beanName ) ; if ( bean != null ) { break ; } ndx -- ; } if ( bean == null ) { throw new PetiteException ( "Invalid bean property: " + name ) ; } try { BeanUtil . declared . setProperty ( bean , name . substring ( ndx + 1 ) , value ) ; } catch ( Exception ex ) { throw new PetiteException ( "Invalid bean property: " + name , ex ) ; }


signature:
public class PetiteContainer { /** * Returns petite bean property value . */
public Object getBeanProperty ( final String name ) { } }

implementation: int ndx = name . indexOf ( '.' ) ; if ( ndx == - 1 ) { throw new PetiteException ( "Only bean name is specified, missing property name: " + name ) ; } String beanName = name . substring ( 0 , ndx ) ; Object bean = getBean ( beanName ) ; if ( bean == null ) { throw new PetiteException ( "Bean doesn't exist: " + name ) ; } try { return BeanUtil . declared . getProperty ( bean , name . substring ( ndx + 1 ) ) ; } catch ( Exception ex ) { throw new PetiteException ( "Invalid bean property: " + name , ex ) ; }


signature:
public class PetiteContainer { /** * Shutdowns container . After container is down , it can ' t be used anymore . */
public void shutdown ( ) { } }

implementation: scopes . forEachValue ( Scope :: shutdown ) ; externalsCache . clear ( ) ; beans . clear ( ) ; beansAlt . clear ( ) ; scopes . clear ( ) ; providers . clear ( ) ; beanCollections . clear ( ) ;


signature:
public class SmtpServer { /** * - - - - - properties */
@ Override protected Properties createSessionProperties ( ) { } }

implementation: final Properties props = super . createSessionProperties ( ) ; props . setProperty ( MAIL_TRANSPORT_PROTOCOL , PROTOCOL_SMTP ) ; props . setProperty ( MAIL_HOST , host ) ; props . setProperty ( MAIL_SMTP_HOST , host ) ; props . setProperty ( MAIL_SMTP_PORT , String . valueOf ( port ) ) ; if ( authenticator != null ) { props . setProperty ( MAIL_SMTP_AUTH , TRUE ) ; } if ( timeout > 0 ) { final String timeoutValue = String . valueOf ( timeout ) ; props . put ( MAIL_SMTP_CONNECTIONTIMEOUT , timeoutValue ) ; props . put ( MAIL_SMTP_TIMEOUT , timeoutValue ) ; props . put ( MAIL_SMTP_WRITETIMEOUT , timeoutValue ) ; } return props ;


signature:
public class SmtpServer { /** * { @ inheritDoc }
 * @ return { @ link SendMailSession } */
@ Override public SendMailSession createSession ( ) { } }

implementation: final Session session = Session . getInstance ( createSessionProperties ( ) , authenticator ) ; final Transport mailTransport ; try { mailTransport = getTransport ( session ) ; } catch ( final NoSuchProviderException nspex ) { throw new MailException ( nspex ) ; } return new SendMailSession ( session , mailTransport ) ;


signature:
public class JoyPaths { /** * - - - - - lifecycle */
@ Override public void start ( ) { } }

implementation: initLogger ( ) ; final String resourceName = StringUtil . replaceChar ( JoyPaths . class . getName ( ) , '.' , '/' ) + ".class" ; URL url = ClassLoaderUtil . getResourceUrl ( resourceName ) ; if ( url == null ) { throw new JoyException ( "Failed to resolve app dir, missing: " + resourceName ) ; } final String protocol = url . getProtocol ( ) ; if ( ! protocol . equals ( "file" ) ) { try { url = new URL ( url . getFile ( ) ) ; } catch ( MalformedURLException ignore ) { } } appDir = url . getFile ( ) ; final int ndx = appDir . indexOf ( "WEB-INF" ) ; appDir = ( ndx > 0 ) ? appDir . substring ( 0 , ndx ) : SystemUtil . info ( ) . getWorkingDir ( ) ; System . setProperty ( APP_DIR , appDir ) ; log . info ( "Application folder: " + appDir ) ;


signature:
public class JDKLogger { /** * Converts Jodd logging level to JDK . */
private java . util . logging . Level jodd2jdk ( final Level level ) { } }

implementation: switch ( level ) { case TRACE : return java . util . logging . Level . FINER ; case DEBUG : return java . util . logging . Level . FINE ; case INFO : return java . util . logging . Level . INFO ; case WARN : return java . util . logging . Level . WARNING ; case ERROR : return java . util . logging . Level . SEVERE ; default : throw new IllegalArgumentException ( ) ; }


signature:
public class DoubleSqlType { /** * { @ inheritDoc } */
@ Override public Double get ( final ResultSet rs , final int index , final int dbSqlType ) throws SQLException { } }

implementation: return Double . valueOf ( rs . getDouble ( index ) ) ;


signature:
public class DoubleSqlType { /** * { @ inheritDoc } */
@ Override public void set ( final PreparedStatement st , final int index , final Double value , final int dbSqlType ) throws SQLException { } }

implementation: st . setDouble ( index , value . doubleValue ( ) ) ;


signature:
public class Paramo { /** * Resolves method parameters from a method or constructor .
 * Returns an empty array when target does not contain any parameter .
 * No caching is involved in this process , i . e . class bytecode
 * is examined every time this method is called . */
public static MethodParameter [ ] resolveParameters ( final AccessibleObject methodOrCtor ) { } }

implementation: Class [ ] paramTypes ; Class declaringClass ; String name ; if ( methodOrCtor instanceof Method ) { Method method = ( Method ) methodOrCtor ; paramTypes = method . getParameterTypes ( ) ; name = method . getName ( ) ; declaringClass = method . getDeclaringClass ( ) ; } else { Constructor constructor = ( Constructor ) methodOrCtor ; paramTypes = constructor . getParameterTypes ( ) ; declaringClass = constructor . getDeclaringClass ( ) ; name = CTOR_METHOD ; } if ( paramTypes . length == 0 ) { return MethodParameter . EMPTY_ARRAY ; } InputStream stream ; try { stream = ClassLoaderUtil . getClassAsStream ( declaringClass ) ; } catch ( IOException ioex ) { throw new ParamoException ( "Failed to read class bytes: " + declaringClass . getName ( ) , ioex ) ; } if ( stream == null ) { throw new ParamoException ( "Class not found: " + declaringClass ) ; } try { ClassReader reader = new ClassReader ( stream ) ; MethodFinder visitor = new MethodFinder ( declaringClass , name , paramTypes ) ; reader . accept ( visitor , 0 ) ; return visitor . getResolvedParameters ( ) ; } catch ( IOException ioex ) { throw new ParamoException ( ioex ) ; } finally { StreamUtil . close ( stream ) ; }


signature:
public class FormTag { /** * Performs smart form population . */
@ Override public int doAfterBody ( ) throws JspException { } }

implementation: BodyContent body = getBodyContent ( ) ; JspWriter out = body . getEnclosingWriter ( ) ; String bodytext = populateForm ( body . getString ( ) , name -> value ( name , pageContext ) ) ; try { out . print ( bodytext ) ; } catch ( IOException ioex ) { throw new JspException ( ioex ) ; } return SKIP_BODY ;


signature:
public class PropsEntry { /** * Returns the property value , with replaced macros . */
public String getValue ( final String ... profiles ) { } }

implementation: if ( hasMacro ) { return propsData . resolveMacros ( value , profiles ) ; } return value ;


signature:
public class LagartoDOMBuilderTagVisitor { /** * Starts with DOM building .
 * Creates root { @ link jodd . lagarto . dom . Document } node . */
@ Override public void start ( ) { } }

implementation: log . debug ( "DomTree builder started" ) ; if ( rootNode == null ) { rootNode = new Document ( domBuilder . config ) ; } parentNode = rootNode ; enabled = true ; if ( domBuilder . config . isEnabledVoidTags ( ) ) { htmlVoidRules = new HtmlVoidRules ( ) ; }


signature:
public class LagartoDOMBuilderTagVisitor { /** * Finishes the tree building . Closes unclosed tags . */
@ Override public void end ( ) { } }

implementation:
if ( parentNode != rootNode ) { Node thisNode = parentNode ; while ( thisNode != rootNode ) { if ( domBuilder . config . isImpliedEndTags ( ) ) { if ( implRules . implicitlyCloseTagOnEOF ( thisNode . getNodeName ( ) ) ) { thisNode = thisNode . getParentNode ( ) ; continue ; } } error ( "Unclosed tag closed: <" + thisNode . getNodeName ( ) + ">" ) ; thisNode = thisNode . getParentNode ( ) ; } } // remove whitespaces
if ( domBuilder . config . isIgnoreWhitespacesBetweenTags ( ) ) { removeLastChildNodeIfEmptyText ( parentNode , true ) ; } // foster
if ( domBuilder . config . isUseFosterRules ( ) ) { HtmlFosterRules fosterRules = new HtmlFosterRules ( ) ; fosterRules . fixFosterElements ( rootNode ) ; } // elapsed
rootNode . end ( ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "LagartoDom tree created in " + rootNode . getElapsedTime ( ) + " ms" ) ; }


signature:
public class LagartoDOMBuilderTagVisitor { /** * Creates new element with correct configuration . */
protected Element createElementNode ( final Tag tag ) { } }

implementation:
boolean hasVoidTags = htmlVoidRules != null ; boolean isVoid = false ; boolean selfClosed = false ; if ( hasVoidTags ) { isVoid = htmlVoidRules . isVoidTag ( tag . getName ( ) ) ; // HTML and XHTML
if ( isVoid ) { // it ' s void tag , lookup the flag
selfClosed = domBuilder . config . isSelfCloseVoidTags ( ) ; } } else { // XML , no voids , lookup the flag
selfClosed = domBuilder . config . isSelfCloseVoidTags ( ) ; } return new Element ( rootNode , tag , isVoid , selfClosed ) ;


signature:
public class LagartoDOMBuilderTagVisitor { /** * Visits tags . */
@ Override public void tag ( final Tag tag ) { } }

implementation:
if ( ! enabled ) { return ; } TagType tagType = tag . getType ( ) ; Element node ; switch ( tagType ) { case START : if ( domBuilder . config . isIgnoreWhitespacesBetweenTags ( ) ) { removeLastChildNodeIfEmptyText ( parentNode , false ) ; } node = createElementNode ( tag ) ; if ( domBuilder . config . isImpliedEndTags ( ) ) { while ( true ) { String parentNodeName = parentNode . getNodeName ( ) ; if ( ! implRules . implicitlyCloseParentTagOnNewTag ( parentNodeName , node . getNodeName ( ) ) ) { break ; } parentNode = parentNode . getParentNode ( ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Implicitly closed tag <" + node . getNodeName ( ) + "> " ) ; } } } parentNode . addChild ( node ) ; if ( ! node . isVoidElement ( ) ) { parentNode = node ; } break ; case END : if ( domBuilder . config . isIgnoreWhitespacesBetweenTags ( ) ) { removeLastChildNodeIfEmptyText ( parentNode , true ) ; } String tagName = tag . getName ( ) . toString ( ) ; Node matchingParent = findMatchingParentOpenTag ( tagName ) ; if ( matchingParent == parentNode ) { // regular situation
parentNode = parentNode . getParentNode ( ) ; break ; } if ( matchingParent == null ) { // matching open tag not found , remove it
error ( "Orphan closed tag ignored: </" + tagName + "> " + tag . getTagPosition ( ) ) ; break ; } // try to close it implicitly
if ( domBuilder . config . isImpliedEndTags ( ) ) { boolean fixed = false ; while ( implRules . implicitlyCloseParentTagOnTagEnd ( parentNode . getNodeName ( ) , tagName ) ) { parentNode = parentNode . getParentNode ( ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Implicitly closed tag <" + tagName + ">" ) ; } if ( parentNode == matchingParent ) { parentNode = matchingParent . parentNode ; fixed = true ; break ; } } if ( fixed ) { break ; } } // matching tag found , but it is not a regular situation
// therefore close all unclosed tags in between
fixUnclosedTagsUpToMatchingParent ( tag , matchingParent ) ; break ; case SELF_CLOSING : if ( domBuilder . config . isIgnoreWhitespacesBetweenTags ( ) ) { removeLastChildNodeIfEmptyText ( parentNode , false ) ; } node = createElementNode ( tag ) ; parentNode . addChild ( node ) ; break ; }


signature:
public class LagartoDOMBuilderTagVisitor { /** * Removes last child node if contains just empty text . */
protected void removeLastChildNodeIfEmptyText ( final Node parentNode , final boolean closedTag ) { } }

implementation: if ( parentNode == null ) { return ; } Node lastChild = parentNode . getLastChild ( ) ; if ( lastChild == null ) { return ; } if ( lastChild . getNodeType ( ) != Node . NodeType . TEXT ) { return ; } if ( closedTag ) { if ( parentNode . getChildNodesCount ( ) == 1 ) { return ; } } Text text = ( Text ) lastChild ; if ( text . isBlank ( ) ) { lastChild . detachFromParent ( ) ; }


signature:
public class LagartoDOMBuilderTagVisitor { /** * Finds matching parent open tag or < code > null < / code > if not found . */
protected Node findMatchingParentOpenTag ( String tagName ) { } }

implementation: Node parent = parentNode ; if ( ! rootNode . config . isCaseSensitive ( ) ) { tagName = tagName . toLowerCase ( ) ; } while ( parent != null ) { String parentNodeName = parent . getNodeName ( ) ; if ( parentNodeName != null ) { if ( ! rootNode . config . isCaseSensitive ( ) ) { parentNodeName = parentNodeName . toLowerCase ( ) ; } } if ( tagName . equals ( parentNodeName ) ) { return parent ; } parent = parent . getParentNode ( ) ; } return null ;


signature:
public class LagartoDOMBuilderTagVisitor { /** * Fixes all unclosed tags up to matching parent . Missing end tags will be added
 * just before parent tag is closed , making the whole inner content as its tag body .
 * Tags that can be closed implicitly are checked and closed .
 * There is optional check for detecting orphan tags inside the
 * table or lists . If set , tags can be closed beyond the border of the
 * table and the list and it is reported as orphan tag .
 * This is just a generic solutions , closest to the rules . */
protected void fixUnclosedTagsUpToMatchingParent ( final Tag tag , final Node matchingParent ) { } }

implementation:
if ( domBuilder . config . isUnclosedTagAsOrphanCheck ( ) ) { Node thisNode = parentNode ; if ( ! CharSequenceUtil . equalsIgnoreCase ( tag . getName ( ) , "table" ) ) { // check if there is table or list between this node
// and matching parent
while ( thisNode != matchingParent ) { String thisNodeName = thisNode . getNodeName ( ) . toLowerCase ( ) ; if ( thisNodeName . equals ( "table" ) || thisNodeName . equals ( "ul" ) || thisNodeName . equals ( "ol" ) ) { String positionString = tag . getPosition ( ) ; if ( positionString == null ) { positionString = StringPool . EMPTY ; } error ( "Orphan closed tag ignored: </" + tag . getName ( ) + "> " + positionString ) ; return ; } thisNode = thisNode . getParentNode ( ) ; } } } while ( true ) { if ( parentNode == matchingParent ) { parentNode = parentNode . getParentNode ( ) ; break ; } Node parentParentNode = parentNode . getParentNode ( ) ; if ( domBuilder . config . isImpliedEndTags ( ) ) { if ( implRules . implicitlyCloseParentTagOnNewTag ( parentParentNode . getNodeName ( ) , parentNode . getNodeName ( ) ) ) { // break the tree : detach this node and append it after parent
parentNode . detachFromParent ( ) ; parentParentNode . getParentNode ( ) . addChild ( parentNode ) ; } } // debug message
error ( "Unclosed tag closed: <" + parentNode . getNodeName ( ) + ">" ) ; // continue looping
parentNode = parentParentNode ; }


signature:
public class LagartoDOMBuilderTagVisitor { /** * - - - - - tree */
@ Override public void script ( final Tag tag , final CharSequence body ) { } }

implementation: if ( ! enabled ) { return ; } Element node = createElementNode ( tag ) ; parentNode . addChild ( node ) ; if ( body . length ( ) != 0 ) { Node text = new Text ( rootNode , body . toString ( ) ) ; node . addChild ( text ) ; }


signature:
public class LagartoDOMBuilderTagVisitor { /** * - - - - - error */
@ Override public void error ( final String message ) { } }

implementation: rootNode . addError ( message ) ; log . log ( domBuilder . config . getParsingErrorLogLevel ( ) , message ) ;


signature:
public class HistoryMethodAdapter { /** * Returns argument index from the history .
 * < b > Must < / b > POP value from the stack after the execution . */
protected int getArgumentIndex ( ) { } }

implementation: if ( ! isPrevious ) { throw new ProxettaException ( "Unexpected previous instruction type used for setting argument index" ) ; } int argIndex ; switch ( opcode ) { case ICONST_0 : argIndex = 0 ; break ; case ICONST_1 : argIndex = 1 ; break ; case ICONST_2 : argIndex = 2 ; break ; case ICONST_3 : argIndex = 3 ; break ; case ICONST_4 : argIndex = 4 ; break ; case ICONST_5 : argIndex = 5 ; break ; case BIPUSH : case SIPUSH : argIndex = operand ; break ; default : throw new ProxettaException ( "Unexpected previous instruction used for setting argument index" ) ; } return argIndex ;


signature:
public class HistoryMethodAdapter { /** * - - - - - visitors */
@ Override public void visitInsn ( final int opcode ) { } }

implementation: this . opcode = opcode ; isPrevious = true ; traceNext = false ; super . visitInsn ( opcode ) ;


signature:
public class ProxyTargetReplacement { /** * Visits replacement code for { @ link ProxyTarget # argumentsCount ( ) } . */
public static void argumentsCount ( final MethodVisitor mv , final MethodInfo methodInfo ) { } }

implementation: int argsCount = methodInfo . getArgumentsCount ( ) ; pushInt ( mv , argsCount ) ;


signature:
public class ProxyTargetReplacement { /** * Visits replacement code for { @ link ProxyTarget # argumentType ( int ) } . */
public static void argumentType ( final MethodVisitor mv , final MethodInfo methodInfo , final int argIndex ) { } }

implementation: checkArgumentIndex ( methodInfo , argIndex ) ; mv . visitInsn ( POP ) ; loadMethodArgumentClass ( mv , methodInfo , argIndex ) ;


signature:
public class ProxyTargetReplacement { /** * Visits replacement code for { @ link ProxyTarget # argument ( int ) } . */
public static void argument ( final MethodVisitor mv , final MethodInfo methodInfo , final int argIndex ) { } }

implementation: checkArgumentIndex ( methodInfo , argIndex ) ; mv . visitInsn ( POP ) ; loadMethodArgumentAsObject ( mv , methodInfo , argIndex ) ;


signature:
public class ProxyTargetReplacement { /** * Visits replacement code for { @ link ProxyTarget # createArgumentsArray ( ) } . */
public static void createArgumentsArray ( final MethodVisitor mv , final MethodInfo methodInfo ) { } }

implementation: int argsCount = methodInfo . getArgumentsCount ( ) ; pushInt ( mv , argsCount ) ; mv . visitTypeInsn ( ANEWARRAY , AsmUtil . SIGNATURE_JAVA_LANG_OBJECT ) ; for ( int i = 0 ; i < argsCount ; i ++ ) { mv . visitInsn ( DUP ) ; pushInt ( mv , i ) ; loadMethodArgumentAsObject ( mv , methodInfo , i + 1 ) ; mv . visitInsn ( AASTORE ) ; }


signature:
public class ProxyTargetReplacement { /** * Visits replacement code for { @ link ProxyTarget # createArgumentsClassArray ( ) } . */
public static void createArgumentsClassArray ( final MethodVisitor mv , final MethodInfo methodInfo ) { } }

implementation: int argsCount = methodInfo . getArgumentsCount ( ) ; pushInt ( mv , argsCount ) ; mv . visitTypeInsn ( ANEWARRAY , AsmUtil . SIGNATURE_JAVA_LANG_CLASS ) ; for ( int i = 0 ; i < argsCount ; i ++ ) { mv . visitInsn ( DUP ) ; pushInt ( mv , i ) ; loadMethodArgumentClass ( mv , methodInfo , i + 1 ) ; mv . visitInsn ( AASTORE ) ; }


signature:
public class ProxyTargetReplacement { /** * Visits replacement code for { @ link ProxyTarget # returnType ( ) } . */
public static void returnType ( final MethodVisitor mv , final MethodInfo methodInfo ) { } }

implementation: ProxettaAsmUtil . loadClass ( mv , methodInfo . getReturnType ( ) . getOpcode ( ) , methodInfo . getReturnType ( ) . getName ( ) ) ;


signature:
public class ProxyTargetReplacement { /** * Visits replacement code for { @ link ProxyTarget # targetClass ( ) } . */
public static void targetClass ( final MethodVisitor mv , final MethodInfo methodInfo ) { } }

implementation: ClassInfo classInfo = methodInfo . getClassInfo ( ) ; mv . visitLdcInsn ( Type . getType ( 'L' + classInfo . getReference ( ) + ';' ) ) ;


signature:
public class ProxyTargetReplacement { /** * Visits replacement code for { @ link ProxyTarget # info ( ) } . */
public static void info ( final MethodVisitor mv , final MethodInfo methodInfo , final int argsOff ) { } }

implementation:
mv . visitTypeInsn ( Opcodes . NEW , PROXY_TARGET_INFO ) ; mv . visitInsn ( DUP ) ; mv . visitMethodInsn ( Opcodes . INVOKESPECIAL , PROXY_TARGET_INFO , "<init>" , "()V" , false ) ; // int argsOff = methodInfo . getAllArgumentsSize ( ) ;
// argsOff + + ;
mv . visitVarInsn ( Opcodes . ASTORE , argsOff ) ; // argument count
mv . visitVarInsn ( Opcodes . ALOAD , argsOff ) ; argumentsCount ( mv , methodInfo ) ; mv . visitFieldInsn ( Opcodes . PUTFIELD , PROXY_TARGET_INFO , "argumentCount" , "I" ) ; // arguments class
mv . visitVarInsn ( Opcodes . ALOAD , argsOff ) ; createArgumentsClassArray ( mv , methodInfo ) ; mv . visitFieldInsn ( Opcodes . PUTFIELD , PROXY_TARGET_INFO , "argumentsClasses" , "[Ljava/lang/Class;" ) ; // arguments
mv . visitVarInsn ( Opcodes . ALOAD , argsOff ) ; createArgumentsArray ( mv , methodInfo ) ; mv . visitFieldInsn ( Opcodes . PUTFIELD , PROXY_TARGET_INFO , "arguments" , "[Ljava/lang/Object;" ) ; // return type
mv . visitVarInsn ( Opcodes . ALOAD , argsOff ) ; returnType ( mv , methodInfo ) ; mv . visitFieldInsn ( Opcodes . PUTFIELD , PROXY_TARGET_INFO , "returnType" , AsmUtil . L_SIGNATURE_JAVA_LANG_CLASS ) ; // target method name
mv . visitVarInsn ( Opcodes . ALOAD , argsOff ) ; targetMethodName ( mv , methodInfo ) ; mv . visitFieldInsn ( Opcodes . PUTFIELD , PROXY_TARGET_INFO , "targetMethodName" , AsmUtil . L_SIGNATURE_JAVA_LANG_STRING ) ; // target method name
mv . visitVarInsn ( Opcodes . ALOAD , argsOff ) ; targetMethodDescription ( mv , methodInfo ) ; mv . visitFieldInsn ( Opcodes . PUTFIELD , PROXY_TARGET_INFO , "targetMethodDescription" , AsmUtil . L_SIGNATURE_JAVA_LANG_STRING ) ; // target method name
mv . visitVarInsn ( Opcodes . ALOAD , argsOff ) ; targetMethodSignature ( mv , methodInfo ) ; mv . visitFieldInsn ( Opcodes . PUTFIELD , PROXY_TARGET_INFO , "targetMethodSignature" , AsmUtil . L_SIGNATURE_JAVA_LANG_STRING ) ; // target class
mv . visitVarInsn ( Opcodes . ALOAD , argsOff ) ; targetClass ( mv , methodInfo ) ; mv . visitFieldInsn ( Opcodes . PUTFIELD , PROXY_TARGET_INFO , "targetClass" , AsmUtil . L_SIGNATURE_JAVA_LANG_CLASS ) ; // the end
mv . visitVarInsn ( Opcodes . ALOAD , argsOff ) ;


signature:
public class ProxyTargetReplacement { /** * Visits replacement code for { @ link ProxyTarget # targetMethodAnnotation ( String , String ) } . */
public static void targetMethodAnnotation ( final MethodVisitor mv , final MethodInfo methodInfo , final String [ ] args ) { } }

implementation: AnnotationInfo [ ] anns = methodInfo . getAnnotations ( ) ; if ( anns != null ) { targetAnnotation ( mv , anns , args ) ; }


signature:
public class ProxyTargetReplacement { /** * Visits replacement code for { @ link ProxyTarget # targetClassAnnotation ( String , String ) } . */
public static void targetClassAnnotation ( final MethodVisitor mv , final ClassInfo classInfo , final String [ ] args ) { } }

implementation: AnnotationInfo [ ] anns = classInfo . getAnnotations ( ) ; if ( anns != null ) { targetAnnotation ( mv , anns , args ) ; } else { mv . visitInsn ( Opcodes . ACONST_NULL ) ; }


signature:
public class BaseLoggableStatement { /** * Returns the query string . */
public String getQueryString ( ) { } }

implementation: if ( sqlTemplate == null ) { return toString ( ) ; } if ( parameterValues == null ) { return sqlTemplate ; } final StringBuilder sb = new StringBuilder ( ) ; int qMarkCount = 0 ; final StringTokenizer tok = new StringTokenizer ( sqlTemplate + ' ' , "?" ) ; while ( tok . hasMoreTokens ( ) ) { final String oneChunk = tok . nextToken ( ) ; sb . append ( oneChunk ) ; try { Object value = null ; if ( parameterValues . size ( ) > 1 + qMarkCount ) { value = parameterValues . get ( 1 + qMarkCount ) ; qMarkCount ++ ; } else { if ( ! tok . hasMoreTokens ( ) ) { value = "" ; } } if ( value == null ) { value = "?" ; } sb . append ( value ) ; } catch ( Throwable th ) { sb . append ( "--- Building query failed: " ) . append ( th . toString ( ) ) ; } } return sb . toString ( ) . trim ( ) ;


signature:
public class BaseLoggableStatement { /** * Saves the parameter value < code > obj < / code > for the specified
 * < code > position < / code > for use in logging output .
 * @ param position position ( starting at 1 ) of the parameter to save
 * @ param obj java . lang . Object the parameter value to save */
protected void saveQueryParamValue ( final int position , final Object obj ) { } }

implementation:
final String strValue ; if ( obj instanceof String || obj instanceof Date ) { strValue = "'" + obj + '\'' ; // if we have a String or Date , include ' ' in the saved value
} else if ( obj instanceof LocalDateTime || obj instanceof LocalDate || obj instanceof LocalTime ) { strValue = "'" + Converter . get ( ) . toString ( obj ) + '\'' ; // time as string with '
} else if ( obj == null ) { strValue = "<null>" ; // convert null to the string null
} else { strValue = Converter . get ( ) . toString ( obj ) ; // all other objects ( includes all Numbers , arrays , etc )
} // if we are setting a position larger than current size of parameterValues ,
// first make it larger
if ( parameterValues == null ) { parameterValues = new ArrayList < > ( ) ; } while ( position >= parameterValues . size ( ) ) { parameterValues . add ( null ) ; } parameterValues . set ( position , strValue ) ;


signature:
public class I18nInterceptor { /** * Returns correct action class name . Detects Proxetta classes . */
protected String getActionClassName ( final Object action ) { } }

implementation: Class clazz = action . getClass ( ) ; clazz = ProxettaUtil . resolveTargetClass ( clazz ) ; return clazz . getName ( ) ;


signature:
public class IteratorTag { /** * Calculates ' TO ' . */
protected int calculateTo ( final int from , final int count , final int size ) { } }

implementation: int to = size ; if ( count != - 1 ) { to = from + count ; if ( to > size ) { to = size ; } } return to ;


signature:
public class IteratorTag { /** * Iterates collection . */
protected void iterateCollection ( final Collection collection , final int from , final int count , final PageContext pageContext ) throws JspException { } }

implementation: JspFragment body = getJspBody ( ) ; Iterator iter = collection . iterator ( ) ; int i = 0 ; int to = calculateTo ( from , count , collection . size ( ) ) ; while ( i < to ) { Object item = iter . next ( ) ; if ( i >= from ) { if ( status != null ) { iteratorStatus . next ( ! iter . hasNext ( ) ) ; } TagUtil . setScopeAttribute ( var , item , scope , pageContext ) ; TagUtil . invokeBody ( body ) ; } i ++ ; }


signature:
public class IteratorTag { /** * Iterates arrays . */
protected void iterateArray ( final Object [ ] array , final int from , final int count , final PageContext pageContext ) throws JspException { } }

implementation: JspFragment body = getJspBody ( ) ; int len = array . length ; int to = calculateTo ( from , count , len ) ; int last = to - 1 ; for ( int i = from ; i < to ; i ++ ) { Object item = array [ i ] ; if ( status != null ) { iteratorStatus . next ( i == last ) ; } TagUtil . setScopeAttribute ( var , item , scope , pageContext ) ; TagUtil . invokeBody ( body ) ; }


signature:
public class JoinHintResolver { /** * Joins entity array using provided string hints . */
public Object [ ] join ( final Object [ ] data , final String [ ] hints ) { } }

implementation:
if ( hints == null ) { return data ; } // build context
Map < String , Object > context = new HashMap < > ( hints . length ) ; for ( int i = 0 ; i < hints . length ; i ++ ) { hints [ i ] = hints [ i ] . trim ( ) ; String hint = hints [ i ] ; if ( hint . indexOf ( '.' ) == - 1 ) { context . put ( hint , data [ i ] ) ; } } // no joining hints found
if ( context . size ( ) == data . length ) { return data ; } // joining
Object [ ] result = new Object [ context . size ( ) ] ; int count = 0 ; for ( int i = 0 ; i < hints . length ; i ++ ) { String hint = hints [ i ] ; int ndx = hint . indexOf ( '.' ) ; if ( ndx != - 1 ) { String key = hint . substring ( 0 , ndx ) ; Object value = context . get ( key ) ; if ( value == null ) { throw new DbOomException ( "Hint value missing: " + key ) ; } // don ' t merge nulls
if ( data [ i ] == null ) { continue ; } String hintPropertyName = hint . substring ( ndx + 1 ) ; Class hintPropertyType = BeanUtil . pojo . getPropertyType ( value , hintPropertyName ) ; if ( hintPropertyType != null ) { ClassDescriptor cd = ClassIntrospector . get ( ) . lookup ( hintPropertyType ) ; if ( cd . isCollection ( ) ) { // add element to collection
try { Collection collection = BeanUtil . declared . getProperty ( value , hintPropertyName ) ; if ( collection == null ) { collection = ( Collection ) ClassUtil . newInstance ( hintPropertyType ) ; BeanUtil . declaredSilent . setProperty ( value , hintPropertyName , collection ) ; } collection . add ( data [ i ] ) ; } catch ( Exception ex ) { throw new DbOomException ( ex ) ; } } else if ( cd . isArray ( ) ) { // add element to array
try { Object [ ] array = BeanUtil . declared . getProperty ( value , hintPropertyName ) ; if ( array == null ) { array = ( Object [ ] ) Array . newInstance ( hintPropertyType . getComponentType ( ) , 1 ) ; BeanUtil . declaredSilent . setProperty ( value , hintPropertyName , array ) ; array [ 0 ] = data [ i ] ; } else { Object [ ] newArray = ArraysUtil . append ( array , data [ i ] ) ; if ( newArray != array ) { BeanUtil . declaredSilent . setProperty ( value , hintPropertyName , newArray ) ; } } } catch ( Exception ex ) { throw new DbOomException ( ex ) ; } } else { // set value
BeanUtil . declaredSilent . setProperty ( value , hintPropertyName , data [ i ] ) ; } } else { // special case - the property probably contains the collection in the way
int lastNdx = hintPropertyName . lastIndexOf ( '.' ) ; String name = hintPropertyName . substring ( 0 , lastNdx ) ; Object target = resolveValueInSpecialCase ( value , name ) ; if ( target != null ) { String targetSimpleName = hintPropertyName . substring ( lastNdx + 1 ) ; BeanUtil . declaredForcedSilent . setProperty ( target , targetSimpleName , data [ i ] ) ; } } } else { result [ count ] = data [ i ] ; count ++ ; } } return result ;


signature:
public class StringUtil { /** * Replaces all occurrences of a certain pattern in a string with a
 * replacement string . This is the fastest replace function known to author .
 * @ param s string to be inspected
 * @ param sub string pattern to be replaced
 * @ param with string that should go where the pattern was */
public static String replace ( final String s , final String sub , final String with ) { } }

implementation: if ( sub . isEmpty ( ) ) { return s ; } int c = 0 ; int i = s . indexOf ( sub , c ) ; if ( i == - 1 ) { return s ; } int length = s . length ( ) ; StringBuilder sb = new StringBuilder ( length + with . length ( ) ) ; do { sb . append ( s , c , i ) ; sb . append ( with ) ; c = i + sub . length ( ) ; } while ( ( i = s . indexOf ( sub , c ) ) != - 1 ) ; if ( c < length ) { sb . append ( s , c , length ) ; } return sb . toString ( ) ;


signature:
public class StringUtil { /** * Replaces all occurrences of a character in a string .
 * @ param s input string
 * @ param sub character to replace
 * @ param with character to replace with */
public static String replaceChar ( final String s , final char sub , final char with ) { } }

implementation: int startIndex = s . indexOf ( sub ) ; if ( startIndex == - 1 ) { return s ; } char [ ] str = s . toCharArray ( ) ; for ( int i = startIndex ; i < str . length ; i ++ ) { if ( str [ i ] == sub ) { str [ i ] = with ; } } return new String ( str ) ;


signature:
public class StringUtil { /** * Replaces all occurrences of a characters in a string .
 * @ param s input string
 * @ param sub characters to replace
 * @ param with characters to replace with */
public static String replaceChars ( final String s , final char [ ] sub , final char [ ] with ) { } }

implementation: char [ ] str = s . toCharArray ( ) ; for ( int i = 0 ; i < str . length ; i ++ ) { char c = str [ i ] ; for ( int j = 0 ; j < sub . length ; j ++ ) { if ( c == sub [ j ] ) { str [ i ] = with [ j ] ; break ; } } } return new String ( str ) ;


signature:
public class StringUtil { /** * Replaces the very first occurrence of a substring with supplied string .
 * @ param s source string
 * @ param sub substring to replace
 * @ param with substring to replace with */
public static String replaceFirst ( final String s , final String sub , final String with ) { } }

implementation: int i = s . indexOf ( sub ) ; if ( i == - 1 ) { return s ; } return s . substring ( 0 , i ) + with + s . substring ( i + sub . length ( ) ) ;


signature:
public class StringUtil { /** * Replaces the very first occurrence of a character in a string .
 * @ param s string
 * @ param sub char to replace
 * @ param with char to replace with */
public static String replaceFirst ( final String s , final char sub , final char with ) { } }

implementation: int index = s . indexOf ( sub ) ; if ( index == - 1 ) { return s ; } char [ ] str = s . toCharArray ( ) ; str [ index ] = with ; return new String ( str ) ;


signature:
public class StringUtil { /** * Replaces the very last occurrence of a substring with supplied string .
 * @ param s source string
 * @ param sub substring to replace
 * @ param with substring to replace with */
public static String replaceLast ( final String s , final String sub , final String with ) { } }

implementation: int i = s . lastIndexOf ( sub ) ; if ( i == - 1 ) { return s ; } return s . substring ( 0 , i ) + with + s . substring ( i + sub . length ( ) ) ;


signature:
public class StringUtil { /** * Replaces the very last occurrence of a character in a string .
 * @ param s string
 * @ param sub char to replace
 * @ param with char to replace with */
public static String replaceLast ( final String s , final char sub , final char with ) { } }

implementation: int index = s . lastIndexOf ( sub ) ; if ( index == - 1 ) { return s ; } char [ ] str = s . toCharArray ( ) ; str [ index ] = with ; return new String ( str ) ;


signature:
public class StringUtil { /** * Removes all substring occurrences from the string .
 * @ param s source string
 * @ param sub substring to remove */
public static String remove ( final String s , final String sub ) { } }

implementation: int c = 0 ; int sublen = sub . length ( ) ; if ( sublen == 0 ) { return s ; } int i = s . indexOf ( sub , c ) ; if ( i == - 1 ) { return s ; } StringBuilder sb = new StringBuilder ( s . length ( ) ) ; do { sb . append ( s , c , i ) ; c = i + sublen ; } while ( ( i = s . indexOf ( sub , c ) ) != - 1 ) ; if ( c < s . length ( ) ) { sb . append ( s , c , s . length ( ) ) ; } return sb . toString ( ) ;


signature:
public class StringUtil { /** * Removes a single character from string .
 * @ param string source string
 * @ param ch character to remove */
public static String remove ( final String string , final char ch ) { } }

implementation:
int stringLen = string . length ( ) ; char [ ] result = new char [ stringLen ] ; int offset = 0 ; for ( int i = 0 ; i < stringLen ; i ++ ) { char c = string . charAt ( i ) ; if ( c == ch ) { continue ; } result [ offset ] = c ; offset ++ ; } if ( offset == stringLen ) { return string ; // no changes
} return new String ( result , 0 , offset ) ;


signature:
public class StringUtil { /** * Determines if string array contains empty strings .
 * @ see # isEmpty ( CharSequence ) */
public static boolean isAllEmpty ( final String ... strings ) { } }

implementation: for ( String string : strings ) { if ( ! isEmpty ( string ) ) { return false ; } } return true ;


signature:
public class StringUtil { /** * Determines if string array contains just blank strings . */
public static boolean isAllBlank ( final String ... strings ) { } }

implementation: for ( String string : strings ) { if ( ! isBlank ( string ) ) { return false ; } } return true ;


signature:
public class StringUtil { /** * Returns < code > true < / code > if string contains only white spaces . */
public static boolean containsOnlyWhitespaces ( final CharSequence string ) { } }

implementation: int size = string . length ( ) ; for ( int i = 0 ; i < size ; i ++ ) { char c = string . charAt ( i ) ; if ( ! CharUtil . isWhitespace ( c ) ) { return false ; } } return true ;


signature:
public class StringUtil { /** * Returns < code > true < / code > if string contains only digits . */
public static boolean containsOnlyDigits ( final CharSequence string ) { } }

implementation: int size = string . length ( ) ; for ( int i = 0 ; i < size ; i ++ ) { char c = string . charAt ( i ) ; if ( ! CharUtil . isDigit ( c ) ) { return false ; } } return true ;


signature:
public class StringUtil { /** * Converts an array object to array of strings , where every element
 * of input array is converted to a string . If input is not an array ,
 * the result will still be an array with one element . */
public static String [ ] toStringArray ( final Object value ) { } }

implementation: if ( value == null ) { return new String [ 0 ] ; } Class < ? > type = value . getClass ( ) ; if ( ! type . isArray ( ) ) { return new String [ ] { value . toString ( ) } ; } Class componentType = type . getComponentType ( ) ; if ( componentType . isPrimitive ( ) ) { if ( componentType == int . class ) { return ArraysUtil . toStringArray ( ( int [ ] ) value ) ; } else if ( componentType == long . class ) { return ArraysUtil . toStringArray ( ( long [ ] ) value ) ; } else if ( componentType == double . class ) { return ArraysUtil . toStringArray ( ( double [ ] ) value ) ; } else if ( componentType == float . class ) { return ArraysUtil . toStringArray ( ( float [ ] ) value ) ; } else if ( componentType == boolean . class ) { return ArraysUtil . toStringArray ( ( boolean [ ] ) value ) ; } else if ( componentType == short . class ) { return ArraysUtil . toStringArray ( ( short [ ] ) value ) ; } else if ( componentType == byte . class ) { return ArraysUtil . toStringArray ( ( byte [ ] ) value ) ; } else { throw new IllegalArgumentException ( ) ; } } else { return ArraysUtil . toStringArray ( ( Object [ ] ) value ) ; }


signature:
public class StringUtil { /** * Internal method for changing the first character case . */
private static String changeFirstCharacterCase ( final boolean capitalize , final String string ) { } }

implementation:
int strLen = string . length ( ) ; if ( strLen == 0 ) { return string ; } char ch = string . charAt ( 0 ) ; char modifiedCh ; if ( capitalize ) { modifiedCh = Character . toUpperCase ( ch ) ; } else { modifiedCh = Character . toLowerCase ( ch ) ; } if ( modifiedCh == ch ) { // no change , return unchanged string
return string ; } char [ ] chars = string . toCharArray ( ) ; chars [ 0 ] = modifiedCh ; return new String ( chars ) ;


signature:
public class StringUtil { /** * Makes a title - cased string from given input . */
public static String title ( final String string ) { } }

implementation: char [ ] chars = string . toCharArray ( ) ; boolean wasWhitespace = true ; for ( int i = 0 ; i < chars . length ; i ++ ) { char c = chars [ i ] ; if ( CharUtil . isWhitespace ( c ) ) { wasWhitespace = true ; } else { if ( wasWhitespace ) { chars [ i ] = Character . toUpperCase ( c ) ; } else { chars [ i ] = Character . toLowerCase ( c ) ; } wasWhitespace = false ; } } return new String ( chars ) ;


signature:
public class StringUtil { /** * Returns a new string that is a substring of this string . The substring
 * begins at the specified < code > fromIndex < / code > and extends to the character
 * at index < code > toIndex - 1 < / code > . However , index values can be negative ,
 * and then the real index will be calculated from the strings end . This
 * allows to specify , e . g . < code > substring ( 1 , - 1 ) < / code > to cut one character
 * from both ends of the string . If < code > fromIndex < / code > is negative
 * and < code > toIndex < / code > is 0 , it will return last characters of the string .
 * Also , this method will never throw an exception if index is out of range . */
public static String substring ( final String string , int fromIndex , int toIndex ) { } }

implementation:
int len = string . length ( ) ; if ( fromIndex < 0 ) { fromIndex = len + fromIndex ; if ( toIndex == 0 ) { toIndex = len ; } } if ( toIndex < 0 ) { toIndex = len + toIndex ; } // safe net
if ( fromIndex < 0 ) { fromIndex = 0 ; } if ( toIndex > len ) { toIndex = len ; } if ( fromIndex >= toIndex ) { return StringPool . EMPTY ; } return string . substring ( fromIndex , toIndex ) ;


signature:
public class StringUtil { /** * Returns < code > true < / code > if substring exist at given offset in a string . */
public static boolean isSubstringAt ( final String string , final String substring , final int offset ) { } }

implementation: int len = substring . length ( ) ; int max = offset + len ; if ( max > string . length ( ) ) { return false ; } int ndx = 0 ; for ( int i = offset ; i < max ; i ++ , ndx ++ ) { if ( string . charAt ( i ) != substring . charAt ( ndx ) ) { return false ; } } return true ;


signature:
public class StringUtil { /** * Splits a string in several parts ( tokens ) that are separated by delimiter .
 * Delimiter is < b > always < / b > surrounded by two strings ! If there is no
 * content between two delimiters , empty string will be returned for that
 * token . Therefore , the length of the returned array will always be :
 * # delimiters + 1.
 * Method is much , much faster then regexp < code > String . split ( ) < / code > ,
 * and a bit faster then < code > StringTokenizer < / code > .
 * @ param src string to split
 * @ param delimiter split delimiter
 * @ return array of split strings */
public static String [ ] split ( final String src , final String delimiter ) { } }

implementation:
int maxparts = ( src . length ( ) / delimiter . length ( ) ) + 2 ; // one more for the last
int [ ] positions = new int [ maxparts ] ; int dellen = delimiter . length ( ) ; int i , j = 0 ; int count = 0 ; positions [ 0 ] = - dellen ; while ( ( i = src . indexOf ( delimiter , j ) ) != - 1 ) { count ++ ; positions [ count ] = i ; j = i + dellen ; } count ++ ; positions [ count ] = src . length ( ) ; String [ ] result = new String [ count ] ; for ( i = 0 ; i < count ; i ++ ) { result [ i ] = src . substring ( positions [ i ] + dellen , positions [ i + 1 ] ) ; } return result ;


signature:
public class StringUtil { /** * Splits a string in several parts ( tokens ) that are separated by delimiter
 * characters . Delimiter may contains any number of character and it is
 * always surrounded by two strings .
 * @ param src source to examine
 * @ param d string with delimiter characters
 * @ return array of tokens */
public static String [ ] splitc ( final String src , final String d ) { } }

implementation: if ( ( d . length ( ) == 0 ) || ( src . length ( ) == 0 ) ) { return new String [ ] { src } ; } return splitc ( src , d . toCharArray ( ) ) ;


signature:
public class StringUtil { /** * Compress multiple occurrences of given char into one appearance . */
public static String compressChars ( final String s , final char c ) { } }

implementation: int len = s . length ( ) ; StringBuilder sb = new StringBuilder ( len ) ; boolean wasChar = false ; for ( int i = 0 ; i < len ; i ++ ) { char c1 = s . charAt ( i ) ; if ( c1 == c ) { if ( wasChar ) { continue ; } wasChar = true ; } else { wasChar = false ; } sb . append ( c1 ) ; } if ( sb . length ( ) == len ) { return s ; } return sb . toString ( ) ;


signature:
public class StringUtil { /** * Finds the first occurrence of a character in the given source but within limited range ( start , end ] . */
public static int indexOf ( final String src , final char c , int startIndex , int endIndex ) { } }

implementation: if ( startIndex < 0 ) { startIndex = 0 ; } int srclen = src . length ( ) ; if ( endIndex > srclen ) { endIndex = srclen ; } for ( int i = startIndex ; i < endIndex ; i ++ ) { if ( src . charAt ( i ) == c ) { return i ; } } return - 1 ;


signature:
public class StringUtil { /** * Finds the first occurrence of a character in the given source but within limited range ( start , end ] . */
public static int indexOfIgnoreCase ( final String src , char c , int startIndex , int endIndex ) { } }

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


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

implementation: return indexOfIgnoreCase ( src , subS , 0 , src . length ( ) ) ;


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

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


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

implementation: return lastIndexOfIgnoreCase ( src , subS , startIndex , 0 ) ;


signature:
public class StringUtil { /** * Finds last index of a substring in the given source string in specified range [ end , start ]
 * See { @ link # indexOf ( String , String , int , int ) } for details about the speed .
 * @ param srcsource to examine
 * @ param subsubstring to find
 * @ param startIndexstarting index
 * @ param endIndexend index
 * @ return last index of founded substring or - 1 if substring is not found */
public static int lastIndexOf ( final String src , final String sub , int startIndex , int endIndex ) { } }

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


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

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


signature:
public class StringUtil { /** * Tests if this string starts with the specified prefix with ignored case
 * and with the specified prefix beginning a specified index .
 * @ param src source string to test
 * @ param subS starting substring
 * @ param startIndex index from where to test
 * @ return < code > true < / code > if the character sequence represented by the argument is
 * a prefix of the character sequence represented by this string ;
 * < code > false < / code > otherwise . */
public static boolean startsWithIgnoreCase ( final String src , final String subS , final int startIndex ) { } }

implementation: String sub = subS . toLowerCase ( ) ; int sublen = sub . length ( ) ; if ( startIndex + sublen > src . length ( ) ) { return false ; } int j = 0 ; int i = startIndex ; while ( j < sublen ) { char source = Character . toLowerCase ( src . charAt ( i ) ) ; if ( sub . charAt ( j ) != source ) { return false ; } j ++ ; i ++ ; } return true ;


signature:
public class StringUtil { /** * Returns if string ends with provided character . */
public static boolean endsWithChar ( final String s , final char c ) { } }

implementation: if ( s . length ( ) == 0 ) { return false ; } return s . charAt ( s . length ( ) - 1 ) == c ;


signature:
public class StringUtil { /** * Count substring occurrences in a source string , ignoring case .
 * @ param sourcesource string
 * @ param subsubstring to count
 * @ returnnumber of substring occurrences */
public static int countIgnoreCase ( final String source , final String sub ) { } }

implementation: int count = 0 ; int j = 0 ; int sublen = sub . length ( ) ; if ( sublen == 0 ) { return 0 ; } while ( true ) { int i = indexOfIgnoreCase ( source , sub , j ) ; if ( i == - 1 ) { break ; } count ++ ; j = i + sublen ; } return count ;


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

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


signature:
public class StringUtil { /** * Compares two string arrays .
 * @ param as first string array
 * @ param as1 second string array
 * @ return true if all array elements matches */
public static boolean equalsIgnoreCase ( final String [ ] as , final String [ ] as1 ) { } }

implementation: if ( as . length != as1 . length ) { return false ; } for ( int i = 0 ; i < as . length ; i ++ ) { if ( ! as [ i ] . equalsIgnoreCase ( as1 [ i ] ) ) { return false ; } } return true ;


signature:
public class StringUtil { /** * Replaces many substring at once . Order of string array is important .
 * @ param s source string
 * @ param sub substrings array
 * @ param with replace with array
 * @ return string with all occurrences of substrings replaced */
public static String replace ( final String s , final String [ ] sub , final String [ ] with ) { } }

implementation: if ( ( sub . length != with . length ) || ( sub . length == 0 ) ) { return s ; } int start = 0 ; StringBuilder buf = new StringBuilder ( s . length ( ) ) ; while ( true ) { int [ ] res = indexOf ( s , sub , start ) ; if ( res == null ) { break ; } int end = res [ 1 ] ; buf . append ( s , start , end ) ; buf . append ( with [ res [ 0 ] ] ) ; start = end + sub [ res [ 0 ] ] . length ( ) ; } buf . append ( s . substring ( start ) ) ; return buf . toString ( ) ;


signature:
public class StringUtil { /** * Replaces many substring at once . Order of string array is important .
 * @ param s source string
 * @ param sub substrings array
 * @ param with replace with array
 * @ return string with all occurrences of substrings replaced */
public static String replaceIgnoreCase ( final String s , final String [ ] sub , final String [ ] with ) { } }

implementation: if ( ( sub . length != with . length ) || ( sub . length == 0 ) ) { return s ; } int start = 0 ; StringBuilder buf = new StringBuilder ( s . length ( ) ) ; while ( true ) { int [ ] res = indexOfIgnoreCase ( s , sub , start ) ; if ( res == null ) { break ; } int end = res [ 1 ] ; buf . append ( s , start , end ) ; buf . append ( with [ res [ 0 ] ] ) ; start = end + sub [ 0 ] . length ( ) ; } buf . append ( s . substring ( start ) ) ; return buf . toString ( ) ;


signature:
public class StringUtil { /** * Compares string with at least one from the provided array .
 * If at least one equal string is found , returns its index .
 * Otherwise , < code > - 1 < / code > is returned . */
public static int equalsOne ( final String src , final String ... dest ) { } }

implementation: for ( int i = 0 ; i < dest . length ; i ++ ) { if ( src . equals ( dest [ i ] ) ) { return i ; } } return - 1 ;


signature:
public class StringUtil { /** * Compares string with at least one from the provided array , ignoring case .
 * If at least one equal string is found , it returns its index .
 * Otherwise , < code > - 1 < / code > is returned . */
public static int equalsOneIgnoreCase ( final String src , final String ... dest ) { } }

implementation: for ( int i = 0 ; i < dest . length ; i ++ ) { if ( src . equalsIgnoreCase ( dest [ i ] ) ) { return i ; } } return - 1 ;


signature:
public class StringUtil { /** * Checks if string starts with at least one string from the provided array .
 * If at least one string is matched , it returns its index .
 * Otherwise , < code > - 1 < / code > is returned . */
public static int startsWithOne ( final String src , final String ... dest ) { } }

implementation: for ( int i = 0 ; i < dest . length ; i ++ ) { String m = dest [ i ] ; if ( m == null ) { continue ; } if ( src . startsWith ( m ) ) { return i ; } } return - 1 ;


signature:
public class StringUtil { /** * Checks if string starts with at least one string from the provided array .
 * If at least one string is matched , it returns its index .
 * Otherwise , < code > - 1 < / code > is returned . */
public static int startsWithOneIgnoreCase ( final String src , final String ... dest ) { } }

implementation: for ( int i = 0 ; i < dest . length ; i ++ ) { String m = dest [ i ] ; if ( m == null ) { continue ; } if ( startsWithIgnoreCase ( src , m ) ) { return i ; } } return - 1 ;


signature:
public class StringUtil { /** * Checks if string ends with at least one string from the provided array .
 * If at least one string is matched , it returns its index .
 * Otherwise , < code > - 1 < / code > is returned . */
public static int endsWithOne ( final String src , final String ... dest ) { } }

implementation: for ( int i = 0 ; i < dest . length ; i ++ ) { String m = dest [ i ] ; if ( m == null ) { continue ; } if ( src . endsWith ( m ) ) { return i ; } } return - 1 ;


signature:
public class StringUtil { /** * Checks if string ends with at least one string from the provided array .
 * If at least one string is matched , it returns its index .
 * Otherwise , < code > - 1 < / code > is returned . */
public static int endsWithOneIgnoreCase ( final String src , final String ... dest ) { } }

implementation: for ( int i = 0 ; i < dest . length ; i ++ ) { String m = dest [ i ] ; if ( m == null ) { continue ; } if ( endsWithIgnoreCase ( src , m ) ) { return i ; } } return - 1 ;


signature:
public class StringUtil { /** * Returns first index of a whitespace character , starting from specified index offset . */
public static int indexOfWhitespace ( final String string , final int startindex , final int endindex ) { } }

implementation: for ( int i = startindex ; i < endindex ; i ++ ) { if ( CharUtil . isWhitespace ( string . charAt ( i ) ) ) { return i ; } } return - 1 ;


signature:
public class StringUtil { /** * Strips leading char if string starts with one . */
public static String stripLeadingChar ( final String string , final char c ) { } }

implementation: if ( string . length ( ) > 0 ) { if ( string . charAt ( 0 ) == c ) { return string . substring ( 1 ) ; } } return string ;


signature:
public class StringUtil { /** * Strips trailing char if string ends with one . */
public static String stripTrailingChar ( final String string , final char c ) { } }

implementation: if ( string . length ( ) > 0 ) { if ( string . charAt ( string . length ( ) - 1 ) == c ) { return string . substring ( 0 , string . length ( ) - 1 ) ; } } return string ;


signature:
public class StringUtil { /** * Strips leading and trailing char from given string . */
public static String stripChar ( final String string , final char c ) { } }

implementation: if ( string . length ( ) == 0 ) { return string ; } if ( string . length ( ) == 1 ) { if ( string . charAt ( 0 ) == c ) { return StringPool . EMPTY ; } return string ; } int left = 0 ; int right = string . length ( ) ; if ( string . charAt ( left ) == c ) { left ++ ; } if ( string . charAt ( right - 1 ) == c ) { right -- ; } return string . substring ( left , right ) ;


signature:
public class StringUtil { /** * Strips everything up to the first appearance of given char .
 * Character IS included in the returned string . */
public static String stripToChar ( final String string , final char c ) { } }

implementation: int ndx = string . indexOf ( c ) ; if ( ndx == - 1 ) { return string ; } return string . substring ( ndx ) ;


signature:
public class StringUtil { /** * Strips everything from the first appearance of given char .
 * Character IS NOT included in the returned string . */
public static String stripFromChar ( final String string , final char c ) { } }

implementation: int ndx = string . indexOf ( c ) ; if ( ndx == - 1 ) { return string ; } return string . substring ( 0 , ndx ) ;


signature:
public class StringUtil { /** * Trims array of strings . < code > null < / code > array elements are ignored . */
public static void trimAll ( final String ... strings ) { } }

implementation: for ( int i = 0 ; i < strings . length ; i ++ ) { String string = strings [ i ] ; if ( string != null ) { strings [ i ] = string . trim ( ) ; } }


signature:
public class StringUtil { /** * Trims array of strings where empty strings are set to < code > null < / code > .
 * < code > null < / code > elements of the array are ignored .
 * @ see # trimDown ( String ) */
public static void trimDownAll ( final String ... strings ) { } }

implementation: for ( int i = 0 ; i < strings . length ; i ++ ) { String string = strings [ i ] ; if ( string != null ) { strings [ i ] = trimDown ( string ) ; } }


signature:
public class StringUtil { /** * Trims string and sets to < code > null < / code > if trimmed string is empty . */
public static String trimDown ( String string ) { } }

implementation: string = string . trim ( ) ; if ( string . length ( ) == 0 ) { string = null ; } return string ;


signature:
public class StringUtil { /** * Crops all elements of string array . */
public static void cropAll ( final String ... strings ) { } }

implementation: for ( int i = 0 ; i < strings . length ; i ++ ) { String string = strings [ i ] ; if ( string != null ) { string = crop ( strings [ i ] ) ; } strings [ i ] = string ; }


signature:
public class StringUtil { /** * Trim whitespaces from the left . */
public static String trimLeft ( final String src ) { } }

implementation: int len = src . length ( ) ; int st = 0 ; while ( ( st < len ) && ( CharUtil . isWhitespace ( src . charAt ( st ) ) ) ) { st ++ ; } return st > 0 ? src . substring ( st ) : src ;


signature:
public class StringUtil { /** * Trim whitespaces from the right . */
public static String trimRight ( final String src ) { } }

implementation: int len = src . length ( ) ; int count = len ; while ( ( len > 0 ) && ( CharUtil . isWhitespace ( src . charAt ( len - 1 ) ) ) ) { len -- ; } return ( len < count ) ? src . substring ( 0 , len ) : src ;


signature:
public class StringUtil { /** * Returns indexes of the first region without escaping character .
 * @ see # indexOfRegion ( String , String , String , char , int ) */
public static int [ ] indexOfRegion ( final String string , final String leftBoundary , final String rightBoundary , final int offset ) { } }

implementation: int ndx = offset ; int [ ] res = new int [ 4 ] ; ndx = string . indexOf ( leftBoundary , ndx ) ; if ( ndx == - 1 ) { return null ; } res [ 0 ] = ndx ; ndx += leftBoundary . length ( ) ; res [ 1 ] = ndx ; ndx = string . indexOf ( rightBoundary , ndx ) ; if ( ndx == - 1 ) { return null ; } res [ 2 ] = ndx ; res [ 3 ] = ndx + rightBoundary . length ( ) ; return res ;