/** * Puts a value at an index. This will fill any unset indexes less than {@code index} with {@code null}. * * @param key the index at which to insert the value * @param value the value to insert * @return the value */ public Object put(final int key, final Object value) { while (key >= size()) { add(null); } set(key, value); return value; }
public BSONObject getBSONObject() { BSONObject obj = new BasicBSONObject(); BasicBSONList list = new BasicBSONList(); list.add(REQUEST_TYPE); list.add(this.requestId); list.add(this.methodName); BasicBSONList paramList = new BasicBSONList(); paramList.addAll(Arrays.asList(parameters)); list.add(paramList); obj.put("data", list); obj.put("return", this.responseQueue); return obj; }
/** * Adds a new member to the replica set config with the given hostname, port and id. Doesn't attempt to check * that the id is free. */ public ReplicaSetConfig member(String hostname, Integer port, Integer id) { BasicBSONObject member = new BasicBSONObject(); member.put("_id", id); member.put("host", String.format("%s:%s", hostname, port)); members.add(member); return this; }
/** * Puts a value at an index. This will fill any unset indexes less than * <code>index</code> with <code>null</code>. * * @param key * the index at which to insert the value * @param v * the value to insert * @return the value */ public Object put(int key, Object v) { while (key >= size()) add(null); set(key, v); return v; }
private DBObject capabilitiesToObject(RobotCapabilities capabilities) { if (capabilities == null) { return null; } BasicDBObject capabilitiesObj = new BasicDBObject(); for (Capability capability : capabilities.getCapabilitiesMap().values()) { BasicBSONList contexts = new BasicBSONList(); for (Context c : capability.getContexts()) { contexts.add(c.name()); } capabilitiesObj.put(capability.getEventType().name(), new BasicDBObject() .append(CAPABILITY_CONTEXTS_FIELD, contexts) .append(CAPABILITY_FILTER_FIELD, capability.getFilter())); } BasicDBObject object = new BasicDBObject() .append(CAPABILITIES_CAPABILITIES_FIELD, capabilitiesObj) .append(CAPABILITIES_HASH_FIELD, capabilities.getCapabilitiesHash()) .append(CAPABILITIES_VERSION_FIELD, capabilities.getProtocolVersion().name()); return object; }
BasicBSONList newValues = new BasicBSONList(); for (Object v : values) { newValues.add(createMongoData(v));