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.
...@@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify ...@@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option) the Free Software Foundation; either version 2, or (at your option)
any later version. any later version.
GNU Classpath is distributed in the hope that it will be useful, but GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
...@@ -39,25 +39,42 @@ exception statement from your version. */ ...@@ -39,25 +39,42 @@ 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)) { *
return i; * @param array the array to search
} * @param searchFor the object to locate
} * @return the index of the first equal object, or -1
return -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 -1;
}
public static boolean equalsArray(Object[] a, Object[] b) { public static boolean equalsArray(Object[] a, Object[] b) {
if(a.length == b.length) { if(a.length == b.length) {
......
/* 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.
...@@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify ...@@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option) the Free Software Foundation; either version 2, or (at your option)
any later version. any later version.
GNU Classpath is distributed in the hope that it will be useful, but GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
...@@ -42,202 +42,144 @@ import java.util.*; ...@@ -42,202 +42,144 @@ 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) { */
return getTruncatedName(clazz.getName()); public static String getTruncatedClassName(Class clazz)
} {
/** Strip the package part from the class name, or the return getTruncatedName(clazz.getName());
** class part from the method or field name. }
** @param name the name to truncate.
** @return the truncated name. /**
**/ * Strip the package part from the class name, or the class part from
public static String getTruncatedName(String name) { * the method or field name.
int lastInd = name.lastIndexOf('.'); *
if(lastInd == -1) { * @param name the name to truncate
return name; * @return the truncated name
} else { */
return name.substring(lastInd+1); public static String getTruncatedName(String name)
} {
} int lastInd = name.lastIndexOf('.');
if (lastInd == -1)
/** Strip the last portion of the name (after the last return name;
** dot). return name.substring(lastInd + 1);
** @param name the name to get package of. }
** @return the package name. "" if no package.
**/ /**
public static String getPackagePortion(String name) { * Strip the last portion of the name (after the last dot).
int lastInd = name.lastIndexOf('.'); *
if(lastInd == -1) { * @param name the name to get package of
return ""; * @return the package name, or "" if no package
} else { */
return name.substring(0,lastInd); public static String getPackagePortion(String name)
} {
} int lastInd = name.lastIndexOf('.');
if (lastInd == -1)
static Hashtable allMethods = new Hashtable(); return "";
static Hashtable allMethodsAtDeclaration = new Hashtable(); return name.substring(0, lastInd);
}
/** Get all the methods, public, private and
** otherwise, from the class, getting them /** Cache of methods found in getAllMethods(). */
** from the most recent class to find them. private static Map allMethods = new HashMap();
**/
public static Method[] getAllMethods(Class clazz) { /**
Method[] retval = (Method[])allMethods.get(clazz); * Get all the methods, public, private and otherwise, from the class,
if(retval == null) { * getting them from the most recent class to find them. This may not
Method[] superMethods; * be quite the correct approach, as this includes methods that are not
if(clazz.getSuperclass() != null) { * inherited or accessible from clazz, so beware.
superMethods = getAllMethods(clazz.getSuperclass()); *
} else { * @param clazz the class to start at
superMethods = new Method[0]; * @return all methods declared or inherited in clazz
} */
Vector v = new Vector(); public static Method[] getAllMethods(Class clazz)
Method[] currentMethods = clazz.getDeclaredMethods(); {
for(int i=0;i<currentMethods.length;i++) { Method[] retval = (Method[]) allMethods.get(clazz);
v.addElement(currentMethods[i]); if (retval == null)
} {
for(int i=0;i<superMethods.length;i++) { Set methods = new HashSet();
boolean addOK = true; Class c = clazz;
for(int j=0;j<currentMethods.length;j++) { while (c != null)
if(getTruncatedName(superMethods[i].getName()).equals(getTruncatedName(currentMethods[j].getName())) {
&& ArrayHelper.equalsArray(superMethods[i].getParameterTypes(),currentMethods[j].getParameterTypes())) { Method[] currentMethods = c.getDeclaredMethods();
addOK = false; loop:
} for (int i = 0; i < currentMethods.length; i++)
} {
if(addOK) { Method current = currentMethods[i];
v.addElement(superMethods[i]); int size = methods.size();
} Iterator iter = methods.iterator();
} while (--size >= 0)
{
retval = new Method[v.size()]; Method override = (Method) iter.next();
v.copyInto(retval); if (current.getName().equals(override.getName())
allMethods.put(clazz,retval); && Arrays.equals(current.getParameterTypes(),
} override.getParameterTypes())
return retval; && current.getReturnType() == override.getReturnType())
} continue loop;
}
/** Get all the methods, public, private and methods.add(current);
** otherwise, from the class, and get them from }
** their point of declaration. c = c.getSuperclass();
**/ }
public static Method[] getAllMethodsAtDeclaration(Class clazz) { retval = new Method[methods.size()];
Method[] retval = (Method[])allMethodsAtDeclaration.get(clazz); methods.toArray(retval);
if(retval == null) { allMethods.put(clazz, retval);
Method[] superMethods; }
if(clazz.getSuperclass() != null) { return retval;
superMethods = getAllMethodsAtDeclaration(clazz.getSuperclass()); }
} else {
superMethods = new Method[0]; /** Cache of fields found in getAllFields(). */
} private static Map allFields = new HashMap();
Vector v = new Vector();
Method[] currentMethods = clazz.getDeclaredMethods(); /**
for(int i=0;i<superMethods.length;i++) { * Get all the fields, public, private and otherwise, from the class,
v.addElement(superMethods[i]); * getting them from the most recent class to find them. This may not
} * be quite the correct approach, as this includes fields that are not
for(int i=0;i<superMethods.length;i++) { * inherited or accessible from clazz, so beware.
boolean addOK = true; *
for(int j=0;j<currentMethods.length;j++) { * @param clazz the class to start at
if(getTruncatedName(superMethods[i].getName()).equals(getTruncatedName(currentMethods[j].getName())) * @return all fields declared or inherited in clazz
&& ArrayHelper.equalsArray(superMethods[i].getParameterTypes(),currentMethods[j].getParameterTypes())) { */
addOK = false; public static Field[] getAllFields(Class clazz)
} {
} Field[] retval = (Field[]) allFields.get(clazz);
if(addOK) { if (retval == null)
v.addElement(superMethods[i]); {
} Set fields = new HashSet();
} Class c = clazz;
while (c != null)
retval = new Method[v.size()]; {
v.copyInto(retval); Field[] currentFields = c.getDeclaredFields();
allMethodsAtDeclaration.put(clazz,retval); loop:
} for (int i = 0; i < currentFields.length; i++)
return retval; {
} Field current = currentFields[i];
int size = fields.size();
static Hashtable allFields = new Hashtable(); Iterator iter = fields.iterator();
static Hashtable allFieldsAtDeclaration = new Hashtable(); while (--size >= 0)
{
/** Get all the fields, public, private and Field override = (Field) iter.next();
** otherwise, from the class, getting them if (current.getName().equals(override.getName())
** from the most recent class to find them. && current.getType() == override.getType())
**/ continue loop;
public static Field[] getAllFields(Class clazz) { }
Field[] retval = (Field[])allFields.get(clazz); fields.add(current);
if(retval == null) { }
Field[] superFields; c = c.getSuperclass();
if(clazz.getSuperclass() != null) { }
superFields = getAllFields(clazz.getSuperclass()); retval = new Field[fields.size()];
} else { fields.toArray(retval);
superFields = new Field[0]; allFields.put(clazz, retval);
} }
Vector v = new Vector(); return retval;
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;
}
} }
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