jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1134216 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk: MicroKernelImpl.java mem/JsopBuilder.java mem/NodeImpl.java
Date Fri, 10 Jun 2011 07:38:46 GMT
Author: thomasm
Date: Fri Jun 10 07:38:46 2011
New Revision: 1134216

URL: http://svn.apache.org/viewvc?rev=1134216&view=rev
Log:
Simplify JSOP builder.

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/JsopBuilder.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java?rev=1134216&r1=1134215&r2=1134216&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
Fri Jun 10 07:38:46 2011
@@ -464,7 +464,7 @@ public class MicroKernelImpl implements 
                 if (o instanceof String) {
                     o = JsopTokenizer.encode(o.toString());
                 }
-                buff.addValue(o.toString());
+                buff.value(o.toString());
             }
             buff.endArray();
             return buff.toString();

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/JsopBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/JsopBuilder.java?rev=1134216&r1=1134215&r2=1134216&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/JsopBuilder.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/JsopBuilder.java
Fri Jun 10 07:38:46 2011
@@ -16,57 +16,56 @@
  */
 package org.apache.jackrabbit.mk.mem;
 
-import java.util.BitSet;
-
 public class JsopBuilder {
 
     private StringBuilder buff = new StringBuilder();
-    private BitSet commas = new BitSet();
-    private int level;
+    private boolean needComma;
 
     public void beginObject() {
+        optionalComma();
         buff.append('{');
-        commas.clear(level++);
+        needComma = false;
     }
 
     public void endObject() {
         if (Constants.JSON_NEWLINES) {
             buff.append("\n}");
         } else {
-            buff.append("}");
+            buff.append('}');
         }
-        commas.clear(level--);
+        needComma = false;
     }
 
     public void beginArray() {
+        optionalComma();
         buff.append('[');
-        commas.clear(level++);
+        needComma = false;
     }
 
     public void endArray() {
         buff.append("]");
-        commas.clear(level--);
+        needComma = true;
     }
 
-    public void addValue(String encodedValue) {
-        if (commas.get(level)) {
-            buff.append(',');
-        } else {
-            commas.set(level);
-        }
+    public void value(String encodedValue) {
+        optionalComma();
         buff.append(encodedValue);
+        needComma = true;
     }
 
-    public void addProperty(String propertyName, String encodedValue) {
-        if (commas.get(level)) {
-            buff.append(',');
-        } else {
-            commas.set(level);
-        }
+    public void property(String propertyName, String encodedValue) {
+        optionalComma();
         if (Constants.JSON_NEWLINES) {
             buff.append('\n');
         }
         buff.append(JsopTokenizer.encode(propertyName)).append(':').append(encodedValue);
+        needComma = true;
+    }
+
+    private void optionalComma() {
+        if (needComma) {
+            buff.append(',');
+        }
     }
 
     public String toString() {

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java?rev=1134216&r1=1134215&r2=1134216&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
Fri Jun 10 07:38:46 2011
@@ -148,20 +148,20 @@ public class NodeImpl {
             json.beginObject();
             if (properties != null) {
                 for (Entry<String, Val> e : properties.entrySet()) {
-                    json.addProperty(e.getKey(), e.getValue().toString());
+                    json.property(e.getKey(), e.getValue().toString());
                 }
             }
         }
         if (childNodes != null) {
-            json.addProperty(":childNodeCount", "" + childNodes.size());
+            json.property(":childNodeCount", "" + childNodes.size());
             if (depth > 0) {
                 for (Entry<String, NodeImpl> e : childNodes.entrySet()) {
-                    json.addProperty(e.getKey(), e.getValue().toString(true, depth - 1, -1,
-1));
+                    json.property(e.getKey(), e.getValue().toString(true, depth - 1, -1,
-1));
                 }
             }
         } else {
             if (Constants.CHILD_NODE_COUNT_0) {
-                json.addProperty(":childNodeCount", "0");
+                json.property(":childNodeCount", "0");
             }
         }
         if (includeProperties) {



Mime
View raw message