Java Code Examples for org.bson.BsonArray#size()
The following examples show how to use
org.bson.BsonArray#size() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChronoVertex.java From epcis with Apache License 2.0 | 6 votes |
private Stream<ChronoVertex> getOutChronoVertexStream(BsonArray labels, final int branchFactor, final boolean setParallel) { HashSet<ChronoVertex> vertexSet = new HashSet<ChronoVertex>(); BsonDocument filter = new BsonDocument(); BsonDocument inner = new BsonDocument(); filter.put(Tokens.OUT_VERTEX, new BsonString(this.toString())); if (labels != null && labels.size() != 0) { inner.put(Tokens.FC.$in.toString(), labels); filter.put(Tokens.LABEL, inner); } Iterator<BsonDocument> it = null; if (branchFactor == Integer.MAX_VALUE) it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).iterator(); else it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).limit(branchFactor).iterator(); while (it.hasNext()) { BsonDocument d = it.next(); vertexSet.add(new ChronoVertex(d.getString(Tokens.ID).getValue().split("\\|")[2], this.graph)); } if (setParallel) return vertexSet.parallelStream(); else return vertexSet.stream(); }
Example 2
Source File: ChronoVertex.java From epcis with Apache License 2.0 | 6 votes |
private Set<ChronoVertex> getInChronoVertexSet(BsonArray labels, final int branchFactor) { HashSet<ChronoVertex> vertexSet = new HashSet<ChronoVertex>(); BsonDocument filter = new BsonDocument(); BsonDocument inner = new BsonDocument(); filter.put(Tokens.IN_VERTEX, new BsonString(this.toString())); if (labels != null && labels.size() != 0) { inner.put(Tokens.FC.$in.toString(), labels); filter.put(Tokens.LABEL, inner); } Iterator<BsonDocument> it = null; if (branchFactor == Integer.MAX_VALUE) it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).iterator(); else it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).limit(branchFactor).iterator(); while (it.hasNext()) { BsonDocument d = it.next(); vertexSet.add(new ChronoVertex(d.getString(Tokens.ID).getValue().split("\\|")[0], this.graph)); } return vertexSet; }
Example 3
Source File: ChronoVertex.java From epcis with Apache License 2.0 | 6 votes |
private Stream<ChronoVertex> getInChronoVertexStream(final BsonArray labels, final int branchFactor, final boolean setParallel) { HashSet<ChronoVertex> vertexSet = new HashSet<ChronoVertex>(); BsonDocument filter = new BsonDocument(); BsonDocument inner = new BsonDocument(); filter.put(Tokens.IN_VERTEX, new BsonString(this.toString())); if (labels != null && labels.size() != 0) { inner.put(Tokens.FC.$in.toString(), labels); filter.put(Tokens.LABEL, inner); } Iterator<BsonDocument> it = null; if (branchFactor == Integer.MAX_VALUE) it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).iterator(); else it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).limit(branchFactor).iterator(); while (it.hasNext()) { BsonDocument d = it.next(); vertexSet.add(new ChronoVertex(d.getString(Tokens.ID).getValue().split("\\|")[0], this.graph)); } if (setParallel) return vertexSet.parallelStream(); else return vertexSet.stream(); }
Example 4
Source File: ChronoVertex.java From epcis with Apache License 2.0 | 6 votes |
private Iterable<ChronoVertex> getOutChronoVertices(BsonArray labels, final int branchFactor) { HashSet<ChronoVertex> vertexSet = new HashSet<ChronoVertex>(); BsonDocument filter = new BsonDocument(); BsonDocument inner = new BsonDocument(); filter.put(Tokens.OUT_VERTEX, new BsonString(this.toString())); if (labels != null && labels.size() != 0) { inner.put(Tokens.FC.$in.toString(), labels); filter.put(Tokens.LABEL, inner); } Iterator<BsonDocument> it = null; if (branchFactor == Integer.MAX_VALUE) it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).iterator(); else it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).limit(branchFactor).iterator(); while (it.hasNext()) { BsonDocument d = it.next(); vertexSet.add(new ChronoVertex(d.getString(Tokens.ID).getValue().split("\\|")[2], this.graph)); } return vertexSet; }
Example 5
Source File: MongoQueryUtil.java From epcis with Apache License 2.0 | 6 votes |
static BsonDocument getFamilyQueryObject(String type, String[] fieldArr, String csv) { BsonArray orQueries = new BsonArray(); for (String field : fieldArr) { String[] paramValueArr = csv.split("\\|"); BsonArray subObjectList = new BsonArray(); for (int i = 0; i < paramValueArr.length; i++) { String val = paramValueArr[i].trim(); BsonDocument dbo = new BsonDocument(); dbo.put(type, new BsonString(val)); subObjectList.add(dbo); } if (subObjectList.isEmpty() == false) { BsonDocument query = new BsonDocument(); query.put(field, new BsonDocument("$in", subObjectList)); orQueries.add(query); } } if (orQueries.size() != 0) { BsonDocument queryObject = new BsonDocument(); queryObject.put("$or", orQueries); return queryObject; } else { return null; } }
Example 6
Source File: ChronoVertex.java From epcis with Apache License 2.0 | 6 votes |
private Set<ChronoEdge> getOutChronoEdgeSet(final BsonArray labels, final int branchFactor) { HashSet<ChronoEdge> edgeSet = new HashSet<ChronoEdge>(); BsonDocument filter = new BsonDocument(); BsonDocument inner = new BsonDocument(); filter.put(Tokens.OUT_VERTEX, new BsonString(this.toString())); if (labels != null && labels.size() != 0) { inner.put(Tokens.FC.$in.toString(), labels); filter.put(Tokens.LABEL, inner); } Iterator<BsonDocument> it = null; if (branchFactor == Integer.MAX_VALUE) it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).iterator(); else it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).limit(branchFactor).iterator(); while (it.hasNext()) { BsonDocument d = it.next(); edgeSet.add(new ChronoEdge(d.getString(Tokens.ID).getValue(), this.graph)); } return edgeSet; }
Example 7
Source File: MongoQueryUtil.java From epcis with Apache License 2.0 | 6 votes |
static BsonDocument getExistsQueryObject(String[] fieldArr, String str, BsonBoolean isExist) { BsonArray conjQueries = new BsonArray(); for (String field : fieldArr) { BsonDocument query = new BsonDocument(); if (str != null) { str = encodeMongoObjectKey(str); query.put(field + "." + str, new BsonDocument("$exists", isExist)); } else { query.put(field, new BsonDocument("$exists", isExist)); } conjQueries.add(query); } if (conjQueries.size() != 0) { BsonDocument queryObject = new BsonDocument(); if (isExist.equals(BsonBoolean.TRUE)) queryObject.put("$or", conjQueries); else { queryObject.put("$and", conjQueries); } return queryObject; } else { return null; } }
Example 8
Source File: ChronoVertex.java From epcis with Apache License 2.0 | 6 votes |
private Stream<ChronoEdge> getInChronoEdgeStream(final BsonArray labels, final int branchFactor, final boolean setParallel) { HashSet<ChronoEdge> edgeSet = new HashSet<ChronoEdge>(); BsonDocument filter = new BsonDocument(); BsonDocument inner = new BsonDocument(); filter.put(Tokens.IN_VERTEX, new BsonString(this.toString())); if (labels != null && labels.size() != 0) { inner.put(Tokens.FC.$in.toString(), labels); filter.put(Tokens.LABEL, inner); } Iterator<BsonDocument> it = null; if (branchFactor == Integer.MAX_VALUE) it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).iterator(); else it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).limit(branchFactor).iterator(); while (it.hasNext()) { BsonDocument d = it.next(); edgeSet.add(new ChronoEdge(d.getString(Tokens.ID).getValue(), this.graph)); } if (setParallel) return edgeSet.parallelStream(); else return edgeSet.stream(); }
Example 9
Source File: ChronoVertex.java From epcis with Apache License 2.0 | 6 votes |
/** * Return in-going edges (Internal Method) * * @param labels * @return in-going edges */ private Iterable<ChronoEdge> getInChronoEdges(final BsonArray labels, final int branchFactor) { HashSet<ChronoEdge> edgeSet = new HashSet<ChronoEdge>(); BsonDocument filter = new BsonDocument(); BsonDocument inner = new BsonDocument(); filter.put(Tokens.IN_VERTEX, new BsonString(this.toString())); if (labels != null && labels.size() != 0) { inner.put(Tokens.FC.$in.toString(), labels); filter.put(Tokens.LABEL, inner); } Iterator<BsonDocument> it = null; if (branchFactor == Integer.MAX_VALUE) it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).iterator(); else it = graph.getEdgeCollection().find(filter).projection(Tokens.PRJ_ONLY_ID).limit(branchFactor).iterator(); while (it.hasNext()) { BsonDocument d = it.next(); edgeSet.add(new ChronoEdge(d.getString(Tokens.ID).getValue(), this.graph)); } return edgeSet; }
Example 10
Source File: MongoQueryUtil.java From epcis with Apache License 2.0 | 6 votes |
static BsonDocument getFamilyQueryObject(String type, String[] fieldArr, String csv) { BsonArray orQueries = new BsonArray(); for (String field : fieldArr) { String[] paramValueArr = csv.split("\\|"); BsonArray subObjectList = new BsonArray(); for (int i = 0; i < paramValueArr.length; i++) { String val = paramValueArr[i].trim(); BsonDocument dbo = new BsonDocument(); dbo.put(type, new BsonString(val)); subObjectList.add(dbo); } if (subObjectList.isEmpty() == false) { BsonDocument query = new BsonDocument(); query.put(field, new BsonDocument("$in", subObjectList)); orQueries.add(query); } } if (orQueries.size() != 0) { BsonDocument queryObject = new BsonDocument(); queryObject.put("$or", orQueries); return queryObject; } else { return null; } }
Example 11
Source File: DataSynchronizer.java From stitch-android-sdk with Apache License 2.0 | 5 votes |
private Set<BsonDocument> getLatestDocumentsForStaleFromRemote( final NamespaceSynchronizationConfig nsConfig, final Set<BsonValue> staleIds) { final BsonArray ids = new BsonArray(); Collections.addAll(ids, staleIds.toArray(new BsonValue[0])); if (ids.size() == 0) { return new HashSet<>(); } return this.getRemoteCollection(nsConfig.getNamespace()).find( new BsonDocument("_id", new BsonDocument("$in", ids)) ).into(new HashSet<>()); }
Example 12
Source File: MongoQueryService.java From epcis with Apache License 2.0 | 5 votes |
private boolean isExtensionFilterPassed(String type, BsonArray paramArray, BsonDocument ext, boolean isTopLevel) { type = MongoWriterUtil.encodeMongoObjectKey(type); Iterator<String> keyIterator = ext.keySet().iterator(); while (keyIterator.hasNext()) { String key = keyIterator.next(); BsonValue sub = ext.get(key); if (isTopLevel == false) { if (key.equals(type)) { for (int i = 0; i < paramArray.size(); i++) { BsonValue param = paramArray.get(i); if (sub.getBsonType() == param.getBsonType() && sub.toString().equals(param.toString())) { return true; } if (param.getBsonType() == BsonType.REGULAR_EXPRESSION && sub.getBsonType() == BsonType.STRING) { if (Pattern.matches(param.asRegularExpression().getPattern(), sub.asString().getValue())) return true; } } return false; } } if (sub.getBsonType() == BsonType.DOCUMENT) { if (isExtensionFilterPassed(type, paramArray, sub.asDocument(), false) == true) { return true; } } } return false; }
Example 13
Source File: MongoQueryUtil.java From epcis with Apache License 2.0 | 5 votes |
static BsonDocument getQueryObject(String[] fieldArr, BsonArray paramArray) { BsonArray orQueries = new BsonArray(); for (String field : fieldArr) { Iterator<BsonValue> paramIterator = paramArray.iterator(); BsonArray pureStringParamArray = new BsonArray(); while (paramIterator.hasNext()) { BsonValue param = paramIterator.next(); if (param instanceof BsonRegularExpression) { BsonDocument regexQuery = new BsonDocument(field, new BsonDocument("$regex", param)); orQueries.add(regexQuery); } else { pureStringParamArray.add(param); } } if (pureStringParamArray.size() != 0) { BsonDocument stringInQueries = new BsonDocument(field, new BsonDocument("$in", pureStringParamArray)); orQueries.add(stringInQueries); } } if (orQueries.size() != 0) { BsonDocument queryObject = new BsonDocument(); queryObject.put("$or", orQueries); return queryObject; } else { return null; } }
Example 14
Source File: MongoQueryService.java From epcis with Apache License 2.0 | 5 votes |
private boolean isExtensionFilterPassed(String type, BsonArray paramArray, BsonDocument ext, boolean isTopLevel) { type = MongoWriterUtil.encodeMongoObjectKey(type); Iterator<String> keyIterator = ext.keySet().iterator(); while (keyIterator.hasNext()) { String key = keyIterator.next(); BsonValue sub = ext.get(key); if (isTopLevel == false) { if (key.equals(type)) { for (int i = 0; i < paramArray.size(); i++) { BsonValue param = paramArray.get(i); if (sub.getBsonType() == param.getBsonType() && sub.toString().equals(param.toString())) { return true; } if (param.getBsonType() == BsonType.REGULAR_EXPRESSION && sub.getBsonType() == BsonType.STRING) { if (Pattern.matches(param.asRegularExpression().getPattern(), sub.asString().getValue())) return true; } } return false; } } if (sub.getBsonType() == BsonType.DOCUMENT) { if (isExtensionFilterPassed(type, paramArray, sub.asDocument(), false) == true) { return true; } } } return false; }
Example 15
Source File: MongoWriterUtil.java From epcis with Apache License 2.0 | 5 votes |
static BsonDocument getErrorDeclaration(ErrorDeclarationType edt) { BsonDocument errorBson = new BsonDocument(); long declarationTime = edt.getDeclarationTime().toGregorianCalendar().getTimeInMillis(); errorBson.put("declarationTime", new BsonDateTime(declarationTime)); // (Optional) reason if (edt.getReason() != null) { errorBson.put("reason", new BsonString(edt.getReason())); } // (Optional) correctiveEventIDs if (edt.getCorrectiveEventIDs() != null) { CorrectiveEventIDsType cIDs = edt.getCorrectiveEventIDs(); List<String> cIDStringList = cIDs.getCorrectiveEventID(); BsonArray correctiveIDBsonArray = new BsonArray(); for (String cIDString : cIDStringList) { correctiveIDBsonArray.add(new BsonString(cIDString)); } if (correctiveIDBsonArray.size() != 0) { errorBson.put("correctiveEventIDs", correctiveIDBsonArray); } } if (edt.getAny() != null) { BsonDocument map2Save = getAnyMap(edt.getAny()); if (map2Save != null && map2Save.isEmpty() == false) { errorBson.put("any", map2Save); } } return errorBson; }
Example 16
Source File: MongoReaderUtil.java From epcis with Apache License 2.0 | 5 votes |
static List<QuantityElementType> putQuantityElementTypeList(BsonArray quantityDBList) { List<QuantityElementType> qetList = new ArrayList<QuantityElementType>(); for (int i = 0; i < quantityDBList.size(); i++) { QuantityElementType qet = new QuantityElementType(); BsonDocument quantityDBObject = quantityDBList.get(i).asDocument(); BsonValue epcClassObject = quantityDBObject.get("epcClass"); BsonValue quantity = quantityDBObject.get("quantity"); BsonValue uom = quantityDBObject.get("uom"); if (epcClassObject != null) { qet.setEpcClass(epcClassObject.asString().getValue()); if (quantity != null) { double quantityDouble = quantity.asDouble().getValue(); qet.setQuantity(BigDecimal.valueOf(quantityDouble)); } if (uom != null) qet.setUom(uom.asString().getValue()); qetList.add(qet); } } return qetList; }
Example 17
Source File: UpdateDescription.java From stitch-android-sdk with Apache License 2.0 | 5 votes |
/** * Converts an update description BSON document from a MongoDB Change Event into an * UpdateDescription object. * * @param document the * @return the converted UpdateDescription */ public static UpdateDescription fromBsonDocument(final BsonDocument document) { keyPresent(Fields.UPDATED_FIELDS_FIELD, document); keyPresent(Fields.REMOVED_FIELDS_FIELD, document); final BsonArray removedFieldsArr = document.getArray(Fields.REMOVED_FIELDS_FIELD); final Set<String> removedFields = new HashSet<>(removedFieldsArr.size()); for (final BsonValue field : removedFieldsArr) { removedFields.add(field.asString().getValue()); } return new UpdateDescription(document.getDocument(Fields.UPDATED_FIELDS_FIELD), removedFields); }
Example 18
Source File: ResultDecoders.java From stitch-android-sdk with Apache License 2.0 | 5 votes |
public RemoteInsertManyResult decode( final BsonReader reader, final DecoderContext decoderContext ) { final BsonDocument document = (new BsonDocumentCodec()).decode(reader, decoderContext); keyPresent(Fields.INSERTED_IDS_FIELD, document); final BsonArray arr = document.getArray(Fields.INSERTED_IDS_FIELD); final Map<Long, BsonValue> insertedIds = new HashMap<>(); for (int i = 0; i < arr.size(); i++) { insertedIds.put((long) i, arr.get(i)); } return new RemoteInsertManyResult(insertedIds); }
Example 19
Source File: MongoQueryService.java From epcis with Apache License 2.0 | 4 votes |
private boolean isCompExtensionFilterPassed(String type, String comp, BsonArray paramArray, BsonDocument ext) { type = MongoWriterUtil.encodeMongoObjectKey(type); Iterator<String> keyIterator = ext.keySet().iterator(); while (keyIterator.hasNext()) { String key = keyIterator.next(); BsonValue sub = ext.get(key); if (key.equals(type)) { for (int i = 0; i < paramArray.size(); i++) { BsonValue param = paramArray.get(i); if (sub.getBsonType() == param.getBsonType()) { if (sub.getBsonType() == BsonType.INT32) { if (comp.equals("GT")) { if (sub.asInt32().getValue() > param.asInt32().getValue()) return true; } else if (comp.equals("GE")) { if (sub.asInt32().getValue() >= param.asInt32().getValue()) return true; } else if (comp.equals("LT")) { if (sub.asInt32().getValue() < param.asInt32().getValue()) return true; } else if (comp.equals("LE")) { if (sub.asInt32().getValue() <= param.asInt32().getValue()) return true; } } else if (sub.getBsonType() == BsonType.INT64) { if (comp.equals("GT")) { if (sub.asInt64().getValue() > param.asInt64().getValue()) return true; } else if (comp.equals("GE")) { if (sub.asInt64().getValue() >= param.asInt64().getValue()) return true; } else if (comp.equals("LT")) { if (sub.asInt64().getValue() < param.asInt64().getValue()) return true; } else if (comp.equals("LE")) { if (sub.asInt64().getValue() <= param.asInt64().getValue()) return true; } } else if (sub.getBsonType() == BsonType.DOUBLE) { if (comp.equals("GT")) { if (sub.asDouble().getValue() > param.asDouble().getValue()) return true; } else if (comp.equals("GE")) { if (sub.asDouble().getValue() >= param.asDouble().getValue()) return true; } else if (comp.equals("LT")) { if (sub.asDouble().getValue() < param.asDouble().getValue()) return true; } else if (comp.equals("LE")) { if (sub.asDouble().getValue() <= param.asDouble().getValue()) return true; } } else if (sub.getBsonType() == BsonType.DATE_TIME) { if (comp.equals("GT")) { if (sub.asDateTime().getValue() > param.asDateTime().getValue()) return true; } else if (comp.equals("GE")) { if (sub.asDateTime().getValue() >= param.asDateTime().getValue()) return true; } else if (comp.equals("LT")) { if (sub.asDateTime().getValue() < param.asDateTime().getValue()) return true; } else if (comp.equals("LE")) { if (sub.asDateTime().getValue() <= param.asDateTime().getValue()) return true; } } } } return false; } if (sub.getBsonType() == BsonType.DOCUMENT) { if (isCompExtensionFilterPassed(type, comp, paramArray, sub.asDocument()) == true) { return true; } } } return false; }
Example 20
Source File: MongoQueryService.java From epcis with Apache License 2.0 | 4 votes |
private boolean isCompExtensionFilterPassed(String type, String comp, BsonArray paramArray, BsonDocument ext) { type = MongoWriterUtil.encodeMongoObjectKey(type); Iterator<String> keyIterator = ext.keySet().iterator(); while (keyIterator.hasNext()) { String key = keyIterator.next(); BsonValue sub = ext.get(key); if (key.equals(type)) { for (int i = 0; i < paramArray.size(); i++) { BsonValue param = paramArray.get(i); if (sub.getBsonType() == param.getBsonType()) { if (sub.getBsonType() == BsonType.INT32) { if (comp.equals("GT")) { if (sub.asInt32().getValue() > param.asInt32().getValue()) return true; } else if (comp.equals("GE")) { if (sub.asInt32().getValue() >= param.asInt32().getValue()) return true; } else if (comp.equals("LT")) { if (sub.asInt32().getValue() < param.asInt32().getValue()) return true; } else if (comp.equals("LE")) { if (sub.asInt32().getValue() <= param.asInt32().getValue()) return true; } } else if (sub.getBsonType() == BsonType.INT64) { if (comp.equals("GT")) { if (sub.asInt64().getValue() > param.asInt64().getValue()) return true; } else if (comp.equals("GE")) { if (sub.asInt64().getValue() >= param.asInt64().getValue()) return true; } else if (comp.equals("LT")) { if (sub.asInt64().getValue() < param.asInt64().getValue()) return true; } else if (comp.equals("LE")) { if (sub.asInt64().getValue() <= param.asInt64().getValue()) return true; } } else if (sub.getBsonType() == BsonType.DOUBLE) { if (comp.equals("GT")) { if (sub.asDouble().getValue() > param.asDouble().getValue()) return true; } else if (comp.equals("GE")) { if (sub.asDouble().getValue() >= param.asDouble().getValue()) return true; } else if (comp.equals("LT")) { if (sub.asDouble().getValue() < param.asDouble().getValue()) return true; } else if (comp.equals("LE")) { if (sub.asDouble().getValue() <= param.asDouble().getValue()) return true; } } else if (sub.getBsonType() == BsonType.DATE_TIME) { if (comp.equals("GT")) { if (sub.asDateTime().getValue() > param.asDateTime().getValue()) return true; } else if (comp.equals("GE")) { if (sub.asDateTime().getValue() >= param.asDateTime().getValue()) return true; } else if (comp.equals("LT")) { if (sub.asDateTime().getValue() < param.asDateTime().getValue()) return true; } else if (comp.equals("LE")) { if (sub.asDateTime().getValue() <= param.asDateTime().getValue()) return true; } } } } return false; } if (sub.getBsonType() == BsonType.DOCUMENT) { if (isCompExtensionFilterPassed(type, comp, paramArray, sub.asDocument()) == true) { return true; } } } return false; }