db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r998252 - /db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/TypeMap.java
Date Fri, 17 Sep 2010 18:52:46 GMT
Author: tfischer
Date: Fri Sep 17 18:52:45 2010
New Revision: 998252

URL: http://svn.apache.org/viewvc?rev=998252&view=rev
Log:
fix checkstyle issues
improve performance of isTextType()

Modified:
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/TypeMap.java

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/TypeMap.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/TypeMap.java?rev=998252&r1=998251&r2=998252&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/TypeMap.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/TypeMap.java
Fri Sep 17 18:52:45 2010
@@ -21,7 +21,9 @@ package org.apache.torque.templates.type
 
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.torque.generator.jdbc.SchemaType;
 
@@ -67,26 +69,35 @@ import org.apache.torque.generator.jdbc.
  * @author <a href="mailto:mpoeschl@marmot.at>Martin Poeschl</a>
  * @version $Id: TypeMap.java 473814 2006-11-11 22:30:30 +0000 (Sat, 11 Nov 2006) tv $
  */
-public class TypeMap
+public final class TypeMap
 {
-    private static final SchemaType[] TEXT_TYPES =
+    /**
+     * All text types.
+     */
+    private static final Set<SchemaType> TEXT_TYPES;
+
+    static
     {
-        SchemaType.CHAR,
-        SchemaType.VARCHAR,
-        SchemaType.LONGVARCHAR,
-        SchemaType.CLOB,
-        SchemaType.DATE,
-        SchemaType.TIME,
-        SchemaType.TIMESTAMP,
-        SchemaType.BOOLEANCHAR
-    };
+        Set<SchemaType> textTypes = new HashSet<SchemaType>();
+        textTypes.add(SchemaType.CHAR);
+        textTypes.add(SchemaType.VARCHAR);
+        textTypes.add(SchemaType.LONGVARCHAR);
+        textTypes.add(SchemaType.CLOB);
+        textTypes.add(SchemaType.DATE);
+        textTypes.add(SchemaType.TIME);
+        textTypes.add(SchemaType.TIMESTAMP);
+        textTypes.add(SchemaType.BOOLEANCHAR);
+        TEXT_TYPES = Collections.unmodifiableSet(textTypes);
+    }
 
     public static final String CHAR_OBJECT_TYPE = "\"\"";
     public static final String VARCHAR_OBJECT_TYPE = "\"\"";
     public static final String LONGVARCHAR_OBJECT_TYPE = "\"\"";
     public static final String CLOB_OBJECT_TYPE = "\"\"";
-    public static final String NUMERIC_OBJECT_TYPE = "new java.math.BigDecimal((double) 0)";
-    public static final String DECIMAL_OBJECT_TYPE = "new java.math.BigDecimal((double) 0)";
+    public static final String NUMERIC_OBJECT_TYPE 
+            = "new java.math.BigDecimal((double) 0)";
+    public static final String DECIMAL_OBJECT_TYPE 
+            = "new java.math.BigDecimal((double) 0)";
     public static final String BIT_OBJECT_TYPE = "new Boolean(true)";
     public static final String TINYINT_OBJECT_TYPE = "new Byte((byte)0)";
     public static final String SMALLINT_OBJECT_TYPE = "new Short((short)0)";
@@ -300,6 +311,12 @@ public class TypeMap
                 = Collections.unmodifiableMap(schemaToVillageMethod);
     }
 
+    /**
+     * Private constructor for utility class.
+     */
+    private TypeMap()
+    {
+    }
 
     /**
      * Return a Java object which corresponds to the
@@ -403,17 +420,8 @@ public class TypeMap
      * @param type The type to check.
      * @return true if values for the type need to be quoted.
      */
-    public static final boolean isTextType(SchemaType type)
+    public static boolean isTextType(SchemaType type)
     {
-        for (int i = 0; i < TEXT_TYPES.length; i++)
-        {
-            if (type.equals(TEXT_TYPES[i]))
-            {
-                return true;
-            }
-        }
-
-        // If we get this far, there were no matches.
-        return false;
+        return TEXT_TYPES.contains(type);
     }
 }



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


Mime
View raw message