/** * creates an new empty object and adds it to the current list. The new child object becomes the * active one. * * @return returns itself so you can chain */ public BasicDBObjectBuilder addToList() { DBObject list = _cur(); if (!(list instanceof BasicDBList)) { throw new IllegalStateException("addToList without pushList"); } BasicDBObject o = new BasicDBObject(); ((BasicDBList) list).add(o); _stack.addLast(o); return this; } /** * adds the given val to the current list. The passed value does NOT become the new active * object even if it's a DBObject * * @param val the value to be added to the list * @return returns itself so you can chain */ public BasicDBObjectBuilder addToList(Object val) { DBObject list = _cur(); if (!(list instanceof BasicDBList)) { throw new IllegalStateException("addToList without pushList"); } ((BasicDBList) list).add(val); return this; } /** * creates an new empty list and inserts it into the current object with the given key. The new * list becomes the active one. You can use either {@link #push(String)}, * {@link #pushList(String)}, {@link #addToList()} or {@link #addToList(Object)} to add elements * to the list. When using {@link #push(String)} or {@link #pushList(String)} the key is the * index of the value to be inserted. For instance push("3") would add the new object at the 4th * position in the list. * * @param key * @return returns itself so you can chain */ public BasicDBObjectBuilder pushList(String key) { BasicDBList list = new BasicDBList(); _cur().put(key, list); _stack.addLast(list); return this; }