Commit cea5ca6a by Michael Koch Committed by Michael Koch

ArrayHelper.java, [...]: Reformatted to match classpath's versions.

2003-06-17  Michael Koch  <konqueror@gmx.de>

	* gnu/java/lang/ArrayHelper.java,
	gnu/java/lang/ClassHelper.java:
	Reformatted to match classpath's versions.

From-SVN: r68078
parent c1e5104d
2003-06-17 Michael Koch <konqueror@gmx.de>
* gnu/java/lang/ArrayHelper.java,
gnu/java/lang/ClassHelper.java:
Reformatted to match classpath's versions.
2003-06-14 Michael Koch <konqueror@gmx.de> 2003-06-14 Michael Koch <konqueror@gmx.de>
* gnu/java/nio/FileChannelImpl.java * gnu/java/nio/FileChannelImpl.java
......
/* gnu.java.lang.ArrayHelper /* ArrayHelper.java -- Helper methods for handling array operations
Copyright (C) 1998 Free Software Foundation, Inc. Copyright (C) 1998, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -39,20 +39,37 @@ exception statement from your version. */ ...@@ -39,20 +39,37 @@ exception statement from your version. */
package gnu.java.lang; package gnu.java.lang;
/** /**
** ArrayHelper helps you do things with arrays. * ArrayHelper helps you do things with arrays.
** *
** @author John Keiser * @author John Keiser
** @version 1.1.0, 29 Jul 1998 */
**/ public class ArrayHelper
{
public class ArrayHelper { /**
public static boolean contains(Object[] array, Object searchFor) { * Counterpart to java.util.Collection.contains.
return indexOf(array,searchFor) != -1; *
* @param array the array to search
* @param searchFor the object to locate
* @return true if some array element <code>equals(searchFor)</code>
*/
public static boolean contains(Object[] array, Object searchFor)
{
return indexOf(array, searchFor) != -1;
} }
public static int indexOf(Object[] array, Object searchFor) { /**
for(int i=0;i<array.length;i++) { * Counterpart to java.util.Collection.indexOf.
if(array[i].equals(searchFor)) { *
* @param array the array to search
* @param searchFor the object to locate
* @return the index of the first equal object, or -1
*/
public static int indexOf(Object[] array, Object searchFor)
{
for (int i = 0; i < array.length; i++)
{
if(array[i].equals(searchFor))
{
return i; return i;
} }
} }
......
/* gnu.java.lang.ClassHelper /* ClassHelper.java -- Utility methods to augment java.lang.Class
Copyright (C) 1998 Free Software Foundation, Inc. Copyright (C) 1998, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -42,201 +42,143 @@ import java.util.*; ...@@ -42,201 +42,143 @@ import java.util.*;
import java.lang.reflect.*; import java.lang.reflect.*;
/** /**
** ClassHelper has various methods that ought to have been * ClassHelper has various methods that ought to have been in Class.
** in class. *
** * @author John Keiser
** @author John Keiser * @author Eric Blake <ebb9@email.byu.edu>
** @version 1.1.0, 29 Jul 1998 */
**/ public class ClassHelper
{
public class ClassHelper { /**
/** Strip the package part from the class name. * Strip the package part from the class name.
** @param clazz the class to get the truncated name from *
** @return the truncated class name. * @param clazz the class to get the truncated name from
**/ * @return the truncated class name
public static String getTruncatedClassName(Class clazz) { */
public static String getTruncatedClassName(Class clazz)
{
return getTruncatedName(clazz.getName()); return getTruncatedName(clazz.getName());
} }
/** Strip the package part from the class name, or the
** class part from the method or field name. /**
** @param name the name to truncate. * Strip the package part from the class name, or the class part from
** @return the truncated name. * the method or field name.
**/ *
public static String getTruncatedName(String name) { * @param name the name to truncate
* @return the truncated name
*/
public static String getTruncatedName(String name)
{
int lastInd = name.lastIndexOf('.'); int lastInd = name.lastIndexOf('.');
if(lastInd == -1) { if (lastInd == -1)
return name; return name;
} else { return name.substring(lastInd + 1);
return name.substring(lastInd+1);
}
} }
/** Strip the last portion of the name (after the last /**
** dot). * Strip the last portion of the name (after the last dot).
** @param name the name to get package of. *
** @return the package name. "" if no package. * @param name the name to get package of
**/ * @return the package name, or "" if no package
public static String getPackagePortion(String name) { */
public static String getPackagePortion(String name)
{
int lastInd = name.lastIndexOf('.'); int lastInd = name.lastIndexOf('.');
if(lastInd == -1) { if (lastInd == -1)
return ""; return "";
} else { return name.substring(0, lastInd);
return name.substring(0,lastInd); }
}
} /** Cache of methods found in getAllMethods(). */
private static Map allMethods = new HashMap();
static Hashtable allMethods = new Hashtable();
static Hashtable allMethodsAtDeclaration = new Hashtable(); /**
* Get all the methods, public, private and otherwise, from the class,
/** Get all the methods, public, private and * getting them from the most recent class to find them. This may not
** otherwise, from the class, getting them * be quite the correct approach, as this includes methods that are not
** from the most recent class to find them. * inherited or accessible from clazz, so beware.
**/ *
public static Method[] getAllMethods(Class clazz) { * @param clazz the class to start at
Method[] retval = (Method[])allMethods.get(clazz); * @return all methods declared or inherited in clazz
if(retval == null) { */
Method[] superMethods; public static Method[] getAllMethods(Class clazz)
if(clazz.getSuperclass() != null) { {
superMethods = getAllMethods(clazz.getSuperclass()); Method[] retval = (Method[]) allMethods.get(clazz);
} else { if (retval == null)
superMethods = new Method[0]; {
} Set methods = new HashSet();
Vector v = new Vector(); Class c = clazz;
Method[] currentMethods = clazz.getDeclaredMethods(); while (c != null)
for(int i=0;i<currentMethods.length;i++) { {
v.addElement(currentMethods[i]); Method[] currentMethods = c.getDeclaredMethods();
} loop:
for(int i=0;i<superMethods.length;i++) { for (int i = 0; i < currentMethods.length; i++)
boolean addOK = true; {
for(int j=0;j<currentMethods.length;j++) { Method current = currentMethods[i];
if(getTruncatedName(superMethods[i].getName()).equals(getTruncatedName(currentMethods[j].getName())) int size = methods.size();
&& ArrayHelper.equalsArray(superMethods[i].getParameterTypes(),currentMethods[j].getParameterTypes())) { Iterator iter = methods.iterator();
addOK = false; while (--size >= 0)
} {
} Method override = (Method) iter.next();
if(addOK) { if (current.getName().equals(override.getName())
v.addElement(superMethods[i]); && Arrays.equals(current.getParameterTypes(),
} override.getParameterTypes())
} && current.getReturnType() == override.getReturnType())
continue loop;
retval = new Method[v.size()]; }
v.copyInto(retval); methods.add(current);
allMethods.put(clazz,retval); }
c = c.getSuperclass();
}
retval = new Method[methods.size()];
methods.toArray(retval);
allMethods.put(clazz, retval);
} }
return retval; return retval;
} }
/** Get all the methods, public, private and /** Cache of fields found in getAllFields(). */
** otherwise, from the class, and get them from private static Map allFields = new HashMap();
** their point of declaration.
**/ /**
public static Method[] getAllMethodsAtDeclaration(Class clazz) { * Get all the fields, public, private and otherwise, from the class,
Method[] retval = (Method[])allMethodsAtDeclaration.get(clazz); * getting them from the most recent class to find them. This may not
if(retval == null) { * be quite the correct approach, as this includes fields that are not
Method[] superMethods; * inherited or accessible from clazz, so beware.
if(clazz.getSuperclass() != null) { *
superMethods = getAllMethodsAtDeclaration(clazz.getSuperclass()); * @param clazz the class to start at
} else { * @return all fields declared or inherited in clazz
superMethods = new Method[0]; */
} public static Field[] getAllFields(Class clazz)
Vector v = new Vector(); {
Method[] currentMethods = clazz.getDeclaredMethods(); Field[] retval = (Field[]) allFields.get(clazz);
for(int i=0;i<superMethods.length;i++) { if (retval == null)
v.addElement(superMethods[i]); {
} Set fields = new HashSet();
for(int i=0;i<superMethods.length;i++) { Class c = clazz;
boolean addOK = true; while (c != null)
for(int j=0;j<currentMethods.length;j++) { {
if(getTruncatedName(superMethods[i].getName()).equals(getTruncatedName(currentMethods[j].getName())) Field[] currentFields = c.getDeclaredFields();
&& ArrayHelper.equalsArray(superMethods[i].getParameterTypes(),currentMethods[j].getParameterTypes())) { loop:
addOK = false; for (int i = 0; i < currentFields.length; i++)
} {
} Field current = currentFields[i];
if(addOK) { int size = fields.size();
v.addElement(superMethods[i]); Iterator iter = fields.iterator();
} while (--size >= 0)
} {
Field override = (Field) iter.next();
retval = new Method[v.size()]; if (current.getName().equals(override.getName())
v.copyInto(retval); && current.getType() == override.getType())
allMethodsAtDeclaration.put(clazz,retval); continue loop;
} }
return retval; fields.add(current);
} }
c = c.getSuperclass();
static Hashtable allFields = new Hashtable(); }
static Hashtable allFieldsAtDeclaration = new Hashtable(); retval = new Field[fields.size()];
fields.toArray(retval);
/** Get all the fields, public, private and allFields.put(clazz, retval);
** otherwise, from the class, getting them
** from the most recent class to find them.
**/
public static Field[] getAllFields(Class clazz) {
Field[] retval = (Field[])allFields.get(clazz);
if(retval == null) {
Field[] superFields;
if(clazz.getSuperclass() != null) {
superFields = getAllFields(clazz.getSuperclass());
} else {
superFields = new Field[0];
}
Vector v = new Vector();
Field[] currentFields = clazz.getDeclaredFields();
for(int i=0;i<currentFields.length;i++) {
v.addElement(currentFields[i]);
}
for(int i=0;i<superFields.length;i++) {
boolean addOK = true;
for(int j=0;j<currentFields.length;j++) {
if(getTruncatedName(superFields[i].getName()).equals(getTruncatedName(currentFields[j].getName()))) {
addOK = false;
}
}
if(addOK) {
v.addElement(superFields[i]);
}
}
retval = new Field[v.size()];
v.copyInto(retval);
allFields.put(clazz,retval);
}
return retval;
}
/** Get all the fields, public, private and
** otherwise, from the class, and get them from
** their point of declaration.
**/
public static Field[] getAllFieldsAtDeclaration(Class clazz) {
Field[] retval = (Field[])allFieldsAtDeclaration.get(clazz);
if(retval == null) {
Field[] superFields;
if(clazz.getSuperclass() != null) {
superFields = getAllFieldsAtDeclaration(clazz.getSuperclass());
} else {
superFields = new Field[0];
}
Vector v = new Vector();
Field[] currentFields = clazz.getDeclaredFields();
for(int i=0;i<superFields.length;i++) {
v.addElement(superFields[i]);
}
for(int i=0;i<superFields.length;i++) {
boolean addOK = true;
for(int j=0;j<currentFields.length;j++) {
if(getTruncatedName(superFields[i].getName()).equals(getTruncatedName(currentFields[j].getName()))) {
addOK = false;
}
}
if(addOK) {
v.addElement(superFields[i]);
}
}
retval = new Field[v.size()];
v.copyInto(retval);
allFieldsAtDeclaration.put(clazz,retval);
} }
return retval; return retval;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment