commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmi...@apache.org
Subject cvs commit: jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/util ValueUtils.java
Date Sun, 28 Apr 2002 04:31:13 GMT
dmitri      02/04/27 21:31:13

  Modified:    jxpath/src/java/org/apache/commons/jxpath/util
                        ValueUtils.java
  Log:
  Added a generic iterator
  
  Revision  Changes    Path
  1.4       +27 -4     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/util/ValueUtils.java
  
  Index: ValueUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/util/ValueUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ValueUtils.java	26 Apr 2002 03:28:37 -0000	1.3
  +++ ValueUtils.java	28 Apr 2002 04:31:13 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/util/ValueUtils.java,v
1.3 2002/04/26 03:28:37 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/04/26 03:28:37 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/util/ValueUtils.java,v
1.4 2002/04/28 04:31:13 dmitri Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/04/28 04:31:13 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -71,7 +71,7 @@
   
   /**
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2002/04/26 03:28:37 $
  + * @version $Revision: 1.4 $ $Date: 2002/04/28 04:31:13 $
    */
   public class ValueUtils {
       private static Map dynamicPropertyHandlerMap = new HashMap();
  @@ -114,6 +114,29 @@
           }
           else {
               return 1;
  +        }
  +    }
  +    
  +    public static Iterator iterate(Object collection){
  +        if (collection == null){
  +            return Collections.EMPTY_LIST.iterator();
  +        }
  +        if (collection.getClass().isArray()){
  +            int length = Array.getLength(collection);
  +            if (length == 0){
  +                return Collections.EMPTY_LIST.iterator();
  +            }
  +            ArrayList list = new ArrayList();
  +            for (int i = 0; i < length; i++){
  +                list.add(Array.get(collection, i));
  +            }
  +            return list.iterator();
  +        }
  +        else if (collection instanceof Collection){
  +            return ((Collection)collection).iterator();
  +        }
  +        else {
  +            return Collections.singletonList(collection).iterator();
           }
       }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message