jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1304397 - 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 14:56:31 GMT
Author: mduerig
Date: Fri Mar 23 14:56:31 2012
New Revision: 1304397

URL: http://svn.apache.org/viewvc?rev=1304397&view=rev
Log:
OAK-33: Values in oak-core (WIP)
- renamed factory methods
- added null value

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/KernelNodeState.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientNodeState.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=1304397&r1=1304396&r2=1304397&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 14:56:31 2012
@@ -10,50 +10,54 @@ import java.util.concurrent.Callable;
 public abstract class ScalarImpl implements Scalar {
     private final int type;
 
-    public static Scalar createNumber(String value) {
+    public static Scalar numberScalar(String value) {
         // todo improve
         try {
-            return createLong(Long.parseLong(value));
+            return longScalar(Long.parseLong(value));
         }
         catch (NumberFormatException e) {
-            return createDouble(Double.parseDouble(value));
+            return doubleScalar(Double.parseDouble(value));
         }
     }
 
-    public static Scalar createBoolean(final boolean value) {
+    public static Scalar booleanScalar(final boolean value) {
         return value ? TRUE_SCALAR : FALSE_SCALAR;
     }
     
-    public static Scalar createLong(final long value) {
+    public static Scalar longScalar(final long value) {
         return new LongScalar(value);
     }
+
+    public static Scalar nullScalar() {
+        return NULL_SCALAR;
+    }
     
-    public static Scalar createDouble(final double value) {
+    public static Scalar doubleScalar(final double value) {
         return new DoubleScalar(value);
     }
     
-    public static Scalar createString(final String value) {
+    public static Scalar stringScalar(final String value) {
         if (value == null) {
             throw new IllegalArgumentException("Value must not be null");
         }
         return new StringScalar(value);
     }
     
-    public static Scalar createBinary(final String value) {
+    public static Scalar binaryScalar(final String value) {
         if (value == null) {
             throw new IllegalArgumentException("Value must not be null");
         }
         return new SmallBinaryScalar(value);
     }
     
-    public static Scalar createBinary(final Callable<InputStream> valueProvider) {
+    public static Scalar binaryScalar(final Callable<InputStream> valueProvider) {
         if (valueProvider == null) {
             throw new IllegalArgumentException("Value must not be null");
         }
         return new BinaryScalar(valueProvider);
     }
 
-    protected ScalarImpl(int type) {
+    private ScalarImpl(int type) {
         this.type = type;
     }
 
@@ -134,6 +138,29 @@ public abstract class ScalarImpl impleme
         }
     }
 
+    private static final NullScalar NULL_SCALAR = new NullScalar();
+
+    private static final class NullScalar extends ScalarImpl {
+        protected NullScalar() {
+            super(Scalar.NULL);
+        }
+
+        @Override
+        public String getString() {
+            return "null";
+        }
+
+        @Override
+        public boolean equals(Object other) {
+            return this == other || other != null && getClass() == other.getClass();
+        }
+
+        @Override
+        public int hashCode() {
+            return 42;
+        }
+    }
+
     private static final class LongScalar extends ScalarImpl {
         private final long value;
 
@@ -270,7 +297,7 @@ public abstract class ScalarImpl impleme
         }
     }
 
-    private static class BinaryScalar extends ScalarImpl {
+    private static final class BinaryScalar extends ScalarImpl {
         private final Callable<InputStream> valueProvider;
 
         public BinaryScalar(Callable<InputStream> valueProvider) {
@@ -311,4 +338,5 @@ public abstract class ScalarImpl impleme
             return getString().hashCode();
         }
     }
+     
 }

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=1304397&r1=1304396&r2=1304397&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 14:56:31 2012
@@ -27,8 +27,9 @@ public interface Scalar {
     int DOUBLE = 2;
     int BINARY = 3;
     int STRING = 4;
+    int NULL = 5;
     
-    String[] typeNames = {"boolean", "long", "double", "binary", "string"};
+    String[] typeNames = {"boolean", "long", "double", "binary", "string", "null"};
 
     /**
      * Returns the value type.

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java?rev=1304397&r1=1304396&r2=1304397&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
Fri Mar 23 14:56:31 2012
@@ -89,16 +89,16 @@ public class KernelNodeState extends Abs
                             kernel, childPath, revision));
                 } else if (reader.matches(JsopTokenizer.NUMBER)) {
                     properties.put(name, new KernelPropertyState(
-                            name, ScalarImpl.createNumber(reader.getToken())));
+                            name, ScalarImpl.numberScalar(reader.getToken())));
                 } else if (reader.matches(JsopTokenizer.STRING)) {
                     properties.put(name, new KernelPropertyState(
-                            name, ScalarImpl.createString(reader.getToken())));
+                            name, ScalarImpl.stringScalar(reader.getToken())));
                 } else if (reader.matches(JsopTokenizer.TRUE)) {
                     properties.put(name, new KernelPropertyState(
-                            name, ScalarImpl.createBoolean(true)));
+                            name, ScalarImpl.booleanScalar(true)));
                 } else if (reader.matches(JsopTokenizer.FALSE)) {
                     properties.put(name, new KernelPropertyState(
-                            name, ScalarImpl.createBoolean(false)));
+                            name, ScalarImpl.booleanScalar(false)));
                 } else if (reader.matches('[')) {
                     properties.put(name, new KernelPropertyState(
                             name, readArray(reader)));
@@ -218,13 +218,13 @@ public class KernelNodeState extends Abs
         List<Scalar> values = new ArrayList<Scalar>();
         while (!reader.matches(']')) {
             if (reader.matches(JsopTokenizer.NUMBER)) {
-                values.add(ScalarImpl.createNumber(reader.getToken()));
+                values.add(ScalarImpl.numberScalar(reader.getToken()));
             } else if (reader.matches(JsopTokenizer.STRING)) {
-                values.add(ScalarImpl.createString(reader.getToken()));
+                values.add(ScalarImpl.stringScalar(reader.getToken()));
             } else if (reader.matches(JsopTokenizer.TRUE)) {
-                values.add(ScalarImpl.createBoolean(true));
+                values.add(ScalarImpl.booleanScalar(true));
             } else if (reader.matches(JsopTokenizer.FALSE)) {
-                values.add(ScalarImpl.createBoolean(false));
+                values.add(ScalarImpl.booleanScalar(false));
             } else {
                 throw new IllegalArgumentException("Unexpected token: " + reader.getToken());
             }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientNodeState.java?rev=1304397&r1=1304396&r2=1304397&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientNodeState.java
Fri Mar 23 14:56:31 2012
@@ -269,11 +269,11 @@ public class TransientNodeState {
     private static Scalar toScalar(JsonValue value) {
         switch (value.type()) {
             case STRING:
-                return ScalarImpl.createString(value.asAtom().value());
+                return ScalarImpl.stringScalar(value.asAtom().value());
             case NUMBER:
-                return ScalarImpl.createNumber(value.asAtom().value());
+                return ScalarImpl.numberScalar(value.asAtom().value());
             case BOOLEAN:
-                return ScalarImpl.createBoolean(value.asAtom().isTrue());
+                return ScalarImpl.booleanScalar(value.asAtom().isTrue());
             default:
                 throw new IllegalStateException("Invalid value");
         }

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=1304397&r1=1304396&r2=1304397&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 14:56:31 2012
@@ -45,16 +45,16 @@ public final class ValueConverter {
     public static Scalar toScalar(Value value) throws RepositoryException {
         switch (value.getType()) {
             case PropertyType.STRING: {
-                return ScalarImpl.createString(value.getString());
+                return ScalarImpl.stringScalar(value.getString());
             }
             case PropertyType.DOUBLE: {
-                return ScalarImpl.createDouble(value.getDouble());
+                return ScalarImpl.doubleScalar(value.getDouble());
             }
             case PropertyType.LONG: {
-                return ScalarImpl.createLong(value.getLong());
+                return ScalarImpl.longScalar(value.getLong());
             }
             case PropertyType.BOOLEAN: {
-                return ScalarImpl.createBoolean(value.getBoolean());
+                return ScalarImpl.booleanScalar(value.getBoolean());
             }
             case PropertyType.DECIMAL:
             case PropertyType.BINARY:



Mime
View raw message