Thread: [Ejtools-cvs] CVS: libraries/common/src/main/net/sourceforge/ejtools/util ClassTools.java,1.2,1.3 JN
Brought to you by:
letiemble
From: Laurent E. <let...@us...> - 2002-05-02 19:25:57
|
Update of /cvsroot/ejtools/libraries/common/src/main/net/sourceforge/ejtools/util In directory usw-pr-cvs1:/tmp/cvs-serv1397/common/src/main/net/sourceforge/ejtools/util Modified Files: ClassTools.java JNDI.java LimitedStack.java Sort.java Log Message: Add some JavaDocs Index: ClassTools.java =================================================================== RCS file: /cvsroot/ejtools/libraries/common/src/main/net/sourceforge/ejtools/util/ClassTools.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ClassTools.java 30 Apr 2002 21:07:38 -0000 1.2 --- ClassTools.java 2 May 2002 19:25:54 -0000 1.3 *************** *** 8,26 **** /** ! * Description of the Class * ! * @author letiembl ! * @created 25 avril 2002 */ public class ClassTools { /** ! * Getter for the class attribute * ! * @param fullPathClassName Description of Parameter ! * @return The value of class attribute */ public static Class getClass(String fullPathClassName) { if (fullPathClassName.equals("int")) { --- 8,86 ---- /** ! * Utility class to handle Class realted stuff. * ! * @author letiemble ! * @created 25 avril 2002 ! * @version $Revision$ */ public class ClassTools { + /** ! * Pretty print a full qualified class name. Specially useful for object ! * arrays. * ! * @param className The fully qualified class name ! * @return The pretty class name ! */ ! public static String classDisplay(String className) ! { ! String result = className; ! ! if (className == null) ! { ! return null; ! } ! ! if (className.startsWith("[Z")) ! { ! result = "boolean[]"; ! } ! if (className.startsWith("[C")) ! { ! result = "char[]"; ! } ! if (className.startsWith("[D")) ! { ! result = "double[]"; ! } ! if (className.startsWith("[F")) ! { ! result = "float[]"; ! } ! if (className.startsWith("[I")) ! { ! result = "int[]"; ! } ! if (className.startsWith("[S")) ! { ! result = "short[]"; ! } ! if (className.startsWith("[J")) ! { ! result = "long[]"; ! } ! if (className.startsWith("[B")) ! { ! result = "byte[]"; ! } ! if (className.startsWith("[L")) ! { ! result = className.substring(2, className.length() - 1) + "[]"; ! } ! ! return result; ! } ! ! ! /** ! * Get the class by its name. ! * ! * @param fullPathClassName The full qualified name of the class ! * @return The class if it is found, otherwise null */ public static Class getClass(String fullPathClassName) { + // Check if the class is a primitive type if (fullPathClassName.equals("int")) { *************** *** 56,59 **** --- 116,120 ---- } + // Try to load the class Class c = null; try *************** *** 63,107 **** catch (Throwable e) { } return c; - } - - - /** - * Description of the Method - * - * @param s Description of Parameter - * @return Description of the Returned Value - */ - public static String classDisplay(String s) - { - String result = s; - - if (s == null) - return null; - - if (s.startsWith("[Z")) - result = "boolean[]"; - if (s.startsWith("[C")) - result = "char[]"; - if (s.startsWith("[D")) - result = "double[]"; - if (s.startsWith("[F")) - result = "float[]"; - if (s.startsWith("[I")) - result = "int[]"; - if (s.startsWith("[S")) - result = "short[]"; - if (s.startsWith("[J")) - result = "long[]"; - if (s.startsWith("[B")) - result = "byte[]"; - if (s.startsWith("[L")) - { - result = s.substring(2, s.length() - 1) + "[]"; - } - - return result; } } --- 124,131 ---- catch (Throwable e) { + // Ignore it } return c; } } Index: JNDI.java =================================================================== RCS file: /cvsroot/ejtools/libraries/common/src/main/net/sourceforge/ejtools/util/JNDI.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** JNDI.java 2 May 2002 07:34:02 -0000 1.3 --- JNDI.java 2 May 2002 19:25:54 -0000 1.4 *************** *** 16,25 **** /** ! * Utility class to access environment properties ! * for JNDI. * ! * @author letiembl ! * @created 12 novembre 2001 ! * @version $Revision$ */ public abstract class JNDI --- 16,24 ---- /** ! * Utility class to access environment properties for JNDI. * ! * @author letiemble ! * @created 12 novembre 2001 ! * @version $Revision$ */ public abstract class JNDI *************** *** 27,34 **** /** Log4j Logger */ static Category logger = Category.getInstance(JNDI.class); ! ! /** ! * Look-up for a file named jndi.properties in the ! * classpath. If found, it is load into the VM environment. */ public static void setJNDIProperties() --- 26,34 ---- /** Log4j Logger */ static Category logger = Category.getInstance(JNDI.class); ! ! ! /** ! * Look-up for a file named jndi.properties in the classpath. If found, it is ! * load into the VM environment. */ public static void setJNDIProperties() *************** *** 40,45 **** if (in != null) { ! logger.debug("Found jndi.properties in classpath"); ! // Load the jndi.properties file Properties props = new Properties(); --- 40,45 ---- if (in != null) { ! logger.debug("Found jndi.properties in classpath"); ! // Load the jndi.properties file Properties props = new Properties(); *************** *** 47,51 **** in.close(); ! logger.debug("Setting VM environment"); // Set up the environment --- 47,51 ---- in.close(); ! logger.debug("Setting VM environment"); // Set up the environment *************** *** 58,62 **** { // Ignore it ! logger.warn("Exception while loading jndi.properties " + ioe.getMessage()); } } --- 58,62 ---- { // Ignore it ! logger.warn("Exception while loading jndi.properties " + ioe.getMessage()); } } Index: LimitedStack.java =================================================================== RCS file: /cvsroot/ejtools/libraries/common/src/main/net/sourceforge/ejtools/util/LimitedStack.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** LimitedStack.java 19 Apr 2002 07:05:02 -0000 1.1 --- LimitedStack.java 2 May 2002 19:25:54 -0000 1.2 *************** *** 10,25 **** /** ! * Description of the Class * ! * @author laurent ! * @created 24 décembre 2001 ! * @todo Javadoc to complete */ public class LimitedStack extends Stack { ! private int maximumSize; ! /** Constructor for the LimitedStack object */ public LimitedStack() { --- 10,27 ---- /** ! * Extension of the Stack class, which has a limited depth (FIFO stack). This ! * class doesn't allow duplicates. * ! * @author letiemble ! * @created 24 décembre 2001 ! * @version $Revision$ */ public class LimitedStack extends Stack { ! /** Maximum number elements allowed in the stack */ ! protected int maximumSize; ! /** Constructor for the LimitedStack object */ public LimitedStack() { *************** *** 29,35 **** /** ! * Constructor for the LimitedStack object * ! * @param size Description of Parameter */ public LimitedStack(int size) --- 31,37 ---- /** ! * Constructor for the LimitedStack object * ! * @param size Depth size of the stack */ public LimitedStack(int size) *************** *** 40,50 **** /** ! * Description of the Method * ! * @param item Description of Parameter ! * @return Description of the Returned Value */ public Object push(Object item) { if (this.contains(item)) { --- 42,53 ---- /** ! * Overrides the push method to limit the number of elements. * ! * @param item Item to push onto the stack ! * @return The item pushed */ public Object push(Object item) { + // Remove duplicate if (this.contains(item)) { *************** *** 53,56 **** --- 56,60 ---- else { + // If size is exceeded, remove the first in if (this.size() >= this.maximumSize) { *************** *** 58,61 **** --- 62,67 ---- } } + + // Push the item return super.push(item); } Index: Sort.java =================================================================== RCS file: /cvsroot/ejtools/libraries/common/src/main/net/sourceforge/ejtools/util/Sort.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Sort.java 30 Apr 2002 21:02:50 -0000 1.2 --- Sort.java 2 May 2002 19:25:54 -0000 1.3 *************** *** 15,141 **** /** ! * Description of the Class * ! * @author laurent ! * @created 24 décembre 2001 */ public abstract class Sort { /** ! * Gets the childrenByClass attribute of the Sort class * ! * @param enum Description of Parameter ! * @param c Description of Parameter ! * @return The childrenByClass value */ ! public static Iterator getChildrenByClass(Iterator enum, Class c) { ! Object obj; ! Vector v = new Vector(); ! while (enum.hasNext()) { ! if (c.isAssignableFrom((obj = enum.next()).getClass())) { ! v.addElement(obj); } } ! return v.iterator(); ! } ! ! ! /** ! * Description of the Method ! * ! * @param enum Description of Parameter ! * @param bean Description of Parameter ! * @param propertyName Description of Parameter ! * @return Description of the Returned Value ! */ ! public static Iterator sortByProperty(Iterator enum, Class bean, String propertyName) ! { ! Vector v = new Vector(); ! while (enum.hasNext()) ! { ! v.addElement(enum.next()); ! } ! ! try ! { ! final PropertyDescriptor pd = new PropertyDescriptor(propertyName, bean); ! final Method m = pd.getReadMethod(); ! ! Collections.sort(v, ! new Comparator() ! { ! public int compare(Object o1, Object o2) ! { ! Comparable val1; ! Comparable val2; ! ! try ! { ! val1 = (Comparable) m.invoke(o1, new Object[0]); ! val2 = (Comparable) m.invoke(o2, new Object[0]); ! } ! catch (Exception e) ! { ! return 0; ! } ! ! if (val1 == null) ! { ! return -1; ! } ! if (val2 == null) ! { ! return 1; ! } ! ! try ! { ! return val1.compareTo(val2); ! } ! catch (Exception e) ! { ! // Ignore it ! } ! return 0; ! } ! ! ! public boolean equals(Object obj) ! { ! return true; ! // Ever called? ! } ! }); ! } ! catch (Exception e) ! { ! // Ignore it ! } ! ! return v.iterator(); } /** ! * Description of the Method * ! * @param enum Description of Parameter ! * @return Description of the Returned Value */ ! public static Iterator sortByClass(Iterator enum) { ! Vector v = new Vector(); ! while (enum.hasNext()) { ! v.addElement(enum.next()); } ! Collections.sort(v, new Comparator() { public int compare(Object o1, Object o2) { --- 15,72 ---- /** ! * Utility class that provides different kind of sort strategies for Iterator. * ! * @author letiemble ! * @created 24 décembre 2001 ! * @version $Revision$ */ public abstract class Sort { /** ! * Extract the elements of the specified class from the Iterator. * ! * @param iterator Iterator to scan ! * @param clazz Class used for the extraction ! * @return The elements of the specified class */ ! public static Iterator getChildrenByClass(Iterator iterator, Class clazz) { ! Object object; ! Vector vector = new Vector(); ! ! while (iterator.hasNext()) { ! // Check if the object is instance of class ! if (clazz.isAssignableFrom((object = iterator.next()).getClass())) { ! vector.addElement(object); } } ! // Return the result ! return vector.iterator(); } /** ! * Sort the iterator by class name * ! * @param iterator Iterator to sort ! * @return The iterator sorted */ ! public static Iterator sortByClass(Iterator iterator) { ! // Create a vector from the iterator ! Vector vector = new Vector(); ! while (iterator.hasNext()) { ! vector.addElement(iterator.next()); } ! // Apply the comparator ! Collections.sort(vector, new Comparator() { + // Compare by class name public int compare(Object o1, Object o2) { *************** *** 150,172 **** } }); ! return v.iterator(); } /** ! * Description of the Method * ! * @param enum Description of Parameter ! * @return Description of the Returned Value */ ! public static Iterator sortByClassAndName(Iterator enum) { ! Vector v = new Vector(); ! while (enum.hasNext()) { ! v.addElement(enum.next()); } ! Collections.sort(v, new Comparator() { --- 81,107 ---- } }); ! ! // Return the result ! return vector.iterator(); } /** ! * Sort the iterator by class name and by toString method * ! * @param iterator Iterator to sort ! * @return The iterator sorted */ ! public static Iterator sortByClassAndName(Iterator iterator) { ! // Create a vector from the iterator ! Vector vector = new Vector(); ! while (iterator.hasNext()) { ! vector.addElement(iterator.next()); } ! // Apply the comparator ! Collections.sort(vector, new Comparator() { *************** *** 188,210 **** } }); ! return v.iterator(); } /** ! * Description of the Method * ! * @param enum Description of Parameter ! * @return Description of the Returned Value */ ! public static Iterator sortByName(Iterator enum) { ! Vector v = new Vector(); ! while (enum.hasNext()) { ! v.addElement(enum.next()); } ! Collections.sort(v, new Comparator() { --- 123,149 ---- } }); ! ! // Return the result ! return vector.iterator(); } /** ! * Sort the iterator by toString method * ! * @param iterator Iterator to sort ! * @return The iterator sorted */ ! public static Iterator sortByName(Iterator iterator) { ! // Create a vector from the iterator ! Vector vector = new Vector(); ! while (iterator.hasNext()) { ! vector.addElement(iterator.next()); } ! // Apply the comparator ! Collections.sort(vector, new Comparator() { *************** *** 221,225 **** } }); ! return v.iterator(); } } --- 160,246 ---- } }); ! ! // Return the result ! return vector.iterator(); ! } ! ! ! /** ! * Sort and iterator of JavaBeans by comparing the given property ! * ! * @param iterator Iterator to sort ! * @param clazz The class of the JavaBean ! * @param propertyName The property used for sorting ! * @return The iterator sorted ! */ ! public static Iterator sortByProperty(Iterator iterator, Class clazz, String propertyName) ! { ! // Create a vector from the iterator ! Vector vector = new Vector(); ! while (iterator.hasNext()) ! { ! vector.addElement(iterator.next()); ! } ! ! try ! { ! // Create the descriptor of the getter ! final PropertyDescriptor pd = new PropertyDescriptor(propertyName, clazz); ! final Method m = pd.getReadMethod(); ! ! // Apply the comparator ! Collections.sort(vector, ! new Comparator() ! { ! public int compare(Object o1, Object o2) ! { ! Comparable val1; ! Comparable val2; ! ! try ! { ! val1 = (Comparable) m.invoke(o1, new Object[0]); ! val2 = (Comparable) m.invoke(o2, new Object[0]); ! } ! catch (Exception e) ! { ! return 0; ! } ! ! if (val1 == null) ! { ! return -1; ! } ! if (val2 == null) ! { ! return 1; ! } ! ! try ! { ! return val1.compareTo(val2); ! } ! catch (Exception e) ! { ! // Ignore it ! } ! return 0; ! } ! ! ! public boolean equals(Object obj) ! { ! return true; ! // Ever called? ! } ! }); ! } ! catch (Exception e) ! { ! // Ignore it ! } ! ! // Return the result ! return vector.iterator(); } } |