Example #1
0
 /**
  * @param index
  * @param c
  */
 public void set(Construct index, Construct c, Target t) {
   if (!associative_mode) {
     try {
       int indx = Static.getInt32(index, t);
       if (indx > next_index || indx < 0) {
         throw ConfigRuntimeException.BuildException(
             "", ExceptionType.IndexOverflowException, Target.UNKNOWN);
       } else if (indx == next_index) {
         this.push(c, t);
       } else {
         array.set(indx, c);
       }
     } catch (ConfigRuntimeException e) {
       // Not a number. Convert to associative.
       associative_array = new TreeMap<String, Construct>(comparator);
       for (int i = 0; i < array.size(); i++) {
         associative_array.put(Integer.toString(i), array.get(i));
       }
       associative_mode = true;
       array = null; // null out the original array container so it can be GC'd
     }
   }
   if (associative_mode) {
     associative_array.put(normalizeConstruct(index), c);
   }
   if (c instanceof CArray) {
     ((CArray) c).parent = this;
   }
   regenValue(new HashSet<CArray>());
 }
Example #2
0
 @Override
 public Construct get(Construct index, Target t) {
   if (!associative_mode) {
     try {
       return array.get(Static.getInt32(index, t));
     } catch (IndexOutOfBoundsException e) {
       throw ConfigRuntimeException.BuildException(
           "The element at index \"" + index.val() + "\" does not exist",
           ExceptionType.IndexOverflowException,
           t,
           e);
     }
   } else {
     if (associative_array.containsKey(normalizeConstruct(index))) {
       Construct val = associative_array.get(normalizeConstruct(index));
       if (val instanceof CEntry) {
         return ((CEntry) val).construct();
       }
       return val;
     } else {
       // Create this so we can at least attach a stacktrace.
       @SuppressWarnings({"ThrowableInstanceNotThrown", "ThrowableInstanceNeverThrown"})
       IndexOutOfBoundsException ioobe = new IndexOutOfBoundsException();
       throw ConfigRuntimeException.BuildException(
           "The element at index \"" + index.val() + "\" does not exist",
           ExceptionType.IndexOverflowException,
           t,
           ioobe);
     }
   }
 }
Example #3
0
 public Construct get(Construct index, Target t) {
   if (!associative_mode) {
     try {
       return array.get(Static.getInt32(index, t));
     } catch (IndexOutOfBoundsException e) {
       throw new ConfigRuntimeException(
           "The element at index \"" + index.val() + "\" does not exist",
           ExceptionType.IndexOverflowException,
           t);
     }
   } else {
     if (associative_array.containsKey(normalizeConstruct(index))) {
       Construct val = associative_array.get(normalizeConstruct(index));
       if (val instanceof CEntry) {
         return ((CEntry) val).construct();
       }
       return val;
     } else {
       throw new ConfigRuntimeException(
           "The element at index \"" + index.val() + "\" does not exist",
           ExceptionType.IndexOverflowException,
           t);
     }
   }
 }