/** Delete an object from this variable at a position. */ @Override public void removeAt(Variable index) throws ScriptException { if (index == null) throw new ScriptException(composeMessage("Remove index cannot be null")); int indexValue = index.getIntValue(); if (indexValue < 0 || indexValue >= configurationNode.getChildCount()) throw new ScriptException(composeMessage("Remove index out of bounds: " + indexValue)); configurationNode.removeChild(indexValue); }
/** Get an indexed property of the variable */ @Override public VariableReference getIndexed(Variable index) throws ScriptException { if (index == null) throw new ScriptException(composeMessage("Subscript cannot be null")); int indexValue = index.getIntValue(); if (indexValue >= 0 && indexValue < configurationNode.getChildCount()) return new NodeReference(indexValue); throw new ScriptException(composeMessage("Subscript is out of bounds: " + indexValue)); }
/** Insert an object into this variable at a position. */ @Override public void insertAt(Variable v, Variable index) throws ScriptException { if (v == null) throw new ScriptException(composeMessage("Can't insert a null object")); if (index == null) configurationNode.addChild(configurationNode.getChildCount(), v.getConfigurationNodeValue()); else { int indexValue = index.getIntValue(); if (indexValue < 0 || indexValue > configurationNode.getChildCount()) throw new ScriptException(composeMessage("Insert out of bounds: " + indexValue)); configurationNode.addChild(indexValue, v.getConfigurationNodeValue()); } }