当前位置: 首页>>代码示例>>Java>>正文


Java BsonValue.isArray方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: getNode

import org.bson.BsonValue; //导入方法依赖的package包/类
private BsonValue getNode(BsonValue ret, List<String> path, int pos) {
    if (pos >= path.size()) {
        return ret;
    }
    String key = path.get(pos);
    if (ret.isArray()) {
        int keyInt = Integer.parseInt(key.replaceAll("\"", ""));
        // Check for index out of bounds, treat as no such path error
        if (keyInt >= ret.asArray().size()) {
        	return null;
        }
        BsonValue element = ret.asArray().get(keyInt);
        if (element == null)
            return null;
        else
            return getNode(ret.asArray().get(keyInt), path, ++pos);
    } else if (ret.isDocument()) {
        if (ret.asDocument().containsKey(key)) {
            return getNode(ret.asDocument().get(key), path, ++pos);
        }
        return null;
    } else {
        return ret;
    }
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:26,代码来源:InPlaceApplyProcessor.java

示例5: 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

示例6: 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

示例7: 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

示例8: generateDiffs

import org.bson.BsonValue; //导入方法依赖的package包/类
private static void generateDiffs(List<Diff> diffs, List<Object> path, BsonValue source, BsonValue target) {
    if (!source.equals(target)) {
        if (source.isArray() && target.isArray()) {
            //both are arrays
            compareArray(diffs, path, source, target);
        } else if (source.isDocument() && target.isDocument()) {
            //both are json
            compareDocuments(diffs, path, source, target);
        } else {
            //can be replaced

            diffs.add(Diff.generateDiff(Operation.REPLACE, path, source, target));
        }
    }
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:16,代码来源:BsonDiff.java

示例9: getJavaValueFromBsonValue

import org.bson.BsonValue; //导入方法依赖的package包/类
private Object getJavaValueFromBsonValue(BsonValue bsonValue, Field field, BsonMapperConfig bsonMapperConfig) {
    if (bsonValue.isArray()) {
        return BsonValueConverterRepertory.getBsonArrayConverter().decode(bsonValue.asArray(), field, bsonMapperConfig);
    }
    if (bsonValue.isDocument()) {
        return BsonValueConverterRepertory.getBsonDocumentConverter().decode(bsonValue.asDocument(), field.getType(), bsonMapperConfig);
    }
    if (bsonValue.isObjectId() && Utils.fieldIsObjectId(field)) {
        ObjectId objectId = (ObjectId) BsonValueConverterRepertory.getValueConverterByBsonType(bsonValue.getBsonType()).decode(bsonValue);
        return getObjectIdByRealType(field.getType(), objectId);
    }
    return BsonValueConverterRepertory.getValueConverterByBsonType(bsonValue.getBsonType()).decode(bsonValue);
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:14,代码来源:BsonDocumentConverter.java

示例10: handleCollectionForBsonArray

import org.bson.BsonValue; //导入方法依赖的package包/类
Object handleCollectionForBsonArray(BsonArray bsonArray, Field field, BsonMapperConfig bsonMapperConfig) {
    Class<?> fieldType = field.getType();
    Class<?> implClass = Utils.giveImplClassIfSupport(fieldType);
    if (Utils.isUnableAddCollectionClazz(implClass)) {
        return null;
    }
    BsonArrayField bsonArrayField = Utils.getBsonArrayFieldAnnotation(field);
    Class<?> targetComponentClazz = bsonArrayField.componentType();

    Object collectionObject = Utils.newInstanceByClazz(implClass);
    Method method;
    try {
        method = implClass.getMethod("add", Object.class);
    } catch (NoSuchMethodException e) {
        throw new BsonMapperConverterException("NoSuchMethodException", e);
    }

    for (BsonValue bsonValue : bsonArray) {
        if (bsonValue == null) {
            continue;
        }
        if (bsonValue.isArray()) {
            BsonArray array = bsonValue.asArray();
            Utils.methodInvoke(method, collectionObject, decode(array, field, bsonMapperConfig));
        } else {
            Object javaValue;
            if (bsonValue.isDocument()) {
                javaValue = BsonValueConverterRepertory.getBsonDocumentConverter().decode(bsonValue.asDocument(), targetComponentClazz, bsonMapperConfig);
            } else {
                javaValue = BsonValueConverterRepertory.getValueConverterByBsonType(bsonValue.getBsonType()).decode(bsonValue);
            }
            Utils.methodInvoke(method, collectionObject, javaValue);
        }
    }
    return collectionObject;
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:37,代码来源:BsonArrayConverter.java


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