jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1304547 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/ oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/ oak-jcr/src/main/java/org/apache/jackrabbit/oa...
Date Fri, 23 Mar 2012 18:30:03 GMT
Author: mduerig
Date: Fri Mar 23 18:30:03 2012
New Revision: 1304547

URL: http://svn.apache.org/viewvc?rev=1304547&view=rev
Log:
OAK-33: Values in oak-core
use enum instead of magic numbers for type

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/ScalarImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Scalar.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/ValueConverter.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/ScalarImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/ScalarImpl.java?rev=1304547&r1=1304546&r2=1304547&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/ScalarImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/ScalarImpl.java Fri
Mar 23 18:30:03 2012
@@ -8,7 +8,7 @@ import java.io.UnsupportedEncodingExcept
 import java.util.concurrent.Callable;
 
 public abstract class ScalarImpl implements Scalar {
-    private final int type;
+    private final Type type;
 
     public static Scalar numberScalar(String value) {
         // todo improve
@@ -57,12 +57,12 @@ public abstract class ScalarImpl impleme
         return new BinaryScalar(valueProvider);
     }
 
-    private ScalarImpl(int type) {
+    private ScalarImpl(Type type) {
         this.type = type;
     }
 
     @Override
-    public int getType() {
+    public Type getType() {
         return type;   
     }
 
@@ -94,7 +94,7 @@ public abstract class ScalarImpl impleme
 
     @Override
     public String toString() {
-        return getString() + ": " + Scalar.typeNames[type];
+        return getString() + ": " + type;
     }
 
     //------------------------------------------------------------< private >---
@@ -106,7 +106,7 @@ public abstract class ScalarImpl impleme
         private final boolean value;
 
         public BooleanScalar(boolean value) {
-            super(Scalar.BOOLEAN);
+            super(Type.BOOLEAN);
             this.value = value;
         }
 
@@ -130,7 +130,7 @@ public abstract class ScalarImpl impleme
             }
 
             Scalar that = (Scalar) other;
-            return that != null && that.getType() == Scalar.BOOLEAN && that.getBoolean()
== value;
+            return that != null && that.getType() == Type.BOOLEAN && that.getBoolean()
== value;
         }
 
         @Override
@@ -143,7 +143,7 @@ public abstract class ScalarImpl impleme
 
     private static final class NullScalar extends ScalarImpl {
         protected NullScalar() {
-            super(Scalar.NULL);
+            super(Type.NULL);
         }
 
         @Override
@@ -161,7 +161,7 @@ public abstract class ScalarImpl impleme
             }
 
             Scalar that = (Scalar) other;
-            return that != null && that.getType() == Scalar.NULL;
+            return that != null && that.getType() == Type.NULL;
         }
 
         @Override
@@ -174,7 +174,7 @@ public abstract class ScalarImpl impleme
         private final long value;
 
         public LongScalar(long value) {
-            super(Scalar.LONG);
+            super(Type.LONG);
             this.value = value;
         }
 
@@ -198,7 +198,7 @@ public abstract class ScalarImpl impleme
             }
 
             Scalar that = (Scalar) other;
-            return that != null && that.getType() == Scalar.LONG && that.getLong()
== value;
+            return that != null && that.getType() == Type.LONG && that.getLong()
== value;
         }
 
         @Override
@@ -211,7 +211,7 @@ public abstract class ScalarImpl impleme
         private final double value;
 
         public DoubleScalar(double value) {
-            super(Scalar.DOUBLE);
+            super(Type.DOUBLE);
             this.value = value;
         }
 
@@ -235,7 +235,7 @@ public abstract class ScalarImpl impleme
             }
 
             Scalar that = (Scalar) other;
-            return that != null && that.getType() == Scalar.DOUBLE && Double.compare(that.getDouble(),
value) == 0;
+            return that != null && that.getType() == Type.DOUBLE && Double.compare(that.getDouble(),
value) == 0;
         }
 
         @Override
@@ -249,7 +249,7 @@ public abstract class ScalarImpl impleme
         private final String value;
 
         public StringScalar(String value) {
-            super(Scalar.STRING);
+            super(Type.STRING);
             this.value = value;
         }
 
@@ -268,7 +268,7 @@ public abstract class ScalarImpl impleme
             }
 
             Scalar that = (Scalar) other;
-            return that != null && that.getType() == Scalar.STRING && that.getString().equals(value);
+            return that != null && that.getType() == Type.STRING && that.getString().equals(value);
         }
 
         @Override
@@ -281,7 +281,7 @@ public abstract class ScalarImpl impleme
         private final String value;
 
         public SmallBinaryScalar(String value) {
-            super(Scalar.BINARY);
+            super(Type.BINARY);
             this.value = value;
         }
 
@@ -300,7 +300,7 @@ public abstract class ScalarImpl impleme
             }
 
             Scalar that = (Scalar) other;
-            return that != null && that.getType() == Scalar.BINARY && that.getString().equals(value);
+            return that != null && that.getType() == Type.BINARY && that.getString().equals(value);
         }
 
         @Override
@@ -313,7 +313,7 @@ public abstract class ScalarImpl impleme
         private final Callable<InputStream> valueProvider;
 
         public BinaryScalar(Callable<InputStream> valueProvider) {
-            super(Scalar.BINARY);
+            super(Type.BINARY);
             this.valueProvider = valueProvider;
         }
 
@@ -343,7 +343,7 @@ public abstract class ScalarImpl impleme
             }
 
             Scalar that = (Scalar) other;
-            return that != null && that.getType() == Scalar.BINARY && that.getString().equals(getString());
+            return that != null && that.getType() == Type.BINARY && that.getString().equals(getString());
         }
 
         @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Scalar.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Scalar.java?rev=1304547&r1=1304546&r2=1304547&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Scalar.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Scalar.java
Fri Mar 23 18:30:03 2012
@@ -22,23 +22,15 @@ import java.io.InputStream;
  * An immutable, typed scalar value.
  */
 public interface Scalar {
-    int BOOLEAN = 0;
-    int LONG = 1;
-    int DOUBLE = 2;
-    int BINARY = 3;
-    int STRING = 4;
-    int NULL = 5;
-    
-    String[] typeNames = {"boolean", "long", "double", "binary", "string", "null"};
+    enum Type {BOOLEAN, LONG, DOUBLE, BINARY, STRING, NULL}
 
     /**
      * Returns the value type.
      * <p>
-     * TODO: Define value types
      *
      * @return value type
      */
-    int getType();
+    Type getType();
 
     boolean getBoolean();
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java?rev=1304547&r1=1304546&r2=1304547&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
Fri Mar 23 18:30:03 2012
@@ -21,6 +21,7 @@ package org.apache.jackrabbit.oak.kernel
 import org.apache.jackrabbit.mk.json.JsonBuilder;
 import org.apache.jackrabbit.mk.model.AbstractPropertyState;
 import org.apache.jackrabbit.oak.api.Scalar;
+import org.apache.jackrabbit.oak.api.Scalar.Type;
 
 import java.util.Collections;
 import java.util.List;
@@ -81,7 +82,7 @@ public class KernelPropertyState extends
     //------------------------------------------------------------< private >--- 
     
     private static String encodeValue(Scalar value) {
-        if (value.getType() == Scalar.STRING) {
+        if (value.getType() == Type.STRING) {
             return '"' + JsonBuilder.escape(value.getString()) + '"';
         }
         else {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/ValueConverter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/ValueConverter.java?rev=1304547&r1=1304546&r2=1304547&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/ValueConverter.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/ValueConverter.java
Fri Mar 23 18:30:03 2012
@@ -80,13 +80,13 @@ public final class ValueConverter {
             throws UnsupportedRepositoryOperationException {
 
         switch (scalar.getType()) {
-            case Scalar.BOOLEAN:
+            case BOOLEAN:
                 return valueFactory.createValue(scalar.getBoolean());
-            case Scalar.LONG:
+            case LONG:
                 return valueFactory.createValue(scalar.getLong());
-            case Scalar.DOUBLE:
+            case DOUBLE:
                 return valueFactory.createValue(scalar.getDouble());
-            case Scalar.STRING:
+            case STRING:
                 return valueFactory.createValue(scalar.getString());
             default:
                 throw new UnsupportedRepositoryOperationException("toValue"); // todo implement
toValue



Mime
View raw message