本文整理汇总了Java中org.bson.BsonType.STRING属性的典型用法代码示例。如果您正苦于以下问题:Java BsonType.STRING属性的具体用法?Java BsonType.STRING怎么用?Java BsonType.STRING使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.bson.BsonType
的用法示例。
在下文中一共展示了BsonType.STRING属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scalarToString
/**
* Gson library reads numbers lazily when using generic {@link com.google.gson.internal.bind.TypeAdapters#JSON_ELEMENT} type adapter.
* Number is read as string and then wrapped inside {@link LazilyParsedNumber}. This inefficiency should only occur if reading numbers with generic JSON element API
* and not using generated type adapters.
*
* @see LazilyParsedNumber
* @see com.google.gson.internal.bind.TypeAdapters#JSON_ELEMENT
*/
private String scalarToString() throws IOException {
final BsonType type = delegate.getCurrentBsonType();
if (type == BsonType.STRING) {
return delegate.readString();
} else if (type == BsonType.SYMBOL) {
return delegate.readSymbol();
} else if (type == BsonType.INT32) {
return Integer.toString(nextInt());
} else if (type == BsonType.INT64) {
return Long.toString(nextLong());
} else if (type == BsonType.DOUBLE) {
return Double.toString(nextDouble());
}
throw new IllegalStateException(String.format("Unknown scalar type to be converted to string: %s", type));
}
示例2: read
public T read(BsonReader reader, String field) {
BsonType currentType = reader.getCurrentBsonType();
if (currentType == BsonType.NULL) {
reader.readNull();
return null;
} else if (currentType == BsonType.STRING) {
String enumValue = reader.readString();
T value = decodingMappings.get(enumValue);
if (value == null) throw Exceptions.error("can not decode value to enum, enumClass={}, value={}", enumClass.getCanonicalName(), enumValue);
return value;
} else {
logger.warn("unexpected field type, field={}, type={}", field, currentType);
reader.skipValue();
return null;
}
}
示例3: convertBsonValueToString
private static String convertBsonValueToString(BsonValue bsonValue) {
BsonType type = bsonValue.getBsonType();
String value = null;
if (type == BsonType.STRING) {
value = bsonValue.asString().getValue();
} else if (type == BsonType.INT32) {
value = String.valueOf(bsonValue.asInt32().getValue());
} else if (type == BsonType.INT64) {
value = String.valueOf(bsonValue.asInt64().getValue());
} else if (type == BsonType.DOUBLE) {
value = String.valueOf(bsonValue.asDouble().getValue());
} else if (type == BsonType.BOOLEAN) {
value = String.valueOf(bsonValue.asBoolean().getValue());
}
return value;
}
示例4: getBsonType
protected BsonType getBsonType(Object value) {
if (value == null) {
return BsonType.NULL;
} else if (value instanceof Boolean) {
return BsonType.BOOLEAN;
} else if (value instanceof Double) {
return BsonType.DOUBLE;
} else if (value instanceof Integer) {
return BsonType.INT32;
} else if (value instanceof Long) {
return BsonType.INT64;
} else if (value instanceof String) {
return BsonType.STRING;
} else if (isObjectIdInstance(value)) {
return BsonType.OBJECT_ID;
} else if (isObjectInstance(value)) {
return BsonType.DOCUMENT;
} else if (isArrayInstance(value)) {
return BsonType.ARRAY;
} else {
return null;
}
}
示例5: decode
@Override
public Integer decode(BsonReader reader, DecoderContext decoderContext) {
if(reader.getCurrentBsonType() == BsonType.STRING) {
return Integer.valueOf(reader.readString());
}
return super.decode(reader, decoderContext);
}
示例6: readString
public String readString(String field) {
BsonType currentType = reader.getCurrentBsonType();
if (currentType == BsonType.NULL) {
reader.readNull();
return null;
} else if (currentType == BsonType.STRING) {
return reader.readString();
} else {
logger.warn("unexpected field type, field={}, type={}", field, currentType);
reader.skipValue();
return null;
}
}
示例7: isExtensionFilterPassed
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;
}