public String on(final String string) {
		if (!enabled) {
			return string;
		}

		final StringBuilder sb = new StringBuilder();

		if (prefix != null) {
			sb.append(prefix).append("m");
		}

		sb.append(string);

		if (suffix != null) {
			sb.append(suffix).append("m");
		}

		return sb.toString();
	}

public String on ( final String string ) { if ( ! enabled ) { return string ; } final StringBuilder sb = new StringBuilder ( ) ; if ( prefix != null ) { sb . append ( prefix ) . append ( "m" ) ; } sb . append ( string ) ; if ( suffix != null ) { sb . append ( suffix ) . append ( "m" ) ; } return sb . toString ( ) ; }


private byte[] replaceAsmInstructions(final byte[] classFile, final boolean hasFrames) {
    final Attribute[] attributes = getAttributePrototypes();
    firstField = null;
    lastField = null;
    firstMethod = null;
    lastMethod = null;
    lastRuntimeVisibleAnnotation = null;
    lastRuntimeInvisibleAnnotation = null;
    lastRuntimeVisibleTypeAnnotation = null;
    lastRuntimeInvisibleTypeAnnotation = null;
    moduleWriter = null;
    nestHostClassIndex = 0;
    numberOfNestMemberClasses = 0;
    nestMemberClasses = null;
    firstAttribute = null;
    compute = hasFrames ? MethodWriter.COMPUTE_INSERTED_FRAMES : MethodWriter.COMPUTE_NOTHING;
    new ClassReader(classFile, 0, /* checkClassVersion = */ false)
        .accept(
            this,
            attributes,
            (hasFrames ? ClassReader.EXPAND_FRAMES : 0) | ClassReader.EXPAND_ASM_INSNS);
    return toByteArray();
  }

private
byte
[
]
replaceAsmInstructions
(
final
byte
[
]
classFile
,
final
boolean
hasFrames
)
{
final
Attribute
[
]
attributes
=
getAttributePrototypes
(
)
;
firstField
=
;
lastField
=
;
firstMethod
=
;
lastMethod
=
;
lastRuntimeVisibleAnnotation
=
;
lastRuntimeInvisibleAnnotation
=
;
lastRuntimeVisibleTypeAnnotation
=
;
lastRuntimeInvisibleTypeAnnotation
=
;
moduleWriter
=
;
nestHostClassIndex
=
0
;
numberOfNestMemberClasses
=
0
;
nestMemberClasses
=
;
firstAttribute
=
;
compute
=
hasFrames
MethodWriter
.
COMPUTE_INSERTED_FRAMES
:
MethodWriter
.
COMPUTE_NOTHING
;
new
ClassReader
(
classFile
,
0
,
/* checkClassVersion = */
false
)
.
accept
(
this
,
attributes
,
(
hasFrames
ClassReader
.
EXPAND_FRAMES
:
0
)
|
ClassReader
.
EXPAND_ASM_INSNS
)
;
return
toByteArray
(
)
;
}

Returns the equivalent of the given class file, with the ASM specific instructions replaced
with standard ones. This is done with a ClassReader -> ClassWriter round trip.

@param classFile a class file containing ASM specific instructions, generated by this
ClassWriter.
@param hasFrames whether there is at least one stack map frames in 'classFile'.
@return an equivalent of 'classFile', with the ASM specific instructions replaced with standard
ones.

Returns the equivalent of the given class file with the ASM specific instructions replaced with standard ones . This is done with a ClassReader - &gt ; ClassWriter round trip .


private Attribute[] getAttributePrototypes() {
    Attribute.Set attributePrototypes = new Attribute.Set();
    attributePrototypes.addAttributes(firstAttribute);
    FieldWriter fieldWriter = firstField;
    while (fieldWriter != null) {
      fieldWriter.collectAttributePrototypes(attributePrototypes);
      fieldWriter = (FieldWriter) fieldWriter.fv;
    }
    MethodWriter methodWriter = firstMethod;
    while (methodWriter != null) {
      methodWriter.collectAttributePrototypes(attributePrototypes);
      methodWriter = (MethodWriter) methodWriter.mv;
    }
    return attributePrototypes.toArray();
  }

private Attribute [ ] getAttributePrototypes ( ) { Attribute . Set attributePrototypes = new Attribute . Set ( ) ; attributePrototypes . addAttributes ( firstAttribute ) ; FieldWriter fieldWriter = firstField ; while ( fieldWriter != null ) { fieldWriter . collectAttributePrototypes ( attributePrototypes ) ; fieldWriter = ( FieldWriter ) fieldWriter . fv ; } MethodWriter methodWriter = firstMethod ; while ( methodWriter != null ) { methodWriter . collectAttributePrototypes ( attributePrototypes ) ; methodWriter = ( MethodWriter ) methodWriter . mv ; } return attributePrototypes . toArray ( ) ; }

Returns the prototypes of the attributes used by this class, its fields and its methods.

@return the prototypes of the attributes used by this class, its fields and its methods.

Returns the prototypes of the attributes used by this class its fields and its methods .


public void registerDefaults() {
		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);
	}

public void registerDefaults ( ) { 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 ) ; }


public void register(final Class type, final Class<? extends SqlType> sqlTypeClass) {
		types.put(type, lookupSqlType(sqlTypeClass));
	}

public void register ( final Class type , final Class < ? extends SqlType > sqlTypeClass ) { types . put ( type , lookupSqlType ( sqlTypeClass ) ) ; }


public SqlType lookup(final Class clazz) {
		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;
	}

public SqlType lookup ( final Class clazz ) { 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 ; }

Retrieves SQL type for provided type. All subclasses and interfaces are examined
for matching sql type.

Retrieves SQL type for provided type . All subclasses and interfaces are examined for matching sql type .


public SqlType lookupSqlType(final Class<? extends SqlType> sqlTypeClass) {
		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;
	}

public
SqlType
lookupSqlType
(
final
Class
<
extends
SqlType
>
sqlTypeClass
)
{
SqlType
sqlType
=
sqlTypes
.
get
(
sqlTypeClass
)
;
if
(
sqlType
==
)
{
try
{
sqlType
=
ClassUtil
.
newInstance
(
sqlTypeClass
)
;
}
catch
(
Exception
ex
)
{
throw
new
DbSqlException
(
"SQL type not found: "
+
sqlTypeClass
.
getSimpleName
(
)
,
ex
)
;
}
sqlTypes
.
put
(
sqlTypeClass
,
sqlType
)
;
}
return
sqlType
;
}

Returns sql type instance. Instances are stored for better performances.

Returns sql type instance . Instances are stored for better performances .


public static ProxyInfo socks4Proxy(final String proxyAddress, final int proxyPort, final String proxyUser) {
		return new ProxyInfo(ProxyType.SOCKS4, proxyAddress, proxyPort, proxyUser, null);
	}

public static ProxyInfo socks4Proxy ( final String proxyAddress , final int proxyPort , final String proxyUser ) { return new ProxyInfo ( ProxyType . SOCKS4 , proxyAddress , proxyPort , proxyUser , null ) ; }


public static ProxyInfo socks5Proxy(final String proxyAddress, final int proxyPort, final String proxyUser, final String proxyPassword) {
		return new ProxyInfo(ProxyType.SOCKS5, proxyAddress, proxyPort, proxyUser, proxyPassword);
	}

public static ProxyInfo socks5Proxy ( final String proxyAddress , final int proxyPort , final String proxyUser , final String proxyPassword ) { return new ProxyInfo ( ProxyType . SOCKS5 , proxyAddress , proxyPort , proxyUser , proxyPassword ) ; }


public static ProxyInfo httpProxy(final String proxyAddress, final int proxyPort, final String proxyUser, final String proxyPassword) {
		return new ProxyInfo(ProxyType.HTTP, proxyAddress, proxyPort, proxyUser, proxyPassword);
	}

public static ProxyInfo httpProxy ( final String proxyAddress , final int proxyPort , final String proxyUser , final String proxyPassword ) { return new ProxyInfo ( ProxyType . HTTP , proxyAddress , proxyPort , proxyUser , proxyPassword ) ; }


public int totalThreadTransactions() {
		ArrayList<JtxTransaction> txList = txStack.get();
		if (txList == null) {
			return 0;
		}
		return txList.size();
	}

public int totalThreadTransactions ( ) { ArrayList < JtxTransaction > txList = txStack . get ( ) ; if ( txList == null ) { return 0 ; } return txList . size ( ) ; }

Returns total number of transactions associated with current thread.

Returns total number of transactions associated with current thread .


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

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

Returns total number of transactions of the specified status associated with current thread.

Returns total number of transactions of the specified status associated with current thread .


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

protected
void
associateTransaction
(
final
JtxTransaction
tx
)
{
totalTransactions
++
;
ArrayList
<
JtxTransaction
>
txList
=
txStack
.
get
(
)
;
if
(
txList
==
)
{
txList
=
new
ArrayList
<>
(
)
;
txStack
.
set
(
txList
)
;
}
txList
.
add
(
tx
)
;
// add last
}

Associate transaction to current thread.

Associate transaction to current thread .


protected void continueTx(final JtxTransaction sourceTx, final JtxTransactionMode destMode) {
		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");
		}
	}

Check if propagation of a transaction is possible, due to source and destination transaction modes.
@see #setValidateExistingTransaction(boolean)

Check if propagation of a transaction is possible due to source and destination transaction modes .


protected <E> JtxResourceManager<E> lookupResourceManager(final Class<E> resourceType) {
		//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;
	}

Lookups resource manager for provided type. Throws an exception if provider doesn't exists.

Lookups resource manager for provided type . Throws an exception if provider doesn t exists .


protected C createProxyObject(Class<C> target) {
		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;
	}

protected C createProxyObject ( Class < C > target ) { 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 ; }


protected void append(final String methodName) {
		if (path.length() != 0) {
			path += StringPool.DOT;
		}
		if (methodName.startsWith(StringPool.LEFT_SQ_BRACKET)) {
			path = StringUtil.substring(path, 0, -1);
		}
		path += methodName;
	}

protected void append ( final String methodName ) { if ( path . length ( ) != 0 ) { path += StringPool . DOT ; } if ( methodName . startsWith ( StringPool . LEFT_SQ_BRACKET ) ) { path = StringUtil . substring ( path , 0 , - 1 ) ; } path += methodName ; }


public static String alignLeftAndPad(final String text, final int size) {
		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();
	}

public static String alignLeftAndPad ( final String text , final int size ) { 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 ( ) ; }

Puts the text to the left and pads with spaces until the size is reached.

Puts the text to the left and pads with spaces until the size is reached .


public static String toPrettyString(final Object value) {
		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();
	}

public static String toPrettyString ( final Object value ) { 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 ( ) ; }

Converts object into pretty string. All arrays are iterated.

Converts object into pretty string . All arrays are iterated .


public static String toCamelCase(final String input, final boolean firstCharUppercase, final char separator) {
		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();
	}

public static String toCamelCase ( final String input , final boolean firstCharUppercase , final char separator ) { 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 ( ) ; }

Converts separated string value to CamelCase.

Converts separated string value to CamelCase .


public static String formatParagraph(final String src, final int len, final boolean breakOnWhitespace) {
		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();
	}

public static String formatParagraph ( final String src , final int len , final boolean breakOnWhitespace ) { 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 ( ' ' ) ; from = to ; } return str . toString ( ) ; }


public static String convertTabsToSpaces(final String line, final int tabWidth) {
		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();
	}

public static String convertTabsToSpaces ( final String line , final int tabWidth ) { int tab_index , tab_size ; int last_tab_index = 0 ; int added_chars = 0 ; if ( tabWidth == 0 ) { return StringUtil . remove ( line , ' ' ) ; } StringBuilder result = new StringBuilder ( ) ; while ( ( tab_index = line . indexOf ( ' ' , 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 ( ) ; }

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.

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 escapeJava(final String string) {
		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();
	}

public static String escapeJava ( final String string ) { int strLen = string . length ( ) ; StringBuilder sb = new StringBuilder ( strLen ) ; for ( int i = 0 ; i < strLen ; i ++ ) { char c = string . charAt ( i ) ; switch ( c ) { case ' ' : sb . append ( "\\b" ) ; break ; case ' ' : sb . append ( "\\t" ) ; break ; case ' ' : sb . append ( "\\n" ) ; break ; case ' ' : sb . append ( "\\f" ) ; break ; case ' ' : 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 ( ' ' ) ; } sb . append ( hex ) ; } else { sb . append ( c ) ; } } } return sb . toString ( ) ; }


public static String unescapeJava(final String str) {
		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();
	}

public
static
String
unescapeJava
(
final
String
str
)
{
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
'
'
:
sb
.
append
(
'
'
)
;
break
;
case
'
'
:
sb
.
append
(
'
'
)
;
break
;
case
'
'
:
sb
.
append
(
'
'
)
;
break
;
case
'
'
:
sb
.
append
(
'
'
)
;
break
;
case
'
'
:
sb
.
append
(
'
'
)
;
break
;
case
'
'
:
sb
.
append
(
'
'
)
;
break
;
case
'
'
:
sb
.
append
(
'
'
)
;
break
;
case
'
'
:
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
(
)
;
}


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

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

Returns Petite bean instance. Bean name will be resolved from provided type.

Returns Petite bean instance . Bean name will be resolved from provided type .


public <T> T getBean(final String name) {

		// 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;
	}

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)

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 .


protected void initBeanDefinition(final BeanDefinition def) {
		// 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());
		}
	}

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

Resolves and initializes bean definition. May be called multiple times.

Resolves and initializes bean definition . May be called multiple times .


protected Object invokeProvider(final ProviderDefinition provider) {
		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");
	}

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


public void addBean(final String name, final Object bean, WiringMode wiringMode) {
		wiringMode = petiteConfig.resolveWiringMode(wiringMode);
		registerPetiteBean(bean.getClass(), name, SingletonScope.class, wiringMode, false, null);
		BeanDefinition def = lookupExistingBeanDefinition(name);
		registerBeanAndWireAndInjectParamsAndInvokeInitMethods(new BeanData(this, def, bean));
	}

Adds object instance to the container as singleton bean.

Adds object instance to the container as singleton bean .


public void setBeanProperty(final String name, final Object value) {
		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);
		}
	}

public
void
setBeanProperty
(
final
String
name
,
final
Object
value
)
{
Object
bean
=
;
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
!=
)
{
break
;
}
ndx
;
}
if
(
bean
==
)
{
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
)
;
}
}


public Object getBeanProperty(final String name) {
		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);
		}
	}


public void shutdown() {
		scopes.forEachValue(Scope::shutdown);

		externalsCache.clear();
		beans.clear();
		beansAlt.clear();
		scopes.clear();
		providers.clear();
		beanCollections.clear();
	}

public void shutdown ( ) { scopes . forEachValue ( Scope :: shutdown ) ; externalsCache . clear ( ) ; beans . clear ( ) ; beansAlt . clear ( ) ; scopes . clear ( ) ; providers . clear ( ) ; beanCollections . clear ( ) ; }

Shutdowns container. After container is down, it can't be used anymore.

Shutdowns container . After container is down it can t be used anymore .


public static MethodParameter[] resolveParameters(final AccessibleObject methodOrCtor) {
		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);
		}
	}

public
static
MethodParameter
[
]
resolveParameters
(
final
AccessibleObject
methodOrCtor
)
{
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
==
)
{
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
)
;
}
}

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.

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 .


@Override
	public int doAfterBody() throws JspException {
		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;
	}

@ Override public int doAfterBody ( ) throws JspException { 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 ; }


public String getValue(final String... profiles) {
		if (hasMacro) {
			return propsData.resolveMacros(value, profiles);
		}
		return value;
	}

public String getValue ( final String ... profiles ) { if ( hasMacro ) { return propsData . resolveMacros ( value , profiles ) ; } return value ; }

Returns the property value, with replaced macros.

Returns the property value with replaced macros .


@Override
	public void end() {
		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");
		}
	}

@
Override
public
void
end
(
)
{
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"
)
;
}
}

Finishes the tree building. Closes unclosed tags.

Finishes the tree building . Closes unclosed tags .


protected Element createElementNode(final Tag tag) {
		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);
	}

protected
Element
createElementNode
(
final
Tag
tag
)
{
boolean
hasVoidTags
=
htmlVoidRules
!=
;
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
)
;
}

Creates new element with correct configuration.

Creates new element with correct configuration .


@Override
	public void tag(final Tag tag) {
		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;
		}
	}


protected void removeLastChildNodeIfEmptyText(final Node parentNode, final boolean closedTag) {
		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();
		}
	}

protected void removeLastChildNodeIfEmptyText ( final Node parentNode , final boolean closedTag ) { 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 ( ) ; } }

Removes last child node if contains just empty text.

Removes last child node if contains just empty text .


public String getQueryString() {
		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();
	}

public
String
getQueryString
(
)
{
if
(
sqlTemplate
==
)
{
return
toString
(
)
;
}
if
(
parameterValues
==
)
{
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
=
;
if
(
parameterValues
.
size
(
)
>
1
+
qMarkCount
)
{
value
=
parameterValues
.
get
(
1
+
qMarkCount
)
;
qMarkCount
++
;
}
else
{
if
(
!
tok
.
hasMoreTokens
(
)
)
{
value
=
""
;
}
}
if
(
value
==
)
{
value
=
"?"
;
}
sb
.
append
(
value
)
;
}
catch
(
Throwable
th
)
{
sb
.
append
(
"--- Building query failed: "
)
.
append
(
th
.
toString
(
)
)
;
}
}
return
sb
.
toString
(
)
.
trim
(
)
;
}


protected String getActionClassName(final Object action) {
		Class clazz = action.getClass();

		clazz = ProxettaUtil.resolveTargetClass(clazz);

		return clazz.getName();
	}

protected String getActionClassName ( final Object action ) { Class clazz = action . getClass ( ) ; clazz = ProxettaUtil . resolveTargetClass ( clazz ) ; return clazz . getName ( ) ; }

Returns correct action class name. Detects Proxetta classes.

Returns correct action class name . Detects Proxetta classes .


protected int calculateTo(final int from, final int count, final int size) {
		int to = size;
		if (count != -1) {
			to = from + count;
			if (to > size) {
				to = size;
			}
		}
		return to;
	}

protected int calculateTo ( final int from , final int count , final int size ) { int to = size ; if ( count != - 1 ) { to = from + count ; if ( to > size ) { to = size ; } } return to ; }


protected void iterateCollection(final Collection collection, final int from, final int count, final PageContext pageContext) throws JspException {
		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++;
		}
	}

protected void iterateCollection ( final Collection collection , final int from , final int count , final PageContext pageContext ) throws JspException { 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 ++ ; } }


protected void iterateArray(final Object[] array, final int from, final int count, final PageContext pageContext) throws JspException {
		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);
		}
	}

protected void iterateArray ( final Object [ ] array , final int from , final int count , final PageContext pageContext ) throws JspException { 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 ) ; } }


public static String replace(final String s, final String sub, final String with) {
		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();
	}

public static String replace ( final String s , final String sub , final String with ) { 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 ( ) ; }

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

Replaces all occurrences of a certain pattern in a string with a replacement string . This is the fastest replace function known to author .


public static String replaceChar(final String s, final char sub, final char with) {
		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);
	}

public static String replaceChar ( final String s , final char sub , final char with ) { 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 ) ; }

Replaces all occurrences of a character in a string.

@param s      input string
@param sub    character to replace
@param with   character to replace with

Replaces all occurrences of a character in a string .


public static String replaceChars(final String s, final char[] sub, final char[] with) {
		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);
	}

public static String replaceChars ( final String s , final char [ ] sub , final char [ ] with ) { 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 ) ; }

Replaces all occurrences of a characters in a string.

@param s      input string
@param sub    characters to replace
@param with   characters to replace with

Replaces all occurrences of a characters in a string .


public static String replaceFirst(final String s, final String sub, final String with) {
		int i = s.indexOf(sub);
		if (i == -1) {
			return s;
		}
		return s.substring(0, i) + with + s.substring(i + sub.length());
	}

public static String replaceFirst ( final String s , final String sub , final String with ) { int i = s . indexOf ( sub ) ; if ( i == - 1 ) { return s ; } return s . substring ( 0 , i ) + with + s . substring ( i + sub . length ( ) ) ; }

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

Replaces the very first occurrence of a substring with supplied string .


public static String replaceFirst(final String s, final char sub, final char with) {
		int index = s.indexOf(sub);
		if (index == -1) {
			return s;
		}
		char[] str = s.toCharArray();
		str[index] = with;
		return new String(str);
	}

public static String replaceFirst ( final String s , final char sub , final char with ) { int index = s . indexOf ( sub ) ; if ( index == - 1 ) { return s ; } char [ ] str = s . toCharArray ( ) ; str [ index ] = with ; return new String ( str ) ; }

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

Replaces the very first occurrence of a character in a string .


public static String replaceLast(final String s, final String sub, final String with) {
		int i = s.lastIndexOf(sub);
		if (i == -1) {
			return s;
		}
		return s.substring(0, i) + with + s.substring(i + sub.length());
	}

public static String replaceLast ( final String s , final String sub , final String with ) { int i = s . lastIndexOf ( sub ) ; if ( i == - 1 ) { return s ; } return s . substring ( 0 , i ) + with + s . substring ( i + sub . length ( ) ) ; }

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

Replaces the very last occurrence of a substring with supplied string .


public static String replaceLast(final String s, final char sub, final char with) {
		int index = s.lastIndexOf(sub);
		if (index == -1) {
			return s;
		}
		char[] str = s.toCharArray();
		str[index] = with;
		return new String(str);
	}

public static String replaceLast ( final String s , final char sub , final char with ) { int index = s . lastIndexOf ( sub ) ; if ( index == - 1 ) { return s ; } char [ ] str = s . toCharArray ( ) ; str [ index ] = with ; return new String ( str ) ; }

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

Replaces the very last occurrence of a character in a string .


public static String remove(final String s, final String sub) {
		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();
	}

public static String remove ( final String s , final String sub ) { 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 ( ) ; }

Removes all substring occurrences from the string.

@param s      source string
@param sub    substring to remove

Removes all substring occurrences from the string .


public static String remove(final String string, final char ch) {
		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);
	}

public
static
String
remove
(
final
String
string
,
final
char
ch
)
{
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
)
;
}

Removes a single character from string.

@param string    source string
@param ch  character to remove

Removes a single character from string .


public static boolean isAllEmpty(final String... strings) {
		for (String string : strings) {
			if (!isEmpty(string)) {
				return false;
			}
		}
		return true;
	}

public static boolean isAllEmpty ( final String ... strings ) { for ( String string : strings ) { if ( ! isEmpty ( string ) ) { return false ; } } return true ; }

Determines if string array contains empty strings.
@see #isEmpty(CharSequence)

Determines if string array contains empty strings .


public static boolean isAllBlank(final String... strings) {
		for (String string : strings) {
			if (!isBlank(string)) {
				return false;
			}
		}
		return true;
	}

public static boolean isAllBlank ( final String ... strings ) { for ( String string : strings ) { if ( ! isBlank ( string ) ) { return false ; } } return true ; }

Determines if string array contains just blank strings.

Determines if string array contains just blank strings .


public static String[] toStringArray(final Object value) {
		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);
		}
	}

public static String [ ] toStringArray ( final Object value ) { 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 ) ; } }

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.

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 .


private static String changeFirstCharacterCase(final boolean capitalize, final String string) {
		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);
	}

private
static
String
changeFirstCharacterCase
(
final
boolean
capitalize
,
final
String
string
)
{
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
)
;
}

Internal method for changing the first character case.

Internal method for changing the first character case .


public static String title(final String string) {
		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);
	}

public static String title ( final String string ) { 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 ) ; }

Makes a title-cased string from given input.

Makes a title - cased string from given input .


public static String compressChars(final String s, final char c) {
		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();
	}

public static String compressChars ( final String s , final char c ) { 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 ( ) ; }

Compress multiple occurrences of given char into one appearance.

Compress multiple occurrences of given char into one appearance .


public static boolean startsWithIgnoreCase(final String src, final String subS, final int startIndex) {
		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;
	}

public static boolean startsWithIgnoreCase ( final String src , final String subS , final int startIndex ) { 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 ; }

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 true if the character sequence represented by the argument is
a prefix of the character sequence represented by this string;
false otherwise.

Tests if this string starts with the specified prefix with ignored case and with the specified prefix beginning a specified index .


public static boolean endsWithChar(final String s, final char c) {
		if (s.length() == 0) {
			return false;
		}
		return s.charAt(s.length() - 1) == c;
	}

public static boolean endsWithChar ( final String s , final char c ) { if ( s . length ( ) == 0 ) { return false ; } return s . charAt ( s . length ( ) - 1 ) == c ; }

Returns if string ends with provided character.

Returns if string ends with provided character .


public static int countIgnoreCase(final String source, final String sub) {
		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;
	}

public static int countIgnoreCase ( final String source , final String sub ) { 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 ; }

Count substring occurrences in a source string, ignoring case.

@param source	source string
@param sub		substring to count
@return			number of substring occurrences

Count substring occurrences in a source string ignoring case .


public static boolean equalsIgnoreCase(final String[] as, final String[] as1) {
		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;
	}

public static boolean equalsIgnoreCase ( final String [ ] as , final String [ ] as1 ) { 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 ; }

Compares two string arrays.

@param as     first string array
@param as1    second string array

@return true if all array elements matches


public static int indexOfWhitespace(final String string, final int startindex, final int endindex) {
		for (int i = startindex; i < endindex; i++) {
			if (CharUtil.isWhitespace(string.charAt(i))) {
				return i;
			}
		}
		return -1;
	}

public static int indexOfWhitespace ( final String string , final int startindex , final int endindex ) { for ( int i = startindex ; i < endindex ; i ++ ) { if ( CharUtil . isWhitespace ( string . charAt ( i ) ) ) { return i ; } } return - 1 ; }

Returns first index of a whitespace character, starting from specified index offset.

Returns first index of a whitespace character starting from specified index offset .


public static String stripLeadingChar(final String string, final char c) {
		if (string.length() > 0) {
			if (string.charAt(0) == c) {
				return string.substring(1);
			}
		}
		return string;
	}

public static String stripLeadingChar ( final String string , final char c ) { if ( string . length ( ) > 0 ) { if ( string . charAt ( 0 ) == c ) { return string . substring ( 1 ) ; } } return string ; }

Strips leading char if string starts with one.

Strips leading char if string starts with one .


public static String stripTrailingChar(final String string, final char c) {
		if (string.length() > 0) {
			if (string.charAt(string.length() - 1) == c) {
				return string.substring(0, string.length() - 1);
			}
		}
		return string;
	}

public static String stripTrailingChar ( final String string , final char c ) { if ( string . length ( ) > 0 ) { if ( string . charAt ( string . length ( ) - 1 ) == c ) { return string . substring ( 0 , string . length ( ) - 1 ) ; } } return string ; }

Strips trailing char if string ends with one.

Strips trailing char if string ends with one .


public static String stripChar(final String string, final char c) {
		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);
	}

public static String stripChar ( final String string , final char c ) { 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 ) ; }

Strips leading and trailing char from given string.

Strips leading and trailing char from given string .


public static String stripToChar(final String string, final char c) {
		int ndx = string.indexOf(c);

		if (ndx == -1) {
			return string;
		}

		return string.substring(ndx);
	}

public static String stripToChar ( final String string , final char c ) { int ndx = string . indexOf ( c ) ; if ( ndx == - 1 ) { return string ; } return string . substring ( ndx ) ; }

Strips everything up to the first appearance of given char.
Character IS included in the returned string.

Strips everything up to the first appearance of given char . Character IS included in the returned string .


public static String stripFromChar(final String string, final char c) {
		int ndx = string.indexOf(c);

		if (ndx == -1) {
			return string;
		}

		return string.substring(0, ndx);
	}

public static String stripFromChar ( final String string , final char c ) { int ndx = string . indexOf ( c ) ; if ( ndx == - 1 ) { return string ; } return string . substring ( 0 , ndx ) ; }

Strips everything from the first appearance of given char.
Character IS NOT included in the returned string.

Strips everything from the first appearance of given char . Character IS NOT included in the returned string .


public static void cropAll(final String... strings) {
		for (int i = 0; i < strings.length; i++) {
			String string = strings[i];
			if (string != null) {
				string = crop(strings[i]);
			}
			strings[i] = string;
		}
	}

public static void cropAll ( final String ... strings ) { for ( int i = 0 ; i < strings . length ; i ++ ) { String string = strings [ i ] ; if ( string != null ) { string = crop ( strings [ i ] ) ; } strings [ i ] = string ; } }


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

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


public static String trimRight(final String src) {
		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;
	}

public static String trimRight ( final String src ) { 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 ; }


public static int[] indexOfRegion(final String string, final String leftBoundary, final String rightBoundary, final int offset) {
		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;
	}

public static int [ ] indexOfRegion ( final String string , final String leftBoundary , final String rightBoundary , final int offset ) { 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 ; }

Returns indexes of the first region without escaping character.
@see #indexOfRegion(String, String, String, char, int)

Returns indexes of the first region without escaping character .


public static String join(final Collection collection, final char separator) {
		if (collection == null) {
			return null;
		}

		if (collection.size() == 0) {
			return StringPool.EMPTY;
		}

		final StringBuilder sb = new StringBuilder(collection.size() * 16);
		final Iterator it = collection.iterator();

		for (int i = 0; i < collection.size(); i++) {

			if (i > 0) {
				sb.append(separator);
			}

			sb.append(it.next());
		}

		return sb.toString();
	}

public static String join ( final Collection collection , final char separator ) { if ( collection == null ) { return null ; } if ( collection . size ( ) == 0 ) { return StringPool . EMPTY ; } final StringBuilder sb = new StringBuilder ( collection . size ( ) * 16 ) ; final Iterator it = collection . iterator ( ) ; for ( int i = 0 ; i < collection . size ( ) ; i ++ ) { if ( i > 0 ) { sb . append ( separator ) ; } sb . append ( it . next ( ) ) ; } return sb . toString ( ) ; }

Joins an collection of objects into one string with separator.

Joins an collection of objects into one string with separator .


public static String join(final Object[] array, final String separator) {
		if (array == null) {
			return null;
		}

		if (array.length == 0) {
			return StringPool.EMPTY;
		}

		if (array.length == 1) {
			return String.valueOf(array[0]);
		}

		final StringBuilder sb = new StringBuilder(array.length * 16);

		for (int i = 0; i < array.length; i++) {

			if (i > 0) {
				sb.append(separator);
			}

			sb.append(array[i]);
		}

		return sb.toString();
	}

public static String join ( final Object [ ] array , final String separator ) { if ( array == null ) { return null ; } if ( array . length == 0 ) { return StringPool . EMPTY ; } if ( array . length == 1 ) { return String . valueOf ( array [ 0 ] ) ; } final StringBuilder sb = new StringBuilder ( array . length * 16 ) ; for ( int i = 0 ; i < array . length ; i ++ ) { if ( i > 0 ) { sb . append ( separator ) ; } sb . append ( array [ i ] ) ; } return sb . toString ( ) ; }

Joins an array of objects into one string with separator.

Joins an array of objects into one string with separator .


public static String convertCharset(final String source, final String srcCharsetName, final String newCharsetName) {
		if (srcCharsetName.equals(newCharsetName)) {
			return source;
		}
		return StringUtil.newString(StringUtil.getBytes(source, srcCharsetName), newCharsetName);
	}

public static String convertCharset ( final String source , final String srcCharsetName , final String newCharsetName ) { if ( srcCharsetName . equals ( newCharsetName ) ) { return source ; } return StringUtil . newString ( StringUtil . getBytes ( source , srcCharsetName ) , newCharsetName ) ; }

Converts string charset. If charset names are the same, the same string is returned.

Converts string charset . If charset names are the same the same string is returned .


public static boolean isCharAtEqual(final String string, final int index, final char charToCompare) {
		if ((index < 0) || (index >= string.length())) {
			return false;
		}
		return string.charAt(index) == charToCompare;
	}

public static boolean isCharAtEqual ( final String string , final int index , final char charToCompare ) { if ( ( index < 0 ) || ( index >= string . length ( ) ) ) { return false ; } return string . charAt ( index ) == charToCompare ; }

Safely compares provided char with char on given location.

Safely compares provided char with char on given location .


public static String surround(String string, final String prefix, final String suffix) {
		if (!string.startsWith(prefix)) {
			string = prefix + string;
		}
		if (!string.endsWith(suffix)) {
			string += suffix;
		}
		return string;
	}

public static String surround ( String string , final String prefix , final String suffix ) { if ( ! string . startsWith ( prefix ) ) { string = prefix + string ; } if ( ! string . endsWith ( suffix ) ) { string += suffix ; } return string ; }

Surrounds the string with provided prefix and suffix if such missing from string.

Surrounds the string with provided prefix and suffix if such missing from string .


public static String prefix(String string, final String prefix) {
		if (!string.startsWith(prefix)) {
			string = prefix + string;
		}
		return string;
	}

public static String prefix ( String string , final String prefix ) { if ( ! string . startsWith ( prefix ) ) { string = prefix + string ; } return string ; }


public static String suffix(String string, final String suffix) {
		if (!string.endsWith(suffix)) {
			string += suffix;
		}
		return string;
	}

public static String suffix ( String string , final String suffix ) { if ( ! string . endsWith ( suffix ) ) { string += suffix ; } return string ; }


public static String cutToIndexOf(String string, final String substring) {
		int i = string.indexOf(substring);
		if (i != -1) {
			string = string.substring(0, i);
		}
		return string;
	}

public static String cutToIndexOf ( String string , final String substring ) { int i = string . indexOf ( substring ) ; if ( i != - 1 ) { string = string . substring ( 0 , i ) ; } return string ; }

Cuts the string from beginning to the first index of provided substring.

Cuts the string from beginning to the first index of provided substring .


public static String cutFromIndexOf(String string, final String substring) {
		int i = string.indexOf(substring);
		if (i != -1) {
			string = string.substring(i);
		}
		return string;
	}

public static String cutFromIndexOf ( String string , final String substring ) { int i = string . indexOf ( substring ) ; if ( i != - 1 ) { string = string . substring ( i ) ; } return string ; }

Cuts the string from the first index of provided substring to the end.

Cuts the string from the first index of provided substring to the end .


public static String cutPrefix(String string, final String prefix) {
		if (string.startsWith(prefix)) {
			string = string.substring(prefix.length());
		}
		return string;
	}

public static String cutPrefix ( String string , final String prefix ) { if ( string . startsWith ( prefix ) ) { string = string . substring ( prefix . length ( ) ) ; } return string ; }


public static String cutSuffix(String string, final String suffix) {
		if (string.endsWith(suffix)) {
			string = string.substring(0, string.length() - suffix.length());
		}
		return string;
	}

public static String cutSuffix ( String string , final String suffix ) { if ( string . endsWith ( suffix ) ) { string = string . substring ( 0 , string . length ( ) - suffix . length ( ) ) ; } return string ; }


public static String cutSurrounding(final String string, final String prefix, final String suffix) {
		int start = 0;
		int end = string.length();

		if (string.startsWith(prefix)) {
			start = prefix.length();
		}
		if (string.endsWith(suffix)) {
			end -= suffix.length();
		}

		if (end <= start) {
			return StringPool.EMPTY;
		}

		return string.substring(start, end);
	}

public static String cutSurrounding ( final String string , final String prefix , final String suffix ) { int start = 0 ; int end = string . length ( ) ; if ( string . startsWith ( prefix ) ) { start = prefix . length ( ) ; } if ( string . endsWith ( suffix ) ) { end -= suffix . length ( ) ; } if ( end <= start ) { return StringPool . EMPTY ; } return string . substring ( start , end ) ; }

Removes surrounding prefix and suffixes.

Removes surrounding prefix and suffixes .


public static String insert(final String src, final String insert, int offset) {
		if (offset < 0) {
			offset = 0;
		}
		if (offset > src.length()) {
			offset = src.length();
		}
		StringBuilder sb = new StringBuilder(src);
		sb.insert(offset, insert);
		return sb.toString();
	}

public static String insert ( final String src , final String insert , int offset ) { if ( offset < 0 ) { offset = 0 ; } if ( offset > src . length ( ) ) { offset = src . length ( ) ; } StringBuilder sb = new StringBuilder ( src ) ; sb . insert ( offset , insert ) ; return sb . toString ( ) ; }


public static String repeat(final String source, int count) {
		StringBand result = new StringBand(count);
		while (count > 0) {
			result.append(source);
			count--;
		}
		return result.toString();
	}

public static String repeat ( final String source , int count ) { StringBand result = new StringBand ( count ) ; while ( count > 0 ) { result . append ( source ) ; count -- ; } return result . toString ( ) ; }

Creates a new string that contains the provided string a number of times.

Creates a new string that contains the provided string a number of times .


public static String reverse(final String s) {
		StringBuilder result = new StringBuilder(s.length());
		for (int i = s.length() -1; i >= 0; i--) {
			result.append(s.charAt(i));
		}
		return result.toString();
	}

public static String reverse ( final String s ) { StringBuilder result = new StringBuilder ( s . length ( ) ) ; for ( int i = s . length ( ) - 1 ; i >= 0 ; i -- ) { result . append ( s . charAt ( i ) ) ; } return result . toString ( ) ; }


public static String maxCommonPrefix(final String one, final String two) {
        final int minLength = Math.min(one.length(), two.length());

        final StringBuilder sb = new StringBuilder(minLength);
        for (int pos = 0; pos < minLength; pos++) {
            final char currentChar = one.charAt(pos);
            if (currentChar != two.charAt(pos)) {
                break;
            }
            sb.append(currentChar);
        }

		return sb.toString();
	}

public static String maxCommonPrefix ( final String one , final String two ) { final int minLength = Math . min ( one . length ( ) , two . length ( ) ) ; final StringBuilder sb = new StringBuilder ( minLength ) ; for ( int pos = 0 ; pos < minLength ; pos ++ ) { final char currentChar = one . charAt ( pos ) ; if ( currentChar != two . charAt ( pos ) ) { break ; } sb . append ( currentChar ) ; } return sb . toString ( ) ; }

Returns max common prefix of two strings.

Returns max common prefix of two strings .


public static String findCommonPrefix(final String... strings) {
		StringBuilder prefix = new StringBuilder();
		int index = 0;
		char c = 0;

		loop:
		while (true) {
			for (int i = 0; i < strings.length; i++) {

				String s = strings[i];
				if (index == s.length()) {
					break loop;
				}

				if (i == 0) {
					c = s.charAt(index);
				} else {
					if (s.charAt(index) != c) {
						break loop;
					}
				}
			}

			index++;
			prefix.append(c);
		}
		return prefix.length() == 0 ? StringPool.EMPTY : prefix.toString();
	}

public static String findCommonPrefix ( final String ... strings ) { StringBuilder prefix = new StringBuilder ( ) ; int index = 0 ; char c = 0 ; loop : while ( true ) { for ( int i = 0 ; i < strings . length ; i ++ ) { String s = strings [ i ] ; if ( index == s . length ( ) ) { break loop ; } if ( i == 0 ) { c = s . charAt ( index ) ; } else { if ( s . charAt ( index ) != c ) { break loop ; } } } index ++ ; prefix . append ( c ) ; } return prefix . length ( ) == 0 ? StringPool . EMPTY : prefix . toString ( ) ; }

Finds common prefix for several strings. Returns an empty string if
arguments do not have a common prefix.

Finds common prefix for several strings . Returns an empty string if arguments do not have a common prefix .


public static String shorten(String s, int length, final String suffix) {
		length -= suffix.length();

		if (s.length() > length) {
			for (int j = length; j >= 0; j--) {
				if (CharUtil.isWhitespace(s.charAt(j))) {
					length = j;
					break;
				}
			}
			String temp = s.substring(0, length);
			s = temp.concat(suffix);
		}

		return s;
	}

public static String shorten ( String s , int length , final String suffix ) { length -= suffix . length ( ) ; if ( s . length ( ) > length ) { for ( int j = length ; j >= 0 ; j -- ) { if ( CharUtil . isWhitespace ( s . charAt ( j ) ) ) { length = j ; break ; } } String temp = s . substring ( 0 , length ) ; s = temp . concat ( suffix ) ; } return s ; }


public static String toUpperCase(final String s, Locale locale) {
		if (s == null) {
			return null;
		}

		StringBuilder sb = null;

		for (int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);

			if (c > 127) {
				// found non-ascii char, fallback to the slow unicode detection

				if (locale == null) {
					locale = Locale.getDefault();
				}

				return s.toUpperCase(locale);
			}

			if ((c >= 'a') && (c <= 'z')) {
				if (sb == null) {
					sb = new StringBuilder(s);
				}

				sb.setCharAt(i, (char)(c - 32));
			}
		}

		if (sb == null) {
			return s;
		}

		return sb.toString();
	}

Converts all of the characters in the string to upper case, based on the
locale.

@param  s the string to convert
@param  locale apply this locale's rules
@return the string, converted to upper case, or null if the
string is null

Converts all of the characters in the string to upper case based on the locale .


public static String removeQuotes(final String string) {
		if (
			(startsWithChar(string, '\'') && endsWithChar(string, '\'')) ||
			(startsWithChar(string, '"') && endsWithChar(string, '"')) ||
			(startsWithChar(string, '`') && endsWithChar(string, '`'))
		) {
			return substring(string, 1, -1);
		}
		return string;
	}

public static String removeQuotes ( final String string ) { if ( ( startsWithChar ( string , ' ' ) && endsWithChar ( string , ' ' ) ) || ( startsWithChar ( string , ' ' ) && endsWithChar ( string , ' ' ) ) || ( startsWithChar ( string , ' ' ) && endsWithChar ( string , ' ' ) ) ) { return substring ( string , 1 , - 1 ) ; } return string ; }

Removes starting and ending single or double quotes.

Removes starting and ending single or double quotes .


public static String toHexString(final byte[] bytes) {
		char[] chars = new char[bytes.length * 2];

		int i = 0;
		for (byte b : bytes) {
			chars[i++] = CharUtil.int2hex((b & 0xF0) >> 4);
			chars[i++] = CharUtil.int2hex(b & 0x0F);
		}

		return new String(chars);
	}

public static String toHexString ( final byte [ ] bytes ) { char [ ] chars = new char [ bytes . length * 2 ] ; int i = 0 ; for ( byte b : bytes ) { chars [ i ++ ] = CharUtil . int2hex ( ( b & 0xF0 ) >> 4 ) ; chars [ i ++ ] = CharUtil . int2hex ( b & 0x0F ) ; } return new String ( chars ) ; }


public static byte[] getBytes(final String string) {
		try {
			return string.getBytes(JoddCore.encoding);
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}
	}

public static byte [ ] getBytes ( final String string ) { try { return string . getBytes ( JoddCore . encoding ) ; } catch ( UnsupportedEncodingException e ) { throw new RuntimeException ( e ) ; } }

Returns String bytes using Jodds default encoding.

Returns String bytes using Jodds default encoding .


public static char detectQuoteChar(final String str) {
		if (str.length() < 2) {
			return 0;
		}

		final char c = str.charAt(0);

		if (c != str.charAt(str.length() - 1)) {
			return 0;
		}

		if (c == '\'' || c == '"' || c == '`') {
			return c;
		}

		return 0;
	}

public static char detectQuoteChar ( final String str ) { if ( str . length ( ) < 2 ) { return 0 ; } final char c = str . charAt ( 0 ) ; if ( c != str . charAt ( str . length ( ) - 1 ) ) { return 0 ; } if ( c == ' ' || c == ' ' || c == ' ' ) { return c ; } return 0 ; }


public void visit(final String name, final Object value) {
    if (av != null) {
      av.visit(name, value);
    }
  }

public void visit ( final String name , final Object value ) { if ( av != null ) { av . visit ( name , value ) ; } }

Visits a primitive value of the annotation.

@param name the value name.
@param value the actual value, whose type must be {@link Byte}, {@link Boolean}, {@link
Character}, {@link Short}, {@link Integer} , {@link Long}, {@link Float}, {@link Double},
{@link String} or {@link Type} of {@link Type#OBJECT} or {@link Type#ARRAY} sort. This
value can also be an array of byte, boolean, short, char, int, long, float or double values
(this is equivalent to using {@link #visitArray} and visiting each array element in turn,
but is more convenient).

Visits a primitive value of the annotation .


public void visitEnum(final String name, final String descriptor, final String value) {
    if (av != null) {
      av.visitEnum(name, descriptor, value);
    }
  }

public void visitEnum ( final String name , final String descriptor , final String value ) { if ( av != null ) { av . visitEnum ( name , descriptor , value ) ; } }

Visits an enumeration value of the annotation.

@param name the value name.
@param descriptor the class descriptor of the enumeration class.
@param value the actual enumeration value.

Visits an enumeration value of the annotation .


public AnnotationVisitor visitAnnotation(final String name, final String descriptor) {
    if (av != null) {
      return av.visitAnnotation(name, descriptor);
    }
    return null;
  }

public AnnotationVisitor visitAnnotation ( final String name , final String descriptor ) { if ( av != null ) { return av . visitAnnotation ( name , descriptor ) ; } return null ; }

Visits a nested annotation value of the annotation.

@param name the value name.
@param descriptor the class descriptor of the nested annotation class.
@return a visitor to visit the actual nested annotation value, or {@literal null} if this
visitor is not interested in visiting this nested annotation. <i>The nested annotation
value must be fully visited before calling other methods on this annotation visitor</i>.

Visits a nested annotation value of the annotation .


public <E> DbEntityDescriptor<E> registerType(final Class<E> type) {
		DbEntityDescriptor<E> ded = createDbEntityDescriptor(type);
		DbEntityDescriptor<E> existing = descriptorsMap.put(type, ded);

		if (log.isDebugEnabled()) {
			log.debug("Register " + type.getName() + " as " + ded.getTableName());
		}

		if (existing != null) {
			if (ded.getType() == type) {
				return ded;
			}
			throw new DbOomException("Type already registered: " + existing.getType());
		}

		existing = entityNamesMap.put(ded.getEntityName(), ded);

		if (existing != null) {
			throw new DbOomException("Name '" + ded.getEntityName() + "' already mapped to an entity: " + existing.getType());
		}
		return ded;
	}

public
<
E
>
DbEntityDescriptor
<
E
>
registerType
(
final
Class
<
E
>
type
)
{
DbEntityDescriptor
<
E
>
ded
=
createDbEntityDescriptor
(
type
)
;
DbEntityDescriptor
<
E
>
existing
=
descriptorsMap
.
put
(
type
,
ded
)
;
if
(
log
.
isDebugEnabled
(
)
)
{
log
.
debug
(
"Register "
+
type
.
getName
(
)
+
" as "
+
ded
.
getTableName
(
)
)
;
}
if
(
existing
!=
)
{
if
(
ded
.
getType
(
)
==
type
)
{
return
ded
;
}
throw
new
DbOomException
(
"Type already registered: "
+
existing
.
getType
(
)
)
;
}
existing
=
entityNamesMap
.
put
(
ded
.
getEntityName
(
)
,
ded
)
;
if
(
existing
!=
)
{
throw
new
DbOomException
(
"Name '"
+
ded
.
getEntityName
(
)
+
"' already mapped to an entity: "
+
existing
.
getType
(
)
)
;
}
return
ded
;
}

Registers just type and entity names. Enough for most usages.

Registers just type and entity names . Enough for most usages .


public <E> DbEntityDescriptor<E> registerEntity(final Class<E> type, final boolean force) {
		if (force) {
			removeEntity(type);
		}
		return registerEntity(type);
	}

public < E > DbEntityDescriptor < E > registerEntity ( final Class < E > type , final boolean force ) { if ( force ) { removeEntity ( type ) ; } return registerEntity ( type ) ; }

Registers entity. Existing entity will be removed if exist, so no exception will be thrown.

Registers entity . Existing entity will be removed if exist so no exception will be thrown .


public <E> DbEntityDescriptor<E> removeEntity(final Class<E> type) {
		DbEntityDescriptor<E> ded = descriptorsMap.remove(type);
		if (ded == null) {
			ded = createDbEntityDescriptor(type);
		}
		entityNamesMap.remove(ded.getEntityName());
		tableNamesMap.remove(ded.getTableName());
		return ded;
	}

public < E > DbEntityDescriptor < E > removeEntity ( final Class < E > type ) { DbEntityDescriptor < E > ded = descriptorsMap . remove ( type ) ; if ( ded == null ) { ded = createDbEntityDescriptor ( type ) ; } entityNamesMap . remove ( ded . getEntityName ( ) ) ; tableNamesMap . remove ( ded . getTableName ( ) ) ; return ded ; }

Removes entity and returns removed descriptor.

Removes entity and returns removed descriptor .


public <E> E createEntityInstance(final Class<E> type) {
		try {
			return ClassUtil.newInstance(type);
		} catch (Exception ex) {
			throw new DbOomException(ex);
		}
	}

public < E > E createEntityInstance ( final Class < E > type ) { try { return ClassUtil . newInstance ( type ) ; } catch ( Exception ex ) { throw new DbOomException ( ex ) ; } }


public WrapperProxettaFactory setTargetInterface(final Class targetInterface) {
		if (!targetInterface.isInterface()) {
			throw new ProxettaException("Not an interface: " + targetInterface.getName());
		}
		this.targetInterface = targetInterface;
		return this;
	}

public
WrapperProxettaFactory
setTargetInterface
(
final
Class
targetInterface
)
{
if
(
!
targetInterface
.
isInterface
(
)
)
{
throw
new
ProxettaException
(
"Not an interface: "
+
targetInterface
.
getName
(
)
)
;
}
this
.
targetInterface
=
targetInterface
;
return
this
;
}

Defines the interface of the resulting class.

Defines the interface of the resulting class .


public void injectTargetIntoWrapper(final Object target, final Object wrapper) {
		ProxettaUtil.injectTargetIntoWrapper(target, wrapper, targetFieldName);
	}

public void injectTargetIntoWrapper ( final Object target , final Object wrapper ) { ProxettaUtil . injectTargetIntoWrapper ( target , wrapper , targetFieldName ) ; }