Javadoc and code tidying

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131167 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-09-20 12:03:52 +00:00
parent 1ad748d9aa
commit 3e9e81696a
1 changed files with 139 additions and 170 deletions

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/MapUtils.java,v 1.35 2003/09/20 11:26:32 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/MapUtils.java,v 1.36 2003/09/20 12:03:52 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -105,7 +105,7 @@ import org.apache.commons.collections.decorators.TypedSortedMap;
* </ul>
*
* @since Commons Collections 1.0
* @version $Revision: 1.35 $ $Date: 2003/09/20 11:26:32 $
* @version $Revision: 1.36 $ $Date: 2003/09/20 12:03:52 $
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @author <a href="mailto:nissim@nksystems.com">Nissim Karpenstein</a>
@ -143,34 +143,32 @@ public class MapUtils {
// Type safe getters
//-------------------------------------------------------------------------
/**
* Synonym for {@link Map#get(Object)}.
* Gets from a Map in a null-safe manner.
*
* @param map the map whose value to look up
* @param key the key whose value to look up in that map
* @return null if the map is null; or the result of
* <Code>map.get(key)</Code>
* @param map the map to use
* @param key the key to look up
* @return the value in the Map, <code>null</code> if null map input
*/
public static Object getObject( Map map, Object key ) {
if ( map != null ) {
return map.get( key );
public static Object getObject(final Map map, final Object key) {
if (map != null) {
return map.get(key);
}
return null;
}
/**
* Looks up the given key in the given map, converting the result into
* a string.
* Gets a String from a Map in a null-safe manner.
* <p>
* The String is obtained via <code>toString</code>.
*
* @param map the map whose value to look up
* @param key the key whose value to look up in that map
* @return null if the map is null; null if the value mapped by that
* key is null; or the <Code>toString()</Code>
* result of the value for that key
* @param map the map to use
* @param key the key to look up
* @return the value in the Map as a String, <code>null</code> if null map input
*/
public static String getString( Map map, Object key ) {
if ( map != null ) {
Object answer = map.get( key );
if ( answer != null ) {
public static String getString(final Map map, final Object key) {
if (map != null) {
Object answer = map.get(key);
if (answer != null) {
return answer.toString();
}
}
@ -178,39 +176,32 @@ public class MapUtils {
}
/**
* Looks up the given key in the given map, converting the result into
* a {@link Boolean}. If the map is null, this method returns null.
* If the value mapped by the given key is a
* {@link Boolean}, then it is returned as-is. Otherwise, if the value
* is a string, then if that string ignoring case equals "true", then
* a true {@link Boolean} is returned. Any other string value will
* result in a false {@link Boolean} being returned. OR, if the value
* is a {@link Number}, and that {@link Number} is 0, then a false
* {@link Boolean} is returned. Any other {@link Number} value results
* in a true {@link Boolean} being returned.<P>
* Gets a Boolean from a Map in a null-safe manner.
* <p>
* If the value is a <code>Boolean</code> it is returned directly.
* If the value is a <code>String</code> and it equals 'true' ignoring case
* then <code>true</code> is returned, otherwise <code>false</code>.
* If the value is a <code>Number</code> an integer zero value returns
* <code>false</code> and non-zero returns <code>true</code>.
* Otherwise, <code>null</code> is returned.
*
* Any value that is not a {@link Boolean}, {@link String} or
* {@link Number} results in null being returned.<P>
*
* @param map the map whose value to look up
* @param key the key whose value to look up in that map
* @return a {@link Boolean} or null
* @param map the map to use
* @param key the key to look up
* @return the value in the Map as a Boolean, <code>null</code> if null map input
*/
public static Boolean getBoolean( Map map, Object key ) {
if ( map != null ) {
Object answer = map.get( key );
if ( answer != null ) {
if ( answer instanceof Boolean ) {
public static Boolean getBoolean(final Map map, final Object key) {
if (map != null) {
Object answer = map.get(key);
if (answer != null) {
if (answer instanceof Boolean) {
return (Boolean) answer;
}
else
if ( answer instanceof String ) {
return new Boolean( (String) answer );
}
else
if ( answer instanceof Number ) {
} else if (answer instanceof String) {
return new Boolean((String) answer);
} else if (answer instanceof Number) {
Number n = (Number) answer;
return ( n.intValue() != 0 ) ? Boolean.TRUE : Boolean.FALSE;
return (n.intValue() != 0) ? Boolean.TRUE : Boolean.FALSE;
}
}
}
@ -218,36 +209,32 @@ public class MapUtils {
}
/**
* Looks up the given key in the given map, converting the result into
* a {@link Number}. If the map is null, this method returns null.
* Otherwise, if the key maps to a {@link Number}, then that number
* is returned as-is. Otherwise, if the key maps to a {@link String},
* that string is parsed into a number using the system default
* {@link NumberFormat}.<P>
* Gets a Number from a Map in a null-safe manner.
* <p>
* If the value is a <code>Number</code> it is returned directly.
* If the value is a <code>String</code> it is converted using
* {@link NumberFormat#parse(String)} on the system default formatter
* returning <code>null</code> if the conversion fails.
* Otherwise, <code>null</code> is returned.
*
* If the value is not a {@link Number} or a {@link String}, or if
* the value is a {@link String} that cannot be parsed into a
* {@link Number}, then null is returned.<P>
*
* @param map the map whose value to look up
* @param key the key whose value to look up in that map
* @return a {@link Number} or null
* @param map the map to use
* @param key the key to look up
* @return the value in the Map as a Number, <code>null</code> if null map input
*/
public static Number getNumber( Map map, Object key ) {
if ( map != null ) {
Object answer = map.get( key );
if ( answer != null ) {
if ( answer instanceof Number ) {
public static Number getNumber(final Map map, final Object key) {
if (map != null) {
Object answer = map.get(key);
if (answer != null) {
if (answer instanceof Number) {
return (Number) answer;
}
else
if ( answer instanceof String ) {
} else if (answer instanceof String) {
try {
String text = (String) answer;
return NumberFormat.getInstance().parse( text );
}
catch (ParseException e) {
logInfo( e );
return NumberFormat.getInstance().parse(text);
} catch (ParseException e) {
logInfo(e);
}
}
}
@ -256,151 +243,133 @@ public class MapUtils {
}
/**
* Looks up the given key in the given map, converting the result into
* a {@link Byte}. First, {@link #getNumber(Map,Object)} is invoked.
* If the result is null, then null is returned. Otherwise, the
* byte value of the resulting {@link Number} is returned.
* Gets a Byte from a Map in a null-safe manner.
* <p>
* The Byte is obtained from the results of {@link #getNumber(Map,Object)}.
*
* @param map the map whose value to look up
* @param key the key whose value to look up in that map
* @return a {@link Byte} or null
* @param map the map to use
* @param key the key to look up
* @return the value in the Map as a Byte, <code>null</code> if null map input
*/
public static Byte getByte( Map map, Object key ) {
Number answer = getNumber( map, key );
if ( answer == null ) {
public static Byte getByte(final Map map, final Object key) {
Number answer = getNumber(map, key);
if (answer == null) {
return null;
}
else
if ( answer instanceof Byte ) {
} else if (answer instanceof Byte) {
return (Byte) answer;
}
return new Byte( answer.byteValue() );
return new Byte(answer.byteValue());
}
/**
* Looks up the given key in the given map, converting the result into
* a {@link Short}. First, {@link #getNumber(Map,Object)} is invoked.
* If the result is null, then null is returned. Otherwise, the
* short value of the resulting {@link Number} is returned.
* Gets a Short from a Map in a null-safe manner.
* <p>
* The Short is obtained from the results of {@link #getNumber(Map,Object)}.
*
* @param map the map whose value to look up
* @param key the key whose value to look up in that map
* @return a {@link Short} or null
* @param map the map to use
* @param key the key to look up
* @return the value in the Map as a Short, <code>null</code> if null map input
*/
public static Short getShort( Map map, Object key ) {
Number answer = getNumber( map, key );
if ( answer == null ) {
public static Short getShort(final Map map, final Object key) {
Number answer = getNumber(map, key);
if (answer == null) {
return null;
}
else
if ( answer instanceof Short ) {
} else if (answer instanceof Short) {
return (Short) answer;
}
return new Short( answer.shortValue() );
return new Short(answer.shortValue());
}
/**
* Looks up the given key in the given map, converting the result into
* an {@link Integer}. First, {@link #getNumber(Map,Object)} is invoked.
* If the result is null, then null is returned. Otherwise, the
* integer value of the resulting {@link Number} is returned.
* Gets a Integer from a Map in a null-safe manner.
* <p>
* The Integer is obtained from the results of {@link #getNumber(Map,Object)}.
*
* @param map the map whose value to look up
* @param key the key whose value to look up in that map
* @return an {@link Integer} or null
* @param map the map to use
* @param key the key to look up
* @return the value in the Map as a Integer, <code>null</code> if null map input
*/
public static Integer getInteger( Map map, Object key ) {
Number answer = getNumber( map, key );
if ( answer == null ) {
public static Integer getInteger(final Map map, final Object key) {
Number answer = getNumber(map, key);
if (answer == null) {
return null;
}
else
if ( answer instanceof Integer ) {
} else if (answer instanceof Integer) {
return (Integer) answer;
}
return new Integer( answer.intValue() );
return new Integer(answer.intValue());
}
/**
* Looks up the given key in the given map, converting the result into
* a {@link Long}. First, {@link #getNumber(Map,Object)} is invoked.
* If the result is null, then null is returned. Otherwise, the
* long value of the resulting {@link Number} is returned.
* Gets a Long from a Map in a null-safe manner.
* <p>
* The Long is obtained from the results of {@link #getNumber(Map,Object)}.
*
* @param map the map whose value to look up
* @param key the key whose value to look up in that map
* @return a {@link Long} or null
* @param map the map to use
* @param key the key to look up
* @return the value in the Map as a Long, <code>null</code> if null map input
*/
public static Long getLong( Map map, Object key ) {
Number answer = getNumber( map, key );
if ( answer == null ) {
public static Long getLong(final Map map, final Object key) {
Number answer = getNumber(map, key);
if (answer == null) {
return null;
}
else
if ( answer instanceof Long ) {
} else if (answer instanceof Long) {
return (Long) answer;
}
return new Long( answer.longValue() );
return new Long(answer.longValue());
}
/**
* Looks up the given key in the given map, converting the result into
* a {@link Float}. First, {@link #getNumber(Map,Object)} is invoked.
* If the result is null, then null is returned. Otherwise, the
* float value of the resulting {@link Number} is returned.
* Gets a Float from a Map in a null-safe manner.
* <p>
* The Float is obtained from the results of {@link #getNumber(Map,Object)}.
*
* @param map the map whose value to look up
* @param key the key whose value to look up in that map
* @return a {@link Float} or null
* @param map the map to use
* @param key the key to look up
* @return the value in the Map as a Float, <code>null</code> if null map input
*/
public static Float getFloat( Map map, Object key ) {
Number answer = getNumber( map, key );
if ( answer == null ) {
public static Float getFloat(final Map map, final Object key) {
Number answer = getNumber(map, key);
if (answer == null) {
return null;
}
else
if ( answer instanceof Float ) {
} else if (answer instanceof Float) {
return (Float) answer;
}
return new Float( answer.floatValue() );
return new Float(answer.floatValue());
}
/**
* Looks up the given key in the given map, converting the result into
* a {@link Double}. First, {@link #getNumber(Map,Object)} is invoked.
* If the result is null, then null is returned. Otherwise, the
* double value of the resulting {@link Number} is returned.
* Gets a Double from a Map in a null-safe manner.
* <p>
* The Double is obtained from the results of {@link #getNumber(Map,Object)}.
*
* @param map the map whose value to look up
* @param key the key whose value to look up in that map
* @return a {@link Double} or null
* @param map the map to use
* @param key the key to look up
* @return the value in the Map as a Double, <code>null</code> if null map input
*/
public static Double getDouble( Map map, Object key ) {
Number answer = getNumber( map, key );
if ( answer == null ) {
public static Double getDouble(final Map map, final Object key) {
Number answer = getNumber(map, key);
if (answer == null) {
return null;
}
else
if ( answer instanceof Double ) {
} else if (answer instanceof Double) {
return (Double) answer;
}
return new Double( answer.doubleValue() );
return new Double(answer.doubleValue());
}
/**
* Looks up the given key in the given map, returning another map.
* If the given map is null or if the given key doesn't map to another
* map, then this method returns null. Otherwise the mapped map is
* returned.
* Gets a Map from a Map in a null-safe manner.
* <p>
* If the value returned from the specified map is not a Map then
* <code>null</code> is returned.
*
* @param map the map whose value to look up
* @param key the key whose value to look up in that map
* @return a {@link Map} or null
* @param map the map to use
* @param key the key to look up
* @return the value in the Map as a Map, <code>null</code> if null map input
*/
public static Map getMap( Map map, Object key ) {
if ( map != null ) {
Object answer = map.get( key );
if ( answer != null && answer instanceof Map ) {
public static Map getMap(final Map map, final Object key) {
if (map != null) {
Object answer = map.get(key);
if (answer != null && answer instanceof Map) {
return (Map) answer;
}
}