jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1330329 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/util/CoreValueUtil.java test/java/org/apache/jackrabbit/oak/util/CoreValueUtilTest.java
Date Wed, 25 Apr 2012 15:06:04 GMT
Author: angela
Date: Wed Apr 25 15:06:03 2012
New Revision: 1330329

URL: http://svn.apache.org/viewvc?rev=1330329&view=rev
Log:
OAK-33 : Values in oak-core (WIP)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/CoreValueUtil.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/util/CoreValueUtilTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/CoreValueUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/CoreValueUtil.java?rev=1330329&r1=1330328&r2=1330329&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/CoreValueUtil.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/CoreValueUtil.java
Wed Apr 25 15:06:03 2012
@@ -94,15 +94,20 @@ public class CoreValueUtil {
         CoreValue value;
         if (reader.matches(JsopTokenizer.NUMBER)) {
             String number = reader.getToken();
-            value = fromJsonString(number, JsopTokenizer.NUMBER, valueFactory);
+            value = valueFactory.createValue(Long.valueOf(number));
         } else if (reader.matches(JsopTokenizer.TRUE)) {
             value = valueFactory.createValue(true);
         } else if (reader.matches(JsopTokenizer.FALSE)) {
             value = valueFactory.createValue(false);
         } else if (reader.matches(JsopTokenizer.STRING)) {
-            String strValue = reader.getToken();
-            value = fromJsonString(strValue, JsopTokenizer.STRING, valueFactory);
-        }  else {
+            String jsonString = reader.getToken();
+            if (startsWithHint(jsonString)) {
+                int type = HINT2TYPE.get(jsonString.substring(0,3));
+                value = valueFactory.createValue(jsonString.substring(4), type);
+            } else {
+                value = valueFactory.createValue(jsonString);
+            }
+        } else {
             throw new IllegalArgumentException("Unexpected token: " + reader.getToken());
         }
         return value;
@@ -121,34 +126,6 @@ public class CoreValueUtil {
         }
     }
 
-    // TODO remove again
-    public static CoreValue fromJsonString(String jsonString, int jsopType, CoreValueFactory
valueFactory) {
-        CoreValue value;
-        switch (jsopType) {
-            case JsopTokenizer.NUMBER:
-                value = valueFactory.createValue(Long.valueOf(jsonString));
-                break;
-            case JsopTokenizer.FALSE:
-                value = valueFactory.createValue(false);
-                break;
-            case JsopTokenizer.TRUE:
-                value = valueFactory.createValue(true);
-                break;
-            case JsopTokenizer.STRING:
-                if (startsWithHint(jsonString)) {
-                    int type = HINT2TYPE.get(jsonString.substring(0,3));
-                    value = valueFactory.createValue(jsonString.substring(4), type);
-                } else {
-                    value = valueFactory.createValue(jsonString);
-                }
-                break;
-            default:
-                throw new IllegalArgumentException("Invalid jsop type: " + jsopType);
-        }
-        return value;
-    }
-
-
     private static String buildJsonStringWithType(CoreValue value) {
         StringBuilder sb = new StringBuilder();
         sb.append(TYPE2HINT.get(value.getType()));

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/util/CoreValueUtilTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/util/CoreValueUtilTest.java?rev=1330329&r1=1330328&r2=1330329&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/util/CoreValueUtilTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/util/CoreValueUtilTest.java
Wed Apr 25 15:06:03 2012
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.oak.util;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.json.JsopReader;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
 import org.apache.jackrabbit.mk.simple.SimpleKernelImpl;
 import org.apache.jackrabbit.oak.api.CoreValue;
@@ -101,17 +102,8 @@ public class CoreValueUtilTest {
     public void testFromJsonValue() throws IOException {
         for (CoreValue v : map.keySet()) {
             String json = map.get(v);
-            int jsopType;
-            if (v.getType() == PropertyType.BOOLEAN) {
-                jsopType = (v.getBoolean()) ? JsopTokenizer.TRUE : JsopTokenizer.FALSE;
-            } else if (v.getType() == PropertyType.LONG) {
-                jsopType = JsopTokenizer.NUMBER;
-            } else {
-                jsopType = JsopTokenizer.STRING;
-                // remove quotes
-                json = json.substring(1, json.length()-1);
-            }
-            assertEquals(v, CoreValueUtil.fromJsonString(json, jsopType, valueFactory));
+            JsopReader reader = new JsopTokenizer(json);
+            assertEquals(v, CoreValueUtil.fromJsopReader(reader, valueFactory));
         }
     }
 }
\ No newline at end of file



Mime
View raw message