jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1212036 - /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsonValue.java
Date Thu, 08 Dec 2011 19:08:16 GMT
Author: mduerig
Date: Thu Dec  8 19:08:15 2011
New Revision: 1212036

URL: http://svn.apache.org/viewvc?rev=1212036&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
- add factory methods
- add remove method

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsonValue.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsonValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsonValue.java?rev=1212036&r1=1212035&r2=1212036&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsonValue.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsonValue.java
Thu Dec  8 19:08:15 2011
@@ -19,7 +19,10 @@
 
 package org.apache.jackrabbit.spi2microkernel.json;
 
+import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -27,7 +30,7 @@ import java.util.Map.Entry;
 /**
  * A {@code JsonValue} represents either an {@link JsonArray array}, an
  * {@link JsonObject object} or a {@link JsonAtom primitive value} (atom)
- * of a JSON document. 
+ * of a JSON document.
  */
 public abstract class JsonValue {
     public enum Type {
@@ -274,6 +277,25 @@ public abstract class JsonValue {
             this.type = type;
         }
 
+        public static JsonAtom string(String value) {
+            return new JsonAtom(value, Type.STRING);
+        }
+        
+        public static JsonAtom number(double value) {
+            if (Double.isNaN(value) || Double.isInfinite(value)) {
+                throw new IllegalArgumentException(Double.toString(value));
+            }
+            return new JsonAtom(Double.toString(value), Type.NUMBER);
+        }
+        
+        public static JsonAtom number(long value) {
+            return new JsonAtom(Long.toString(value), Type.NUMBER);
+        }
+        
+        public static JsonAtom number(BigDecimal value) {
+            return new JsonAtom(value.toString(), Type.NUMBER);
+        }
+
         /**
          * Create a new {@code JsonAtom} from {@code token}.
          * @param token
@@ -325,7 +347,7 @@ public abstract class JsonValue {
             }
         }
 
-        //------------------------------------------< private >--- 
+        //------------------------------------------< private >---
 
         private static JsonValue.Type valueType(Token.Type type) {
             switch (type) {
@@ -349,13 +371,17 @@ public abstract class JsonValue {
      */
     public static class JsonArray extends JsonValue {
         public static JsonArray EMPTY = new JsonArray(Collections.<JsonValue>emptyList());
-
+        
         private final List<JsonValue> values;
 
         public JsonArray(List<JsonValue> values) {
             this.values = values;
         }
 
+        public JsonArray() {
+            this(new ArrayList<JsonValue>());
+        }
+
         /**
          * Append {@code value} to the end of this array.
          * @param value
@@ -428,7 +454,7 @@ public abstract class JsonValue {
      * This class represents JSON objects.
      */
     public static class JsonObject extends JsonValue {
-        public static JsonObject EMPTY = new JsonObject(Collections.<String, JsonValue>emptyMap());
+        public static final JsonObject EMPTY = new JsonObject(Collections.<String, JsonValue>emptyMap());
 
         private final Map<String, JsonValue> values;
 
@@ -436,6 +462,10 @@ public abstract class JsonValue {
             this.values = values;
         }
 
+        public JsonObject() {
+            this(new HashMap<String, JsonValue>());
+        }
+
         /**
          * Put {@code value} into this object
          * @param key
@@ -454,6 +484,16 @@ public abstract class JsonValue {
             return values.get(key);
         }
 
+        /**
+         * Remove {@code key} from this object
+         * @param key
+         * @return  the {@code JsonValue} identified by {@code key} or {@code null}
+         * if no value exists for {@code key}.
+         */
+        public JsonValue remove(String key) {
+            return values.remove(key);
+        }
+
         public boolean isEmpty() {
             return values.isEmpty();
         }



Mime
View raw message