本文整理汇总了Java中org.bson.BsonBoolean类的典型用法代码示例。如果您正苦于以下问题:Java BsonBoolean类的具体用法?Java BsonBoolean怎么用?Java BsonBoolean使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BsonBoolean类属于org.bson包,在下文中一共展示了BsonBoolean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBsonDocument
import org.bson.BsonBoolean; //导入依赖的package包/类
public static BsonDocument getBsonDocument() {
BsonDocument bsonObj = new BsonDocument().append("testDouble", new BsonDouble(20.777));
List<BsonDocument> list = new ArrayList<BsonDocument>();
list.add(bsonObj);
list.add(bsonObj);
byte[] bytes = new byte[3];
bytes[0] = 3;
bytes[1] = 2;
bytes[2] = 1;
BsonDocument bsonDocument = new BsonDocument().append("testDouble", new BsonDouble(20.99))
.append("testString", new BsonString("testStringV"))
.append("testArray", new BsonArray(list));
return new BsonDocument().append("testDouble", new BsonDouble(20.99))
.append("testString", new BsonString("testStringV"))
.append("testArray", new BsonArray(list))
.append("bson_test", bsonDocument)
.append("testBinary", new BsonBinary(bytes))
.append("testBsonUndefined", new BsonUndefined())
.append("testObjectId", new BsonObjectId())
.append("testStringObjectId", new BsonObjectId())
.append("testBoolean", new BsonBoolean(true))
.append("testDate", new BsonDateTime(time))
.append("testNull", new BsonNull())
.append("testInt", new BsonInt32(233))
.append("testLong", new BsonInt64(233332));
}
示例2: testBsonDocumentDeSerialize
import org.bson.BsonBoolean; //导入依赖的package包/类
@Test
public void testBsonDocumentDeSerialize() {
BsonDocument document = new BsonDocument().append("a", new BsonString("MongoDB"))
.append("b", new BsonArray(Arrays.asList(new BsonInt32(1), new BsonInt32(2))))
.append("c", new BsonBoolean(true))
.append("d", new BsonDateTime(0));
String json = oson.useAttribute(false).setValueOnly(true).serialize(document);
String expected = "{\"a\":\"MongoDB\",\"b\":[1,2],\"c\":true,\"d\":0}";
assertEquals(expected, json);
BsonDocument document2 = oson.deserialize(json, BsonDocument.class);
assertEquals(expected, oson.serialize(document2));
}
示例3: converseType
import org.bson.BsonBoolean; //导入依赖的package包/类
private static BsonValue converseType(String value) {
String[] valArr = value.split("\\^");
if (valArr.length != 2) {
return new BsonString(value);
}
try {
String type = valArr[1];
if (type.equals("int")) {
return new BsonInt32(Integer.parseInt(valArr[0]));
} else if (type.equals("long")) {
return new BsonInt64(Long.parseLong(valArr[0]));
} else if (type.equals("double")) {
return new BsonDouble(Double.parseDouble(valArr[0]));
} else if (type.equals("boolean")) {
return new BsonBoolean(Boolean.parseBoolean(valArr[0]));
} else {
return new BsonString(value);
}
} catch (NumberFormatException e) {
return new BsonString(value);
}
}
示例4: getExistsQueryObject
import org.bson.BsonBoolean; //导入依赖的package包/类
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;
}
}
示例5: asBsonDocument
import org.bson.BsonBoolean; //导入依赖的package包/类
public static BsonDocument asBsonDocument(SubscriptionType subscription) {
BsonDocument bson = new BsonDocument();
if (subscription.getSubscriptionID() != null) {
bson.put("subscriptionID", new BsonString(subscription.getSubscriptionID()));
}
if (subscription.getDest() != null) {
bson.put("dest", new BsonString(subscription.getDest()));
}
if (subscription.getSchedule() != null) {
bson.put("schedule", new BsonString(subscription.getSchedule()));
}
if (subscription.getTrigger() != null) {
bson.put("trigger", new BsonString(subscription.getTrigger()));
}
if (subscription.getInitialRecordTime() != null) {
bson.put("initialRecordTime", new BsonString(subscription.getInitialRecordTime()));
}
bson.put("reportIfEmpty", new BsonBoolean(subscription.getReportIfEmpty()));
bson.put("pollParameters", PollParameters.asBsonDocument(subscription.getPollParameters()));
return bson;
}
示例6: converseType
import org.bson.BsonBoolean; //导入依赖的package包/类
static BsonValue converseType(String value) {
String[] valArr = value.split("\\^");
if (valArr.length != 2) {
return new BsonString(value);
}
try {
String type = valArr[1];
if (type.equals("int")) {
return new BsonInt32(Integer.parseInt(valArr[0]));
} else if (type.equals("long")) {
return new BsonInt64(Long.parseLong(valArr[0]));
} else if (type.equals("double")) {
return new BsonDouble(Double.parseDouble(valArr[0]));
} else if (type.equals("boolean")) {
return new BsonBoolean(Boolean.parseBoolean(valArr[0]));
} else {
return new BsonString(value);
}
} catch (NumberFormatException e) {
return new BsonString(value);
}
}
示例7: getTimestampProperties
import org.bson.BsonBoolean; //导入依赖的package包/类
/**
* @param timestamp
* @param projection
* @return TimestampProperties BsonDocument only containing projection keys
*/
public BsonDocument getTimestampProperties(final Long timestamp, final String[] projection) {
BsonDocument bsonProjection = new BsonDocument();
if (projection != null) {
for (String string : projection) {
bsonProjection.append(string, new BsonBoolean(true));
}
}
if (this instanceof ChronoVertex)
return graph.getVertexEvents()
.find(new BsonDocument(Tokens.VERTEX, new BsonString(this.id)).append(Tokens.TIMESTAMP, new BsonDateTime(timestamp)))
.projection(bsonProjection).first();
else
return graph.getEdgeCollection()
.find(new BsonDocument(Tokens.ID, new BsonString(this.id + "-" + timestamp)))
.projection(bsonProjection).first();
}
示例8: deserialise_boolean
import org.bson.BsonBoolean; //导入依赖的package包/类
@Test public void
deserialise_boolean() {
Key<Boolean> booleanKey = Key.named("my-value");
BsonRecordDeserialiser deserialiser = BsonRecordDeserialiser.builder()
.readBoolean(booleanKey)
.get();
BsonDocument trueDoc = new BsonDocument();
trueDoc.put("my-value", new BsonBoolean(true));
Record trueRecord = deserialiser.apply(trueDoc);
assertTrue("wasn't true", booleanKey.get(trueRecord).get());
BsonDocument falseDoc = new BsonDocument();
falseDoc.put("my-value", new BsonBoolean(false));
Record falseRecord = Record.of(booleanKey.of(false));
assertFalse("wasn't false", booleanKey.get(falseRecord).get());
}
示例9: bsonToGson
import org.bson.BsonBoolean; //导入依赖的package包/类
/**
* Reading from BSON to GSON
*/
@Test
public void bsonToGson() throws Exception {
BsonDocument document = new BsonDocument();
document.append("boolean", new BsonBoolean(true));
document.append("int32", new BsonInt32(32));
document.append("int64", new BsonInt64(64));
document.append("double", new BsonDouble(42.42D));
document.append("string", new BsonString("foo"));
document.append("null", new BsonNull());
document.append("array", new BsonArray());
document.append("object", new BsonDocument());
JsonElement element = TypeAdapters.JSON_ELEMENT.read(new BsonReader(new BsonDocumentReader(document)));
check(element.isJsonObject());
check(element.getAsJsonObject().get("boolean").getAsJsonPrimitive().isBoolean());
check(element.getAsJsonObject().get("boolean").getAsJsonPrimitive().getAsBoolean());
check(element.getAsJsonObject().get("int32").getAsJsonPrimitive().isNumber());
check(element.getAsJsonObject().get("int32").getAsJsonPrimitive().getAsNumber().intValue()).is(32);
check(element.getAsJsonObject().get("int64").getAsJsonPrimitive().isNumber());
check(element.getAsJsonObject().get("int64").getAsJsonPrimitive().getAsNumber().longValue()).is(64L);
check(element.getAsJsonObject().get("double").getAsJsonPrimitive().isNumber());
check(element.getAsJsonObject().get("double").getAsJsonPrimitive().getAsNumber().doubleValue()).is(42.42D);
check(element.getAsJsonObject().get("string").getAsJsonPrimitive().isString());
check(element.getAsJsonObject().get("string").getAsJsonPrimitive().getAsString()).is("foo");
check(element.getAsJsonObject().get("null").isJsonNull());
check(element.getAsJsonObject().get("array").isJsonArray());
check(element.getAsJsonObject().get("object").isJsonObject());
}
示例10: getBooleanFromInner
import org.bson.BsonBoolean; //导入依赖的package包/类
private Boolean getBooleanFromInner(Object key) {
BsonBoolean bsonBoolean = innerBsonDocument.getBoolean(key);
if (bsonBoolean != null) {
return (Boolean) BsonValueConverterRepertory.getValueConverterByBsonType(bsonBoolean.getBsonType()).decode(bsonBoolean);
}
return null;
}
示例11: testBooleanType
import org.bson.BsonBoolean; //导入依赖的package包/类
@Test
public void testBooleanType() throws IOException {
BsonDocument bsonDoc = new BsonDocument();
bsonDoc.append("booleanKey", new BsonBoolean(true));
writer.reset();
bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
assertTrue(mapReader.reader("booleanKey").readBoolean());
}
示例12: converseType
import org.bson.BsonBoolean; //导入依赖的package包/类
public static BsonValue converseType(String value) {
String[] valArr = value.split("\\^");
if (valArr.length != 2) {
return new BsonString(value);
}
try {
String type = valArr[1];
if (type.equals("int")) {
return new BsonInt32(Integer.parseInt(valArr[0]));
} else if (type.equals("long")) {
return new BsonInt64(Long.parseLong(valArr[0]));
} else if (type.equals("double")) {
return new BsonDouble(Double.parseDouble(valArr[0]));
} else if (type.equals("boolean")) {
return new BsonBoolean(Boolean.parseBoolean(valArr[0]));
} else if (type.equals("float")) {
return new BsonDouble(Double.parseDouble(valArr[0]));
} else if (type.equals("dateTime")) {
BsonDateTime time = getBsonDateTime(valArr[0]);
if (time != null)
return time;
return new BsonString(value);
} else if (type.equals("geoPoint")) {
BsonDocument point = getBsonGeoPoint(valArr[0]);
if (point == null)
return new BsonString(value);
return point;
} else if (type.equals("geoArea")) {
BsonDocument area = getBsonGeoArea(valArr[0]);
if (area == null)
return new BsonString(value);
return area;
} else {
return new BsonString(value);
}
} catch (NumberFormatException e) {
return new BsonString(value);
}
}
示例13: converseType
import org.bson.BsonBoolean; //导入依赖的package包/类
static BsonValue converseType(String value) {
String[] valArr = value.split("\\^");
if (valArr.length != 2) {
return new BsonString(value);
}
try {
String type = valArr[1].trim();
if (type.equals("int")) {
return new BsonInt32(Integer.parseInt(valArr[0]));
} else if (type.equals("long")) {
return new BsonInt64(Long.parseLong(valArr[0]));
} else if (type.equals("double")) {
return new BsonDouble(Double.parseDouble(valArr[0]));
} else if (type.equals("boolean")) {
return new BsonBoolean(Boolean.parseBoolean(valArr[0]));
} else if (type.equals("regex")) {
return new BsonRegularExpression("^" + valArr[0] + "$");
} else if (type.equals("float")) {
return new BsonDouble(Double.parseDouble(valArr[0]));
} else if (type.equals("dateTime")) {
BsonDateTime time = MongoQueryService.getTimeMillis(valArr[0]);
if (time != null)
return time;
return new BsonString(value);
} else {
return new BsonString(value);
}
} catch (NumberFormatException e) {
return new BsonString(value);
}
}
示例14: getExtensionMap
import org.bson.BsonBoolean; //导入依赖的package包/类
private Map<String, BsonValue> getExtensionMap(List<ECReportMemberField> fields) {
Map<String, BsonValue> extMap = new HashMap<String, BsonValue>();
for (int l = 0; l < fields.size(); l++) {
ECReportMemberField field = fields.get(l);
String key = field.getName();
String value = field.getValue();
String[] valArr = value.split("\\^");
if (valArr.length != 2) {
extMap.put(key, new BsonString(value));
continue;
}
try {
String type = valArr[1];
if (type.equals("int")) {
extMap.put(key, new BsonInt32(Integer.parseInt(valArr[0])));
} else if (type.equals("long")) {
extMap.put(key, new BsonInt64(Long.parseLong(valArr[0])));
} else if (type.equals("double")) {
extMap.put(key, new BsonDouble(Double.parseDouble(valArr[0])));
} else if (type.equals("boolean")) {
extMap.put(key, new BsonBoolean(Boolean.parseBoolean(valArr[0])));
} else if (type.equals("dateTime")) {
extMap.put(key, new BsonDateTime(Long.parseLong(valArr[0])));
} else {
extMap.put(key, new BsonString(valArr[0]));
}
} catch (NumberFormatException e) {
extMap.put(key, new BsonString(valArr[0]));
}
}
return extMap;
}
示例15: makeOtherwiseIdenticalFilter
import org.bson.BsonBoolean; //导入依赖的package包/类
@SuppressWarnings("unused")
private BsonDocument makeOtherwiseIdenticalFilter(BsonDocument filter) {
filter.remove("errorDeclaration");
filter.put("errorDeclaration", new BsonDocument("$exists", new BsonBoolean(false)));
filter.remove("recordTime");
return filter;
}