You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2003/09/24 01:18:32 UTC

cvs commit: jakarta-commons-sandbox/primitives/src/codegen/org/apache/commons/primitive/iterator/impl ArrayXXXIterator.vm

scolebourne    2003/09/23 16:18:32

  Modified:    primitives/src/codegen/org/apache/commons/primitive
                        CodeGenerator.java
               primitives/src/codegen/org/apache/commons/primitive/iterator/impl
                        ArrayXXXIterator.vm
  Added:       primitives/src/codegen/org/apache/commons/primitive
                        XXXUtils.vm
  Log:
  Add Utils class
  
  Revision  Changes    Path
  1.2       +27 -17    jakarta-commons-sandbox/primitives/src/codegen/org/apache/commons/primitive/CodeGenerator.java
  
  Index: CodeGenerator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/primitives/src/codegen/org/apache/commons/primitive/CodeGenerator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CodeGenerator.java	20 Sep 2003 23:46:34 -0000	1.1
  +++ CodeGenerator.java	23 Sep 2003 23:18:32 -0000	1.2
  @@ -164,53 +164,63 @@
           TYPES[0].put("type", "long");
           TYPES[0].put("Type", "Long");
           TYPES[0].put("object", "Long");
  -        TYPES[0].put("preConvert", "new Long(");
  -        TYPES[0].put("postConvert", ")");
  +        TYPES[0].put("emptyArray", "EMPTY_LONG_ARRAY");
  +        TYPES[0].put("toObjectPre", "new Long(");
  +        TYPES[0].put("toObjectPost", ")");
           
           TYPES[1].put("type", "int");
           TYPES[1].put("Type", "Int");
           TYPES[1].put("object", "Integer");
  -        TYPES[1].put("preConvert", "new Integer(");
  -        TYPES[1].put("postConvert", ")");
  +        TYPES[1].put("emptyArray", "EMPTY_INT_ARRAY");
  +        TYPES[1].put("toObjectPre", "new Integer(");
  +        TYPES[1].put("toObjectPost", ")");
           
           TYPES[2].put("type", "short");
           TYPES[2].put("Type", "Short");
           TYPES[2].put("object", "Short");
  -        TYPES[2].put("preConvert", "new Short(");
  -        TYPES[2].put("postConvert", ")");
  +        TYPES[2].put("emptyArray", "EMPTY_SHORT_ARRAY");
  +        TYPES[2].put("toObjectPre", "new Short(");
  +        TYPES[2].put("toObjectPost", ")");
           
           TYPES[3].put("type", "byte");
           TYPES[3].put("Type", "Byte");
           TYPES[3].put("object", "Byte");
  -        TYPES[3].put("preConvert", "new Byte(");
  -        TYPES[3].put("postConvert", ")");
  +        TYPES[3].put("emptyArray", "EMPTY_BYTE_ARRAY");
  +        TYPES[3].put("toObjectPre", "new Byte(");
  +        TYPES[3].put("toObjectPost", ")");
           
           TYPES[4].put("type", "double");
           TYPES[4].put("Type", "Double");
           TYPES[4].put("object", "Double");
  -        TYPES[4].put("preConvert", "new Double(");
  -        TYPES[4].put("postConvert", ")");
  +        TYPES[4].put("emptyArray", "EMPTY_DOUBLE_ARRAY");
  +        TYPES[4].put("toObjectPre", "new Double(");
  +        TYPES[4].put("toObjectPost", ")");
           
           TYPES[5].put("type", "float");
           TYPES[5].put("Type", "Float");
           TYPES[5].put("object", "Float");
  -        TYPES[5].put("preConvert", "new Float(");
  -        TYPES[5].put("postConvert", ")");
  +        TYPES[5].put("emptyArray", "EMPTY_FLOAT_ARRAY");
  +        TYPES[5].put("toObjectPre", "new Float(");
  +        TYPES[5].put("toObjectPost", ")");
           
           TYPES[6].put("type", "char");
           TYPES[6].put("Type", "Char");
           TYPES[6].put("object", "Character");
  -        TYPES[6].put("preConvert", "new Character(");
  -        TYPES[6].put("postConvert", ")");
  +        TYPES[6].put("emptyArray", "EMPTY_CHAR_ARRAY");
  +        TYPES[6].put("toObjectPre", "new Character(");
  +        TYPES[6].put("toObjectPost", ")");
           
           TYPES[7].put("type", "boolean");
           TYPES[7].put("Type", "Boolean");
           TYPES[7].put("object", "Boolean");
  -        TYPES[7].put("preConvert", "(");
  -        TYPES[7].put("postConvert", " ? Boolean.TRUE : Boolean.FALSE)");
  +        TYPES[7].put("emptyArray", "EMPTY_BOOLEAN_ARRAY");
  +        TYPES[7].put("toObjectPre", "(");
  +        TYPES[7].put("toObjectPost", " ? Boolean.TRUE : Boolean.FALSE)");
       }
   
       private static final String[] TEMPLATE_FILENAMES = new String[] {
  +        "org/apache/commons/primitive/XXXUtils",
  +        
           "org/apache/commons/primitive/collection/XXXCollection",
           "org/apache/commons/primitive/iterator/XXXIterator",
           "org/apache/commons/primitive/list/XXXList",
  
  
  
  1.1                  jakarta-commons-sandbox/primitives/src/codegen/org/apache/commons/primitive/XXXUtils.vm
  
  Index: XXXUtils.vm
  ===================================================================
  ${license}
  package org.apache.commons.primitive;
  
  import java.util.Collection;
  import java.util.Iterator;
  
  import org.apache.commons.primitive.collection.${Type}Collection;
  
  /**
   * Provides utility methods and constants for <code>${type}</code>.
   * 
   * @author Stephen Colebourne
   * @version $Id: XXXUtils.vm,v 1.1 2003/09/23 23:18:32 scolebourne Exp $
   * @since 1.0
   */
  public class ${Type}Utils {
      // This file is CODE GENERATED. Do not change manually.
      
      /**
       * Immutable empty array.
       */
      public static final ${type}[] ${emptyArray} = new ${type}[0];
      
      /**
       * Constructor that should not usually be used.
       */
      public ${Type}Utils() {
      }
  
      /**
       * Wraps an <code>${type}</code> with an Object wrapper.
       * 
       * @param value  the primitive value
       * @return the Object wrapper
       */
      public static ${object} toObject(${type} value) {
          return ${toObjectPre}value${toObjectPost};
      }
  
      /**
       * Unwraps the <code>${object}</code> to retrieve the primitive <code>${type}</code>.
       * 
       * @param value  the Object wrapper, must not be null
       * @return the primitive value
       * @throws NullPointerException if the value if null
       * @throws ClassCastException if the object is not <code>${object}</code>
       */
      public static ${type} toPrimitive(Object value) {
          return ((${object}) value).${type}Value();
      }
  
      /**
       * Unwraps a <code>Collection</code> to retrieve the primitive <code>${type}</code>.
       * 
       * @param value  the Object wrapper, must not be null
       * @return the primitive value
       * @throws NullPointerException if the value if null
       * @throws ClassCastException if any object is not <code>${object}</code>
       */
      public static ${type}[] toPrimitiveArray(Collection coll) {
          if (coll instanceof ${Type}Collection) {
              return ((${Type}Collection) coll).toValueArray();
          }
          ${type}[] result = new ${type}[coll.size()];
          int i = 0;
          for (Iterator it = coll.iterator(); it.hasNext(); i++) {
              ${object} value = (${object}) it.next();
              result[i] = value.${type}Value();
          }
          return result;
      }
  
  }
  
  
  
  1.2       +4 -3      jakarta-commons-sandbox/primitives/src/codegen/org/apache/commons/primitive/iterator/impl/ArrayXXXIterator.vm
  
  Index: ArrayXXXIterator.vm
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/primitives/src/codegen/org/apache/commons/primitive/iterator/impl/ArrayXXXIterator.vm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ArrayXXXIterator.vm	20 Sep 2003 23:46:34 -0000	1.1
  +++ ArrayXXXIterator.vm	23 Sep 2003 23:18:32 -0000	1.2
  @@ -3,6 +3,7 @@
   
   import java.util.NoSuchElementException;
   
  +import org.apache.commons.primitive.${Type}Utils;
   import org.apache.commons.primitive.iterator.${Type}Iterator;
   
   /**
  @@ -53,13 +54,13 @@
   
       public ${type} nextValue() {
           if (hasNext() == false) {
  -            throw new NoSuchElementException("There are no more elements in this iterator");
  +            throw new NoSuchElementException("No more elements available");
           }
           return array[cursor++];
       }
   
       public Object next() {
  -        return ${preConvert}nextValue()${postConvert};
  +        return ${Type}Utils.toObject(nextValue());
       }
   
       public void remove() {
  
  
  

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