Fix brace positions

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1077921 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2011-03-04 12:54:18 +00:00
parent 30e369723d
commit 79cddd4ea5
13 changed files with 78 additions and 151 deletions

View File

@ -570,13 +570,11 @@ public static Boolean toBooleanObject(String str) {
case 1: {
char ch0 = str.charAt(0);
if ((ch0 == 'y' || ch0 == 'Y') ||
(ch0 == 't' || ch0 == 'T'))
{
(ch0 == 't' || ch0 == 'T')) {
return Boolean.TRUE;
}
if ((ch0 == 'n' || ch0 == 'N') ||
(ch0 == 'f' || ch0 == 'F'))
{
(ch0 == 'f' || ch0 == 'F')) {
return Boolean.FALSE;
}
break;
@ -585,13 +583,11 @@ public static Boolean toBooleanObject(String str) {
char ch0 = str.charAt(0);
char ch1 = str.charAt(1);
if ((ch0 == 'o' || ch0 == 'O') &&
(ch1 == 'n' || ch1 == 'N') )
{
(ch1 == 'n' || ch1 == 'N') ) {
return Boolean.TRUE;
}
if ((ch0 == 'n' || ch0 == 'N') &&
(ch1 == 'o' || ch1 == 'O') )
{
(ch1 == 'o' || ch1 == 'O') ) {
return Boolean.FALSE;
}
break;
@ -602,14 +598,12 @@ public static Boolean toBooleanObject(String str) {
char ch2 = str.charAt(2);
if ((ch0 == 'y' || ch0 == 'Y') &&
(ch1 == 'e' || ch1 == 'E') &&
(ch2 == 's' || ch2 == 'S') )
{
(ch2 == 's' || ch2 == 'S') ) {
return Boolean.TRUE;
}
if ((ch0 == 'o' || ch0 == 'O') &&
(ch1 == 'f' || ch1 == 'F') &&
(ch2 == 'f' || ch2 == 'F') )
{
(ch2 == 'f' || ch2 == 'F') ) {
return Boolean.FALSE;
}
break;
@ -622,8 +616,7 @@ public static Boolean toBooleanObject(String str) {
if ((ch0 == 't' || ch0 == 'T') &&
(ch1 == 'r' || ch1 == 'R') &&
(ch2 == 'u' || ch2 == 'U') &&
(ch3 == 'e' || ch3 == 'E') )
{
(ch3 == 'e' || ch3 == 'E') ) {
return Boolean.TRUE;
}
break;
@ -638,8 +631,7 @@ public static Boolean toBooleanObject(String str) {
(ch1 == 'a' || ch1 == 'A') &&
(ch2 == 'l' || ch2 == 'L') &&
(ch3 == 's' || ch3 == 'S') &&
(ch4 == 'e' || ch4 == 'E') )
{
(ch4 == 'e' || ch4 == 'E') ) {
return Boolean.FALSE;
}
break;

View File

@ -250,9 +250,8 @@ public static String random(int count, int start, int end, boolean letters, bool
ch = chars[random.nextInt(gap) + start];
}
if ((letters && Character.isLetter(ch))
|| (numbers && Character.isDigit(ch))
|| (!letters && !numbers))
{
|| (numbers && Character.isDigit(ch))
|| (!letters && !numbers)) {
if(ch >= 56320 && ch <= 57343) {
if(count == 0) {
count++;

View File

@ -2725,9 +2725,8 @@ public static String[] splitByWholeSeparatorPreserveAllTokens(String str, String
* @return an array of parsed Strings, <code>null</code> if null String input
* @since 2.4
*/
private static String[] splitByWholeSeparatorWorker(String str, String separator, int max,
boolean preserveAllTokens)
{
private static String[] splitByWholeSeparatorWorker(
String str, String separator, int max, boolean preserveAllTokens) {
if (str == null) {
return null;
}
@ -4035,16 +4034,14 @@ public static String replaceEachRepeatedly(String text, String[] searchList, Str
* and/or size 0)
* @since 2.4
*/
private static String replaceEach(String text, String[] searchList, String[] replacementList,
boolean repeat, int timeToLive)
{
private static String replaceEach(
String text, String[] searchList, String[] replacementList, boolean repeat, int timeToLive) {
// mchyzer Performance note: This creates very few new objects (one major goal)
// let me know if there are performance requests, we can create a harness to measure
if (text == null || text.length() == 0 || searchList == null ||
searchList.length == 0 || replacementList == null || replacementList.length == 0)
{
searchList.length == 0 || replacementList == null || replacementList.length == 0) {
return text;
}
@ -4076,8 +4073,7 @@ private static String replaceEach(String text, String[] searchList, String[] rep
// NOTE: logic duplicated below START
for (int i = 0; i < searchLength; i++) {
if (noMoreMatchesForReplIndex[i] || searchList[i] == null ||
searchList[i].length() == 0 || replacementList[i] == null)
{
searchList[i].length() == 0 || replacementList[i] == null) {
continue;
}
tempIndex = text.indexOf(searchList[i]);
@ -4135,8 +4131,7 @@ private static String replaceEach(String text, String[] searchList, String[] rep
// NOTE: logic mostly duplicated above START
for (int i = 0; i < searchLength; i++) {
if (noMoreMatchesForReplIndex[i] || searchList[i] == null ||
searchList[i].length() == 0 || replacementList[i] == null)
{
searchList[i].length() == 0 || replacementList[i] == null) {
continue;
}
tempIndex = text.indexOf(searchList[i], start);

View File

@ -802,10 +802,8 @@ public static void validState(boolean expression, String message, Object... valu
* @throws IllegalArgumentException if the character sequence does not match the pattern
* @see #matchesPattern(CharSequence, String, String, Object...)
*/
public static void matchesPattern(CharSequence input, String pattern)
{
if (Pattern.matches(pattern, input) == false)
{
public static void matchesPattern(CharSequence input, String pattern) {
if (Pattern.matches(pattern, input) == false) {
throw new IllegalArgumentException(String.format(DEFAULT_MATCHES_PATTERN_EX, input, pattern));
}
}
@ -825,10 +823,8 @@ public static void matchesPattern(CharSequence input, String pattern)
* @throws IllegalArgumentException if the character sequence does not match the pattern
* @see #matchesPattern(CharSequence, String)
*/
public static void matchesPattern(CharSequence input, String pattern, String message, Object... values)
{
if (Pattern.matches(pattern, input) == false)
{
public static void matchesPattern(CharSequence input, String pattern, String message, Object... values) {
if (Pattern.matches(pattern, input) == false) {
throw new IllegalArgumentException(String.format(message, values));
}
}
@ -845,10 +841,8 @@ public static void matchesPattern(CharSequence input, String pattern, String mes
* @throws IllegalArgumentException if the value falls out of the boundaries
* @see #inclusiveBetween(Object, Object, Comparable, String, Object...)
*/
public static <T> void inclusiveBetween(T start, T end, Comparable<T> value)
{
if (value.compareTo(start) < 0 || value.compareTo(end) > 0)
{
public static <T> void inclusiveBetween(T start, T end, Comparable<T> value) {
if (value.compareTo(start) < 0 || value.compareTo(end) > 0) {
throw new IllegalArgumentException(String.format(DEFAULT_INCLUSIVE_BETWEEN_EX_MESSAGE, value, start, end));
}
}
@ -868,10 +862,8 @@ public static <T> void inclusiveBetween(T start, T end, Comparable<T> value)
* @throws IllegalArgumentException if the value falls out of the boundaries
* @see #inclusiveBetween(Object, Object, Comparable)
*/
public static <T> void inclusiveBetween(T start, T end, Comparable<T> value, String message, Object... values)
{
if (value.compareTo(start) < 0 || value.compareTo(end) > 0)
{
public static <T> void inclusiveBetween(T start, T end, Comparable<T> value, String message, Object... values) {
if (value.compareTo(start) < 0 || value.compareTo(end) > 0) {
throw new IllegalArgumentException(String.format(message, values));
}
}
@ -888,10 +880,8 @@ public static <T> void inclusiveBetween(T start, T end, Comparable<T> value, Str
* @throws IllegalArgumentException if the value falls out of the boundaries
* @see #exclusiveBetween(Object, Object, Comparable, String, Object...)
*/
public static <T> void exclusiveBetween(T start, T end, Comparable<T> value)
{
if (value.compareTo(start) <= 0 || value.compareTo(end) >= 0)
{
public static <T> void exclusiveBetween(T start, T end, Comparable<T> value) {
if (value.compareTo(start) <= 0 || value.compareTo(end) >= 0) {
throw new IllegalArgumentException(String.format(DEFAULT_EXCLUSIVE_BETWEEN_EX_MESSAGE, value, start, end));
}
}
@ -911,10 +901,8 @@ public static <T> void exclusiveBetween(T start, T end, Comparable<T> value)
* @throws IllegalArgumentException if the value falls out of the boundaries
* @see #exclusiveBetween(Object, Object, Comparable)
*/
public static <T> void exclusiveBetween(T start, T end, Comparable<T> value, String message, Object... values)
{
if (value.compareTo(start) <= 0 || value.compareTo(end) >= 0)
{
public static <T> void exclusiveBetween(T start, T end, Comparable<T> value, String message, Object... values) {
if (value.compareTo(start) <= 0 || value.compareTo(end) >= 0) {
throw new IllegalArgumentException(String.format(message, values));
}
}
@ -934,10 +922,8 @@ public static <T> void exclusiveBetween(T start, T end, Comparable<T> value, Str
* @throws IllegalArgumentException if argument is not of specified class
* @see #isInstanceOf(Class, Object, String, Object...)
*/
public static void isInstanceOf(Class<?> type, Object o)
{
if (type.isInstance(o) == false)
{
public static void isInstanceOf(Class<?> type, Object o) {
if (type.isInstance(o) == false) {
throw new IllegalArgumentException(String.format(DEFAULT_IS_INSTANCE_OF_EX_MESSAGE, type.getName()));
}
}
@ -956,10 +942,8 @@ public static void isInstanceOf(Class<?> type, Object o)
* @throws IllegalArgumentException if argument is not of specified class
* @see #isInstanceOf(Class, Object)
*/
public static void isInstanceOf(Class<?> type, Object o, String message, Object... values)
{
if (type.isInstance(o) == false)
{
public static void isInstanceOf(Class<?> type, Object o, String message, Object... values) {
if (type.isInstance(o) == false) {
throw new IllegalArgumentException(String.format(message, values));
}
}
@ -979,10 +963,8 @@ public static void isInstanceOf(Class<?> type, Object o, String message, Object.
* @throws IllegalArgumentException if argument can not be converted to the specified class
* @see #isAssignableFrom(Class, Class, String, Object...)
*/
public static void isAssignableFrom(Class<?> superType, Class<?> type)
{
if (superType.isAssignableFrom(type) == false)
{
public static void isAssignableFrom(Class<?> superType, Class<?> type) {
if (superType.isAssignableFrom(type) == false) {
throw new IllegalArgumentException(String.format(DEFAULT_IS_ASSIGNABLE_EX_MESSAGE, superType.getName()));
}
}
@ -1004,10 +986,8 @@ public static void isAssignableFrom(Class<?> superType, Class<?> type)
* @throws IllegalArgumentException if argument can not be converted to the specified class
* @see #isAssignableFrom(Class, Class)
*/
public static void isAssignableFrom(Class<?> superType, Class<?> type, String message, Object... values)
{
if (superType.isAssignableFrom(type) == false)
{
public static void isAssignableFrom(Class<?> superType, Class<?> type, String message, Object... values) {
if (superType.isAssignableFrom(type) == false) {
throw new IllegalArgumentException(String.format(message, values));
}
}

View File

@ -268,9 +268,8 @@ public static int reflectionCompare(Object lhs, Object rhs, String[] excludeFiel
* with <code>lhs</code>
* @since 2.0
*/
public static int reflectionCompare(Object lhs, Object rhs, boolean compareTransients,
Class<?> reflectUpToClass)
{
public static int reflectionCompare(
Object lhs, Object rhs, boolean compareTransients, Class<?> reflectUpToClass) {
return reflectionCompare(lhs, rhs, compareTransients, reflectUpToClass, null);
}

View File

@ -63,8 +63,8 @@
* @since 3.0
* @version $Id$
*/
public class EventListenerSupport<L> implements Serializable
{
public class EventListenerSupport<L> implements Serializable {
/** Serialization version */
private static final long serialVersionUID = 3593265990380473632L;
@ -101,8 +101,7 @@ public class EventListenerSupport<L> implements Serializable
* @throws IllegalArgumentException if <code>listenerInterface</code> is
* not an interface.
*/
public static <T> EventListenerSupport<T> create(Class<T> listenerInterface)
{
public static <T> EventListenerSupport<T> create(Class<T> listenerInterface) {
return new EventListenerSupport<T>(listenerInterface);
}
@ -118,8 +117,7 @@ public static <T> EventListenerSupport<T> create(Class<T> listenerInterface)
* @throws IllegalArgumentException if <code>listenerInterface</code> is
* not an interface.
*/
public EventListenerSupport(Class<L> listenerInterface)
{
public EventListenerSupport(Class<L> listenerInterface) {
this(listenerInterface, Thread.currentThread().getContextClassLoader());
}
@ -136,8 +134,7 @@ public EventListenerSupport(Class<L> listenerInterface)
* @throws IllegalArgumentException if <code>listenerInterface</code> is
* not an interface.
*/
public EventListenerSupport(Class<L> listenerInterface, ClassLoader classLoader)
{
public EventListenerSupport(Class<L> listenerInterface, ClassLoader classLoader) {
this();
Validate.notNull(listenerInterface, "Listener interface cannot be null.");
Validate.notNull(classLoader, "ClassLoader cannot be null.");
@ -161,8 +158,7 @@ private EventListenerSupport() {
* @return a proxy object which can be used to call listener methods on all
* of the registered event listeners
*/
public L fire()
{
public L fire() {
return proxy;
}
@ -178,8 +174,7 @@ public L fire()
* @throws NullPointerException if <code>listener</code> is
* <code>null</code>.
*/
public void addListener(L listener)
{
public void addListener(L listener) {
Validate.notNull(listener, "Listener object cannot be null.");
listeners.add(listener);
}
@ -189,8 +184,7 @@ public void addListener(L listener)
*
* @return the number of registered listeners.
*/
int getListenerCount()
{
int getListenerCount() {
return listeners.size();
}
@ -202,8 +196,7 @@ int getListenerCount()
* @throws NullPointerException if <code>listener</code> is
* <code>null</code>.
*/
public void removeListener(L listener)
{
public void removeListener(L listener) {
Validate.notNull(listener, "Listener object cannot be null.");
listeners.remove(listener);
}
@ -296,8 +289,7 @@ protected InvocationHandler createInvocationHandler() {
/**
* An invocation handler used to dispatch the event(s) to all the listeners.
*/
protected class ProxyInvocationHandler implements InvocationHandler
{
protected class ProxyInvocationHandler implements InvocationHandler {
/** Serialization version */
private static final long serialVersionUID = 1L;
@ -311,11 +303,8 @@ protected class ProxyInvocationHandler implements InvocationHandler
* listeners.
* @param args event arguments to propagate to the listeners.
*/
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable
{
for (L listener : listeners)
{
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
for (L listener : listeners) {
method.invoke(listener, args);
}
return null;

View File

@ -33,8 +33,8 @@
* @since 3.0
* @version $Id$
*/
public class EventUtils
{
public class EventUtils {
/**
* Adds an event listener to the specified source. This looks for an "add" method corresponding to the event
* type (addActionListener, for example).
@ -45,22 +45,14 @@ public class EventUtils
*
* @throws IllegalArgumentException if the object doesn't support the listener type
*/
public static <L> void addEventListener(Object eventSource, Class<L> listenerType, L listener)
{
try
{
public static <L> void addEventListener(Object eventSource, Class<L> listenerType, L listener) {
try {
MethodUtils.invokeMethod(eventSource, "add" + listenerType.getSimpleName(), listener);
}
catch (NoSuchMethodException e)
{
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException("Class " + eventSource.getClass().getName() + " does not have a public add" + listenerType.getSimpleName() + " method which takes a parameter of type " + listenerType.getName() + ".");
}
catch (IllegalAccessException e)
{
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Class " + eventSource.getClass().getName() + " does not have an accessible add" + listenerType.getSimpleName () + " method which takes a parameter of type " + listenerType.getName() + ".");
}
catch (InvocationTargetException e)
{
} catch (InvocationTargetException e) {
throw new RuntimeException("Unable to add listener.", e.getCause());
}
}
@ -76,43 +68,34 @@ public static <L> void addEventListener(Object eventSource, Class<L> listenerTyp
* @param eventTypes the event types (method names) from the listener interface (if none specified, all will be
* supported)
*/
public static <L> void bindEventsToMethod(Object target, String methodName, Object eventSource, Class<L> listenerType, String... eventTypes)
{
public static <L> void bindEventsToMethod(Object target, String methodName, Object eventSource, Class<L> listenerType, String... eventTypes) {
final L listener = listenerType.cast(Proxy.newProxyInstance(target.getClass().getClassLoader(), new Class[] { listenerType }, new EventBindingInvocationHandler(target, methodName, eventTypes)));
addEventListener(eventSource, listenerType, listener);
}
private static class EventBindingInvocationHandler implements InvocationHandler
{
private static class EventBindingInvocationHandler implements InvocationHandler {
private final Object target;
private final String methodName;
private final Set<String> eventTypes;
public EventBindingInvocationHandler(final Object target, final String methodName, String[] eventTypes)
{
public EventBindingInvocationHandler(final Object target, final String methodName, String[] eventTypes) {
this.target = target;
this.methodName = methodName;
this.eventTypes = new HashSet<String>(Arrays.asList(eventTypes));
}
public Object invoke(final Object proxy, final Method method, final Object[] parameters) throws Throwable
{
if ( eventTypes.isEmpty() || eventTypes.contains(method.getName()))
{
if (hasMatchingParametersMethod(method))
{
public Object invoke(final Object proxy, final Method method, final Object[] parameters) throws Throwable {
if ( eventTypes.isEmpty() || eventTypes.contains(method.getName())) {
if (hasMatchingParametersMethod(method)) {
return MethodUtils.invokeMethod(target, methodName, parameters);
}
else
{
} else {
return MethodUtils.invokeMethod(target, methodName);
}
}
return null;
}
private boolean hasMatchingParametersMethod(final Method method)
{
private boolean hasMatchingParametersMethod(final Method method) {
return MethodUtils.getAccessibleMethod(target.getClass(), methodName, method.getParameterTypes()) != null;
}
}

View File

@ -58,8 +58,7 @@ public ExceptionContext addValue(String label, Object value) {
while (contextValueMap.containsKey(key)) {
Object information = contextValueMap.get(key);
if ((value == null && information == null)
|| (value != null && value.equals(information)))
{
|| (value != null && value.equals(information))) {
return this;
}
key = label + "[" + ++i +"]";
@ -132,12 +131,10 @@ public String getFormattedExceptionMessage(String baseMessage){
value = this.contextValueMap.get(label);
if (value == null) {
buffer.append("null");
}
else {
} else {
try {
valueStr = value.toString();
}
catch (Exception e) {
} catch (Exception e) {
valueStr = "Exception thrown on toString(): " + ExceptionUtils.getStackTrace(e);
}
buffer.append(valueStr);

View File

@ -98,8 +98,7 @@ public boolean equals(Object obj) {
if (this.getClass() == obj.getClass()) {
MutableObject<?> that = (MutableObject<?>) obj;
return this.value.equals(that.value);
}
else {
} else {
return false;
}
}

View File

@ -1174,8 +1174,7 @@ public StrBuilder appendSeparator(char separator) {
public StrBuilder appendSeparator(char standard, char defaultIfEmpty) {
if (size() > 0) {
append(standard);
}
else {
} else {
append(defaultIfEmpty);
}
return this;

View File

@ -174,15 +174,13 @@ public static <V> String replace(Object source, Map<String, V> valueMap, String
* @param valueProperties the properties with values, may be null
* @return the result of the replace operation
*/
public static String replace(Object source, Properties valueProperties)
{
public static String replace(Object source, Properties valueProperties) {
if (valueProperties == null) {
return source.toString();
}
Map<String,String> valueMap = new HashMap<String,String>();
Enumeration<?> propNames = valueProperties.propertyNames();
while (propNames.hasMoreElements())
{
while (propNames.hasMoreElements()) {
String propName = (String)propNames.nextElement();
String propValue = valueProperties.getProperty(propName);
valueMap.put(propName, propValue);

View File

@ -726,8 +726,7 @@ private int readNextToken(char[] chars, int start, int len, StrBuilder workArea,
* then the length of string
*/
private int readWithQuotes(char[] chars, int start, int len, StrBuilder workArea,
List<String> tokens, int quoteStart, int quoteLen)
{
List<String> tokens, int quoteStart, int quoteLen) {
// Loop until we've found the end of the quoted
// string or the end of the input
workArea.clear();

View File

@ -348,12 +348,10 @@ public static String formatPeriod(long startMillis, long endMillis, String forma
days += start.getActualMaximum(Calendar.DAY_OF_YEAR) - start.get(Calendar.DAY_OF_YEAR);
// Not sure I grok why this is needed, but the brutal tests show it is
if(start instanceof GregorianCalendar) {
if( (start.get(Calendar.MONTH) == Calendar.FEBRUARY) &&
(start.get(Calendar.DAY_OF_MONTH) == 29 ) )
{
days += 1;
}
if (start instanceof GregorianCalendar &&
start.get(Calendar.MONTH) == Calendar.FEBRUARY &&
start.get(Calendar.DAY_OF_MONTH) == 29) {
days += 1;
}
start.add(Calendar.YEAR, 1);