Ejemplo n.º 1
0
 /**
  * Returns a string version of this array. The arrays that have been accounted for so far are
  * stored in arrays, to prevent recursion. Subclasses may override this method if a more efficient
  * or concise string can be generated.
  *
  * @param arrays The values accounted for so far
  * @param t
  * @return
  */
 protected String getString(Stack<CArray> arrays, Target t) {
   StringBuilder b = new StringBuilder();
   b.append("{");
   if (!inAssociativeMode()) {
     for (int i = 0; i < this.size(); i++) {
       Mixed value = this.get(i, t);
       String v;
       if (value instanceof CArray) {
         if (arrays.contains((CArray) value)) {
           // Check for recursion
           v = "*recursion*";
         } else {
           arrays.add(((CArray) value));
           v = ((CArray) value).getString(arrays, t);
           arrays.pop();
         }
       } else {
         v = value.val();
       }
       if (i > 0) {
         b.append(", ");
       }
       b.append(v);
     }
   } else {
     boolean first = true;
     for (String key : this.stringKeySet()) {
       if (!first) {
         b.append(", ");
       }
       first = false;
       String v;
       if (this.get(key, t) == null) {
         v = "null";
       } else {
         Mixed value = this.get(key, t);
         if (value instanceof CArray) {
           if (arrays.contains(((CArray) value))) {
             v = "*recursion*";
           } else {
             arrays.add(((CArray) value));
             v = ((CArray) value).getString(arrays, t);
           }
         } else {
           v = value.val();
         }
       }
       b.append(key).append(": ").append(v);
     }
   }
   b.append("}");
   String ret = b.toString();
   return ret;
 }
Ejemplo n.º 2
0
 private String getString(Set<CArray> arrays) {
   StringBuilder b = new StringBuilder();
   b.append("{");
   if (!associative_mode) {
     for (int i = 0; i < array.size(); i++) {
       Mixed value = array.get(i);
       String v;
       if (value instanceof CArray) {
         if (arrays.contains((CArray) value)) {
           // Check for recursion
           v = "*recursion*";
         } else {
           arrays.add(((CArray) value));
           v = ((CArray) value).getString(arrays);
         }
       } else {
         v = value.val();
       }
       if (i > 0) {
         b.append(", ");
       }
       b.append(v);
     }
   } else {
     boolean first = true;
     for (String key : associative_array.keySet()) {
       if (!first) {
         b.append(", ");
       }
       first = false;
       String v;
       if (associative_array.get(key) == null) {
         v = "null";
       } else {
         Mixed value = associative_array.get(key);
         if (value instanceof CArray) {
           if (arrays.contains(((CArray) value))) {
             v = "*recursion*";
           } else {
             arrays.add(((CArray) value));
             v = ((CArray) value).getString(arrays);
           }
         } else {
           v = value.val();
         }
       }
       b.append(key).append(": ").append(v);
     }
   }
   b.append("}");
   String ret = b.toString();
   return ret;
 }