请选择 进入手机版 | 继续访问电脑版
  • 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java BsonValue类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.bson.BsonValue的典型用法代码示例。如果您正苦于以下问题:Java BsonValue类的具体用法?Java BsonValue怎么用?Java BsonValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



BsonValue类属于org.bson包,在下文中一共展示了BsonValue类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testCustomizedBsonConverter

import org.bson.BsonValue; //导入依赖的package包/类
@Test
public void testCustomizedBsonConverter() throws Exception {
    BsonValueConverterRepertory.registerCustomizedBsonConverter(String.class, new AbstractBsonConverter<String, BsonString>() {
        @Override
        public String decode(BsonReader bsonReader) {
            return "replace string";
        }

        @Override
        public void encode(BsonWriter bsonWriter, String value) {

        }

        @Override
        public String decode(BsonValue bsonValue) {
            return "replace string";
        }

        @Override
        public BsonString encode(String object) {
            return new BsonString("replace string");
        }
    });
    readFrom();
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:26,代码来源:DefaultBsonMapperTest.java


示例2: getPath

import org.bson.BsonValue; //导入依赖的package包/类
static List<String> getPath(BsonValue path) {
    List<String> result = new ArrayList<String>();
    StringBuilder builder = new StringBuilder();
    String cleanPath = path.asString().getValue().replaceAll("\"", "");
    for (int index = 0; index < cleanPath.length(); index++) {
        char c = cleanPath.charAt(index);
        if (c == '/') {
            result.add(decodePath(builder.toString()));
            builder.delete(0,  builder.length());
        } else {
            builder.append(c);
        }
    }
    result.add(decodePath(builder.toString()));
    return result;
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:17,代码来源:PathUtils.java


示例3: add

import org.bson.BsonValue; //导入依赖的package包/类
@Override
public void add(List<String> path, BsonValue value) {
    if (path.isEmpty()) {
        error(Operation.ADD, "path is empty , path : ");
    } else {
    	BsonValue parentNode = getParentNode(path, Operation.ADD);
        String fieldToReplace = path.get(path.size() - 1).replaceAll("\"", "");
        if (fieldToReplace.equals("") && path.size() == 1)
            target = value;
        else if (!parentNode.isDocument() && !parentNode.isArray())
            error(Operation.ADD, "parent is not a container in source, path provided : " + PathUtils.getPathRepresentation(path) + " | node : " + parentNode);
        else if (parentNode.isArray())
            addToArray(path, value, parentNode);
        else
            addToObject(path, parentNode, value);
    }
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:18,代码来源:InPlaceApplyProcessor.java


示例4: replace

import org.bson.BsonValue; //导入依赖的package包/类
@Override
public void replace(List<String> path, BsonValue value) {
    if (path.isEmpty()) {
        error(Operation.REPLACE, "path is empty");
    } else {
        BsonValue parentNode = getParentNode(path, Operation.REPLACE);
        String fieldToReplace = path.get(path.size() - 1).replaceAll("\"", "");
        if (isNullOrEmpty(fieldToReplace) && path.size() == 1)	
            target = value;
        else if (parentNode.isDocument())
            parentNode.asDocument().put(fieldToReplace, value);
        else if (parentNode.isArray())
            parentNode.asArray().set(arrayIndex(fieldToReplace, parentNode.asArray().size() - 1, false), value);
        else
            error(Operation.REPLACE, "noSuchPath in source, path provided : " + PathUtils.getPathRepresentation(path));
    }
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:18,代码来源:InPlaceApplyProcessor.java


示例5: remove

import org.bson.BsonValue; //导入依赖的package包/类
@Override
public void remove(List<String> path) {
    if (path.isEmpty()) {
        error(Operation.REMOVE, "path is empty");
    } else {
        BsonValue parentNode = getParentNode(path, Operation.REMOVE);
        String fieldToRemove = path.get(path.size() - 1).replaceAll("\"", "");
        if (parentNode.isDocument())
            parentNode.asDocument().remove(fieldToRemove);
        else if (parentNode.isArray()) {
        	// If path specifies a non-existent array element and the REMOVE_NONE_EXISTING_ARRAY_ELEMENT flag is not set, then
        	// arrayIndex will throw an error.
        	int i = arrayIndex(fieldToRemove, parentNode.asArray().size() - 1, flags.contains(CompatibilityFlags.REMOVE_NONE_EXISTING_ARRAY_ELEMENT));
        	// However, BsonArray.remove(int) is not very forgiving, so we need to avoid making the call if the index is past the end
        	// otherwise, we'll get an IndexArrayOutOfBounds error
        	if (i < parentNode.asArray().size()) {
        		parentNode.asArray().remove(i);
        	}
        } else
            error(Operation.REMOVE, "noSuchPath in source, path provided : " + PathUtils.getPathRepresentation(path));
    }
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:23,代码来源:InPlaceApplyProcessor.java


示例6: asBson

import org.bson.BsonValue; //导入依赖的package包/类
public static BsonArray asBson(final BsonValue source, final BsonValue target, EnumSet<DiffFlags> flags) {
    final List<Diff> diffs = new ArrayList<Diff>();
    List<Object> path = new ArrayList<Object>(0);
    
    // generating diffs in the order of their occurrence
    generateDiffs(diffs, path, source, target);

    if (!flags.contains(DiffFlags.OMIT_MOVE_OPERATION)) {        
      // Merging remove & add to move operation
     compactDiffs(diffs);
    }

    if (!flags.contains(DiffFlags.OMIT_COPY_OPERATION)) {
      // Introduce copy operation
     introduceCopyOperation(source, target, diffs);
    }

    return getBsonNodes(diffs, flags);
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:20,代码来源:BsonDiff.java


示例7: computeUnchangedValues

import org.bson.BsonValue; //导入依赖的package包/类
private static void computeUnchangedValues(Map<BsonValue, List<Object>> unchangedValues, List<Object> path, BsonValue source, BsonValue target) {
    if (source.equals(target)) {
        if (!unchangedValues.containsKey(target)) {
        	unchangedValues.put(target, path);
        }
        return;
    }

    if (source.getBsonType().equals(target.getBsonType())) {
        switch (source.getBsonType()) {
            case DOCUMENT:
                computeDocument(unchangedValues, path, source, target);
                break;
            case ARRAY:
                computeArray(unchangedValues, path, source, target);
            default:
                /* nothing */
        }
    }
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:21,代码来源:BsonDiff.java


示例8: testPatchAppliedCleanly

import org.bson.BsonValue; //导入依赖的package包/类
@Test
    public void testPatchAppliedCleanly() throws Exception {
        for (int i = 0; i < jsonNode.size(); i++) {
        	BsonDocument node = jsonNode.get(i).asDocument();
        	
            BsonValue first = node.get("first");
            BsonValue second = node.get("second");
            BsonArray patch = node.getArray("patch");
            String message = node.containsKey("message") ? node.getString("message").getValue() : "";

//            System.out.println("Test # " + i);
//            System.out.println(first);
//            System.out.println(second);
//            System.out.println(patch);

            BsonValue secondPrime = BsonPatch.apply(patch, first);
//            System.out.println(secondPrime);
            Assert.assertThat(message, secondPrime, equalTo(second));
        }

    }
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:22,代码来源:JsonDiffTest2.java


示例9: testSampleJsonDiff

import org.bson.BsonValue; //导入依赖的package包/类
@Test
    public void testSampleJsonDiff() throws Exception {
        for (int i = 0; i < jsonNode.size(); i++) {
            BsonValue first = jsonNode.get(i).asDocument().get("first");
            BsonValue second = jsonNode.get(i).asDocument().get("second");

//            System.out.println("Test # " + i);
//            System.out.println(first);
//            System.out.println(second);

            BsonArray actualPatch = BsonDiff.asBson(first, second);

//            System.out.println(actualPatch);

            BsonValue secondPrime = BsonPatch.apply(actualPatch, first);
//            System.out.println(secondPrime);
            Assert.assertTrue(second.equals(secondPrime));
        }
    }
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:20,代码来源:JsonDiffTest.java


示例10: testRenderedOperationsExceptMoveAndCopy

import org.bson.BsonValue; //导入依赖的package包/类
@Test
    public void testRenderedOperationsExceptMoveAndCopy() throws Exception {
    	BsonDocument source = new BsonDocument();
    	source.put("age", new BsonInt32(10));
    	BsonDocument target = new BsonDocument();
    	target.put("height", new BsonInt32(10));

        EnumSet<DiffFlags> flags = DiffFlags.dontNormalizeOpIntoMoveAndCopy().clone(); //only have ADD, REMOVE, REPLACE, Don't normalize operations into MOVE & COPY

        BsonArray diff = BsonDiff.asBson(source, target, flags);

//        System.out.println(source);
//        System.out.println(target);
//        System.out.println(diff);

        for (BsonValue d : diff) {
            Assert.assertNotEquals(Operation.MOVE.rfcName(), d.asDocument().getString("op").getValue());
            Assert.assertNotEquals(Operation.COPY.rfcName(), d.asDocument().getString("op").getValue());
        }

        BsonValue targetPrime = BsonPatch.apply(diff, source);
//        System.out.println(targetPrime);
        Assert.assertTrue(target.equals(targetPrime));


    }
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:27,代码来源:JsonDiffTest.java


示例11: convertBinaryUUID

import org.bson.BsonValue; //导入依赖的package包/类
/**
 * Converts a binary uuid to a standard uuid
 *
 * @param json The json string (should contain "$binary" and "$type" or something like that)
 * @return The uuid
 */
private UUID convertBinaryUUID(String key, String json) {
    BsonDocument document = BsonDocument.parse(json);

    BsonValue value = document.get(key);
    if(!(value instanceof BsonBinary)) {
        return null;
    }
    byte[] bytes = ((BsonBinary) value).getData();
    ByteBuffer bb = ByteBuffer.wrap(bytes);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    long l1 = bb.getLong();
    long l2 = bb.getLong();

    return new UUID(l1, l2);
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:22,代码来源:DbFilter.java


示例12: getBsonValueList

import org.bson.BsonValue; //导入依赖的package包/类
private ArrayList<BsonValue> getBsonValueList(Field field, Collection values, BsonMapperConfig bsonMapperConfig, Class<?> componentType) {
    ArrayList<BsonValue> arrayList = new ArrayList<BsonValue>();
    for (Object o : values) {
        if (o == null) {
            continue;
        }
        Class<?> oClazz = o.getClass();
        if (Utils.isArrayType(oClazz)) {
            BsonArray innerBsonArray = new BsonArray();
            encode(innerBsonArray, field, o, bsonMapperConfig);
            arrayList.add(innerBsonArray);
        }
        if (componentType.isInstance(o)) {
            if (BsonValueConverterRepertory.isCanConverterValueType(componentType)) {
                arrayList.add(BsonValueConverterRepertory.getValueConverterByClazz(componentType).encode(o));
            } else {
                BsonDocument arrayEle = new BsonDocument();
                BsonValueConverterRepertory.getBsonDocumentConverter().encode(arrayEle, o, bsonMapperConfig);
                arrayList.add(arrayEle);
            }
        } else {
            throw new BsonMapperConverterException(String.format("array field has element which has different type with declaring componentType.field name: %s", field.getName()));
        }
    }
    return arrayList;
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:27,代码来源:BsonArrayConverter.java


示例13: handleArrayForBsonArray

import org.bson.BsonValue; //导入依赖的package包/类
private Object handleArrayForBsonArray(BsonArray bsonArray, Field field, BsonMapperConfig bsonMapperConfig) {
    ArrayList<Object> arrayList = new ArrayList<Object>();
    Class<?> fieldClazz = field.getType();
    for (BsonValue bsonValue : bsonArray) {
        if (bsonValue == null) {
            continue;
        }
        if (bsonValue.isArray()) {
            arrayList.add(decode(bsonValue.asArray(), field, bsonMapperConfig));
        } else {
            Object javaValue;
            if (bsonValue.isDocument()) {
                javaValue = BsonValueConverterRepertory.getBsonDocumentConverter().decode(bsonValue.asDocument(), fieldClazz.getComponentType(), bsonMapperConfig);
            } else {
                javaValue = BsonValueConverterRepertory.getValueConverterByBsonType(bsonValue.getBsonType()).decode(bsonValue);
            }
            arrayList.add(javaValue);
        }
    }
    return arrayList.toArray((Object[]) Array.newInstance(fieldClazz.getComponentType(), 0));
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:22,代码来源:BsonArrayConverter.java


示例14: toBson

import org.bson.BsonValue; //导入依赖的package包/类
BsonValue toBson() {
  @SuppressWarnings("unchecked")
  Encoder<T> encoder = BsonEncoding.encoderFor((Class<T>) value.getClass(), adapter);
  BsonDocument bson = new BsonDocument();
  org.bson.BsonWriter writer = new BsonDocumentWriter(bson);
  // Bson doesn't allow to write directly scalars / primitives, they have to be embedded in a document.
  writer.writeStartDocument();
  writer.writeName("$");
  encoder.encode(writer, value, EncoderContext.builder().build());
  writer.writeEndDocument();
  writer.flush();
  return bson.get("$");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:Support.java


示例15: move

import org.bson.BsonValue; //导入依赖的package包/类
@Override
public void move(List<String> fromPath, List<String> toPath) {
    BsonValue parentNode = getParentNode(fromPath, Operation.MOVE);
    String field = fromPath.get(fromPath.size() - 1).replaceAll("\"", "");
    BsonValue valueNode = parentNode.isArray() ? parentNode.asArray().get(Integer.parseInt(field)) : parentNode.asDocument().get(field);
    remove(fromPath);
    add(toPath, valueNode);
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:9,代码来源:InPlaceApplyProcessor.java


示例16: copy

import org.bson.BsonValue; //导入依赖的package包/类
@Override
public void copy(List<String> fromPath, List<String> toPath) {
    BsonValue parentNode = getParentNode(fromPath, Operation.COPY);
    String field = fromPath.get(fromPath.size() - 1).replaceAll("\"", "");
    BsonValue valueNode = parentNode.isArray() ? parentNode.asArray().get(Integer.parseInt(field)) : parentNode.asDocument().get(field);
    add(toPath, valueNode);
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:8,代码来源:InPlaceApplyProcessor.java


示例17: getParentNode

import org.bson.BsonValue; //导入依赖的package包/类
private BsonValue getParentNode(List<String> fromPath, Operation forOp) {
    List<String> pathToParent = fromPath.subList(0, fromPath.size() - 1); // would never by out of bound, lets see
    BsonValue node = getNode(target, pathToParent, 1);
    if (node == null)
    	error(forOp, "noSuchPath in source, path provided: " + PathUtils.getPathRepresentation(fromPath));
    return node;
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:8,代码来源:InPlaceApplyProcessor.java


示例18: toList

import org.bson.BsonValue; //导入依赖的package包/类
static List<BsonValue> toList(BsonArray input) {
    int size = input.size();
    List<BsonValue> toReturn = new ArrayList<BsonValue>(size);
    for (int i = 0; i < size; i++) {
        toReturn.add(input.get(i));
    }
    return toReturn;
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:9,代码来源:InternalUtils.java


示例19: getPatchAttrWithDefault

import org.bson.BsonValue; //导入依赖的package包/类
private static BsonValue getPatchAttrWithDefault(BsonValue bsonNode, String attr, BsonValue defaultValue) {
	BsonValue child = bsonNode.asDocument().get(attr);
    if (child == null)
        return defaultValue;
    else
        return child;
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:8,代码来源:BsonPatch.java


示例20: get

import org.bson.BsonValue; //导入依赖的package包/类
@Override
public Object get(Object key) {
    BsonValue bsonValue = innerBsonDocument.get(key);
    if (bsonValue == null) {
        return null;
    }
    return BsonValueConverterRepertory.getValueConverterByClazz(bsonValue.getClass()).decode(bsonValue);
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:9,代码来源:TDocument.java



注:本文中的org.bson.BsonValue类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RegexMapper类代码示例发布时间:2022-05-21
下一篇:
Java StreamCloser类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap