Formatting changes (inserting missing {}s) in Entities, NestableDelagate, NumberUtils, MethodUtils.

Added javadoc examples for string conversion methods in NumberUtils.
Patch submitted by Fredrik Westermarck
Reviewed by Phil Steitz


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137667 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Phil Steitz 2003-09-13 03:11:30 +00:00
parent fd3bd5bdd2
commit c94b5776c1
4 changed files with 82 additions and 20 deletions

View File

@ -69,7 +69,7 @@ import java.util.TreeMap;
* @author <a href="mailto:alex@purpletech.com">Alexander Day Chaffee</a>
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
* @since 2.0
* @version $Id: Entities.java,v 1.14 2003/09/07 14:32:34 psteitz Exp $
* @version $Id: Entities.java,v 1.15 2003/09/13 03:11:29 psteitz Exp $
*/
class Entities {
@ -431,8 +431,9 @@ class Entities {
public int value(String name) {
Object value = mapNameToValue.get(name);
if (value == null)
if (value == null) {
return -1;
}
return ((Integer) value).intValue();
}
}
@ -453,8 +454,9 @@ class Entities {
public int value(String name) {
Object value = mapNameToValue.get(name);
if (value == null)
if (value == null) {
return -1;
}
return ((Integer) value).intValue();
}
}
@ -572,12 +574,13 @@ class Entities {
int mid = (low + high) >> 1;
int midVal = values[mid];
if (midVal < key)
if (midVal < key) {
low = mid + 1;
else if (midVal > key)
} else if (midVal > key) {
high = mid - 1;
else
} else {
return mid; // key found
}
}
return -(low + 1); // key not found.
}
@ -585,7 +588,9 @@ class Entities {
public void add(String name, int value) {
ensureCapacity(size + 1);
int insertAt = binarySearch(value);
if (insertAt > 0) return; // note: this means you can't insert the same value twice
if (insertAt > 0) {
return; // note: this means you can't insert the same value twice
}
insertAt = -(insertAt + 1); // binarySearch returns it negative and off-by-one
System.arraycopy(values, insertAt, values, insertAt + 1, size - insertAt);
values[insertAt] = value;
@ -596,7 +601,9 @@ class Entities {
public String name(int value) {
int index = binarySearch(value);
if (index < 0) return null;
if (index < 0) {
return null;
}
return names[index];
}
}

View File

@ -79,7 +79,7 @@ import java.util.List;
* @author Sean C. Sullivan
* @author Stephen Colebourne
* @since 1.0
* @version $Id: NestableDelegate.java,v 1.21 2003/09/07 14:32:35 psteitz Exp $
* @version $Id: NestableDelegate.java,v 1.22 2003/09/13 03:11:30 psteitz Exp $
*/
public class NestableDelegate implements Serializable {
@ -344,7 +344,9 @@ public class NestableDelegate implements Serializable {
}
// Remove the repeated lines in the stack
if (trimStackFrames) trimStackFrames(stacks);
if (trimStackFrames) {
trimStackFrames(stacks);
}
synchronized (out) {
for (Iterator iter=stacks.iterator(); iter.hasNext();) {
@ -352,8 +354,9 @@ public class NestableDelegate implements Serializable {
for (int i=0, len=st.length; i < len; i++) {
out.println(st[i]);
}
if (iter.hasNext())
if (iter.hasNext()) {
out.print(separatorLine);
}
}
}
}

View File

@ -71,7 +71,7 @@ import org.apache.commons.lang.StringUtils;
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
* @author <a href="mailto:fredrik@westermarck.com">Fredrik Westermarck</a>
* @since 2.0
* @version $Id: NumberUtils.java,v 1.13 2003/09/07 14:32:35 psteitz Exp $
* @version $Id: NumberUtils.java,v 1.14 2003/09/13 03:11:30 psteitz Exp $
*/
public class NumberUtils {
@ -129,6 +129,12 @@ public class NumberUtils {
*
* <p>If the string is <code>null</code>, <code>zero</code> is returned.</p>
*
* <pre>
* NumberUtils.stringToInt(null) = 0
* NumberUtils.stringToInt("") = 0
* NumberUtils.stringToInt("1") = 1
* </pre>
*
* @param str the string to convert, may be null
* @return the int represented by the string, or <code>zero</code> if
* conversion fails
@ -143,6 +149,12 @@ public class NumberUtils {
*
* <p>If the string is <code>null</code>, the default value is returned.</p>
*
* <pre>
* NumberUtils.stringToInt(null, 1) = 1
* NumberUtils.stringToInt("", 1) = 1
* NumberUtils.stringToInt("1", 0) = 1
* </pre>
*
* @param str the string to convert, may be null
* @param defaultValue the default value
* @return the int represented by the string, or the default if conversion fails
@ -161,6 +173,12 @@ public class NumberUtils {
*
* <p>If the string is <code>null</code>, <code>zero</code> is returned.</p>
*
* <pre>
* NumberUtils.stringToLong(null) = 0L
* NumberUtils.stringToLong("") = 0L
* NumberUtils.stringToLong("1") = 1L
* </pre>
*
* @param str the string to convert, may be null
* @return the long represented by the string, or <code>0</code> if
* conversion fails
@ -176,6 +194,12 @@ public class NumberUtils {
*
* <p>If the string is <code>null</code>, the default value is returned.</p>
*
* <pre>
* NumberUtils.stringToLong(null, 1L) = 1L
* NumberUtils.stringToLong("", 1L) = 1L
* NumberUtils.stringToLong("1", 0L) = 1L
* </pre>
*
* @param str the string to convert, may be null
* @param defaultValue the default value
* @return the long represented by the string, or the default if conversion fails
@ -196,6 +220,12 @@ public class NumberUtils {
* <p>If the string <code>str</code> is <code>null</code>,
* <code>0.0f</code> is returned.</p>
*
* <pre>
* NumberUtils.stringToFloat(null) = 0.0f
* NumberUtils.stringToFloat("") = 0.0f
* NumberUtils.stringToFloat("1.5") = 1.5f
* </pre>
*
* @param str the string to convert, may be <code>null</code>
* @return the float represented by the string, or <code>0.0f</code>
* if conversion fails
@ -212,6 +242,12 @@ public class NumberUtils {
* <p>If the string <code>str</code> is <code>null</code>, the default
* value is returned.</p>
*
* <pre>
* NumberUtils.stringToFloat(null, 1.1f) = 1.0f
* NumberUtils.stringToFloat("", 1.1f) = 1.1f
* NumberUtils.stringToFloat("1.5", 0.0f) = 1.5f
* </pre>
*
* @param str the string to convert, may be <code>null</code>
* @param defaultValue the default value
* @return the float represented by the string, or defaultValue
@ -219,7 +255,7 @@ public class NumberUtils {
* @since 2.1
*/
public static float stringToFloat(String str, float defaultValue) {
if(str==null) {
if (str == null) {
return defaultValue;
}
try {
@ -236,6 +272,12 @@ public class NumberUtils {
* <p>If the string <code>str</code> is <code>null</code>,
* <code>0.0d</code> is returned.</p>
*
* <pre>
* NumberUtils.stringToDouble(null) = 0.0d
* NumberUtils.stringToDouble("") = 0.0d
* NumberUtils.stringToDouble("1.5") = 1.5d
* </pre>
*
* @param str the string to convert, may be <code>null</code>
* @return the double represented by the string, or <code>0.0d</code>
* if conversion fails
@ -252,6 +294,12 @@ public class NumberUtils {
* <p>If the string <code>str</code> is <code>null</code>, the default
* value is returned.</p>
*
* <pre>
* NumberUtils.stringToDouble(null, 1.1d) = 1.1d
* NumberUtils.stringToDouble("", 1.1d) = 1.1d
* NumberUtils.stringToDouble("1.5", 0.0d) = 1.5d
* </pre>
*
* @param str the string to convert, may be <code>null</code>
* @param defaultValue the default value
* @return the double represented by the string, or defaultValue
@ -259,7 +307,7 @@ public class NumberUtils {
* @since 2.1
*/
public static double stringToDouble(String str, double defaultValue) {
if(str==null) {
if (str == null) {
return defaultValue;
}
try {

View File

@ -76,7 +76,7 @@ import org.apache.commons.lang.ArrayUtils;
* @author Jan Sorensen
* @author Robert Burrell Donkin
* @author Gary Gregory
* @version $Id: MethodUtils.java,v 1.16 2003/09/07 14:32:35 psteitz Exp $
* @version $Id: MethodUtils.java,v 1.17 2003/09/13 03:11:30 psteitz Exp $
*/
public class MethodUtils {
@ -400,10 +400,11 @@ public class MethodUtils {
object.getClass(),
methodName,
parameterTypes);
if (method == null)
if (method == null) {
throw new ReflectionException("No such accessible method: " +
methodName + "() on object: " + object.getClass().getName());
}
try {
return method.invoke(object, args);
@ -491,8 +492,9 @@ public class MethodUtils {
for (int i = 0; i < interfaces.length; i++) {
// Is this interface public?
if (!Modifier.isPublic(interfaces[i].getModifiers()))
if (!Modifier.isPublic(interfaces[i].getModifiers())) {
continue;
}
// Does the method exist on this interface?
try {
@ -501,16 +503,18 @@ public class MethodUtils {
} catch (NoSuchMethodException e) {
// empty
}
if (method != null)
if (method != null) {
break;
}
// Recursively check our parent interfaces
method =
getAccessibleMethodFromInterfaceNest(interfaces[i],
methodName,
parameterTypes);
if (method != null)
if (method != null) {
break;
}
}