You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2005/01/14 18:12:44 UTC
DO NOT REPLY [Bug 33101] New: -
add generic length function to ArrayUtils, for object.getClass().isArray()
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=33101>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=33101
Summary: add generic length function to ArrayUtils, for
object.getClass().isArray()
Product: Commons
Version: unspecified
Platform: PC
OS/Version: Windows XP
Status: NEW
Severity: enhancement
Priority: P2
Component: Lang
AssignedTo: commons-dev@jakarta.apache.org
ReportedBy: vive_lafrique@yahoo.com
This method will calculate the length of any Array object, on the condition that
object.getClass().isArray() is true:
public static int length(Object array) {
if (array == null)
throw new NullPointerException("May not pass in null");
if (!array.getClass().isArray())
throw new IllegalArgumentException("You may only get the generic length of
an array if you pass in an array");
if (array instanceof int[])
return ((int[])array).length;
else if (array instanceof short[])
return ((short[])array).length;
else if (array instanceof byte[])
return ((byte[])array).length;
else if (array instanceof boolean[])
return ((boolean[])array).length;
else if (array instanceof long[])
return ((long[])array).length;
else if (array instanceof char[])
return ((char[])array).length;
else if (array instanceof double[])
return ((double[])array).length;
else if (array instanceof float[])
return ((float[])array).length;
else if (array instanceof Object[])
return ((Object[])array).length;
else //Not reachable strictly.
throw new IllegalArgumentException("Unknown type");
}
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org