本文整理汇总了Java中com.redhat.lightblue.util.Path.numSegments方法的典型用法代码示例。如果您正苦于以下问题:Java Path.numSegments方法的具体用法?Java Path.numSegments怎么用?Java Path.numSegments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.redhat.lightblue.util.Path
的用法示例。
在下文中一共展示了Path.numSegments方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDBObject
import com.redhat.lightblue.util.Path; //导入方法依赖的package包/类
public static Object getDBObject(DBObject start, Path p) {
int n = p.numSegments();
Object trc = start;
for (int seg = 0; seg < n; seg++) {
String segment = p.head(seg);
if (segment.equals(Path.ANY)) {
throw Error.get(MongoCrudConstants.ERR_TRANSLATION_ERROR, p.toString());
} else if (trc != null && Util.isNumber(segment)) {
trc = ((List) trc).get(Integer.valueOf(segment));
} else if (trc != null) {
trc = ((DBObject) trc).get(segment);
}
if (trc == null && seg + 1 < n) {
//At least one element in the Path is optional and does not exist in the document. Just return null.
LOGGER.debug("Error retrieving path {} with {} segments from {}", p, p.numSegments(), start);
return null;
}
}
return trc;
}
示例2: processNestedArrays
import com.redhat.lightblue.util.Path; //导入方法依赖的package包/类
private Block processNestedArrays(Context ctx,Path field,Block parent,Name arrayFieldName) {
MutablePath pathSegment=new MutablePath();
for(int i=0;i<field.numSegments();i++) {
String seg=field.head(i);
if(Path.ANY.equals(seg)) {
Name name=ctx.varName(arrayFieldName);
ArrForLoop loop=new ArrForLoop(ctx.newName("ri"),name);
parent.add(IfStatement.ifDefined(name,loop));
parent=loop;
pathSegment.push(Path.ANY);
arrayFieldName.add(loop.loopVar,true);
} else {
arrayFieldName.add(seg,field.isIndex(i));
pathSegment.push(seg);
}
}
return parent;
}
示例3: getArrayIdentityExtractor
import com.redhat.lightblue.util.Path; //导入方法依赖的package包/类
@Override
public IdentityExtractor getArrayIdentityExtractor(Path arrayField) {
MutablePath p = new MutablePath();
int n = arrayField.numSegments();
for (int i = 0; i < n; i++) {
if (arrayField.isIndex(i)) {
p.push(Path.ANY);
} else {
p.push(arrayField.head(i));
}
}
if(ignoredIdentities.contains(p))
return null;
else {
ArrayIdentityFields fields = getArrayIdentities().get(p);
if (fields != null) {
return getArrayIdentityExtractorImpl(fields);
}
}
return null;
}
示例4: getArray
import com.redhat.lightblue.util.Path; //导入方法依赖的package包/类
/**
* Input is a path to an array element
* Output is the array containing that element, and all indexes replaced with *
*/
private Path getArray(Path p) {
int lastIndex=p.numSegments()-1;
while(lastIndex>0) {
if(p.isIndex(lastIndex))
break;
lastIndex--;
}
MutablePath mp=new MutablePath();
for(int i=0;i<lastIndex;i++) {
if(p.isIndex(i))
mp.push(Path.ANY);
else
mp.push(p.head(i));
}
return mp.immutableCopy();
}
示例5: addFieldToParent
import com.redhat.lightblue.util.Path; //导入方法依赖的package包/类
/**
* Adds the <code>newField</cod> to the <code>newFieldPath</code>.
* @param md - {@link EntityMetadata}
* @param newFieldPath - {@link Path} to add
* @param newField - {@link Field} to add at the <code>newFieldPath</code>
*/
private void addFieldToParent(EntityMetadata md, Path newFieldPath, Field newField){
Fields fields;
if(newFieldPath.numSegments() == 1){
fields = md.getFields();
}
else{
Path parentPath = newFieldPath.prefix(-1);
FieldTreeNode parent = md.resolve(parentPath);
if(parent instanceof ObjectField){
fields = ((ObjectField) parent).getFields();
}
else if (parent instanceof ObjectArrayElement){
fields = ((ObjectArrayElement) parent).getFields();
}
else {
throw Error.get(MetadataConstants.ERR_FIELD_WRONG_TYPE, parentPath.toString());
}
}
fields.addNew(newField);
}
示例6: Name
import com.redhat.lightblue.util.Path; //导入方法依赖的package包/类
public Name(Path p) {
int n=p.numSegments();
for(int i=0;i<n;i++) {
String s=p.head(i);
parts.add(new Part(s,p.isIndex(i)));
}
}
示例7: hasHiddenField
import com.redhat.lightblue.util.Path; //导入方法依赖的package包/类
private boolean hasHiddenField(Path path) {
for (int i = 0; i < path.numSegments(); i++) {
if (path.head(i).equals(DocTranslator.HIDDEN_SUB_PATH.toString())) {
return true;
}
}
return false;
}
示例8: translatePath
import com.redhat.lightblue.util.Path; //导入方法依赖的package包/类
/**
* Translate a path to a mongo path
*
* Any * in the path is removed. Array indexes remain intact.
*/
public static String translatePath(Path p) {
StringBuilder str = new StringBuilder();
int n = p.numSegments();
for (int i = 0; i < n; i++) {
String s = p.head(i);
if (!s.equals(Path.ANY)) {
if (i > 0) {
str.append('.');
}
str.append(s);
}
}
return str.toString();
}
示例9: addField
import com.redhat.lightblue.util.Path; //导入方法依赖的package包/类
private void addField(DBObject doc,
List<DocComparator.Delta<Object>> delta,
DocComparator.Removal<Object> removedField) {
Path field = removedField.getField1();
// 'field' is the name of the removed field in the old document.
// We have to find the field name it has in the new document, because array elements might have moved around
MutablePath newFieldName = new MutablePath();
int n = field.numSegments();
for (int i = 0; i < n; i++) {
if (field.isIndex(i)) {
// At this point, newFieldName points to an array,
// field.prefix(i) points to an array element. If there
// is a Move delta for the move of field.prefix(i+1)
// -> someField, then we get the new index from
// someField
Path arrayElement = field.prefix(i+1);
// arrayElement.tail(0) is an index
Path movedTo = null;
for (DocComparator.Delta<Object> d : delta) {
if (d instanceof DocComparator.Move) {
DocComparator.Move<Object> move = (DocComparator.Move<Object>) d;
if (move.getField1().equals(arrayElement)) {
movedTo = move.getField2();
break;
}
}
}
LOGGER.debug("field: {}, arrayElement: {}, movedTo:{}", field,arrayElement,movedTo);
if (movedTo != null) {
// arrayElement moved to somewhere else, get the new index, push it to the newFieldName
newFieldName.push(movedTo.tail(0));
} else {
// ArrayElement did not move
newFieldName.push(field.head(i));
}
} else {
newFieldName.push(field.head(i));
}
}
// At this point, newFieldName contains the field in the new document
LOGGER.debug("Adding contents of {} to {}", field, newFieldName);
DBObject parent;
if (newFieldName.numSegments() > 1) {
parent = (DBObject) DocTranslator.getDBObject(doc, newFieldName.prefix(-1));
} else {
parent = doc;
}
parent.put(newFieldName.tail(0), copy(removedField.getRemovedNode()));
}
示例10: resolveFieldForQuery
import com.redhat.lightblue.util.Path; //导入方法依赖的package包/类
private FieldInfo resolveFieldForQuery(FieldTreeNode context,Path contextPath,Path field) {
int n=field.numSegments();
// Two paths: p: the full thing, s: only the relative field
// If the field reference moves to a parent of relative field, we use p
// otherwise, we use s
MutablePath p=new MutablePath(contextPath);
MutablePath s=new MutablePath();
FieldTreeNode fieldNode=context;
for(int i=0;i<n;i++) {
String seg=field.head(i);
if(field.isIndex(i)) {
p.push(seg);
if(s!=null)
s.push(seg);
if(fieldNode instanceof ArrayField) {
fieldNode=((ArrayField)fieldNode).getElement();
} else {
throw Error.get(ERR_INVALID_FIELD,field.toString());
}
} else {
if(Path.THIS.equals(seg)) {
// Don't push anything
;
} else if(Path.PARENT.equals(seg)) {
p.pop();
if(s!=null)
if(s.isEmpty())
s=null;
else
s.pop();
fieldNode=fieldNode.getParent();
} else {
p.push(seg);
if(s!=null)
s.push(seg);
fieldNode=fieldNode.resolve(new Path(seg));
}
}
}
if(!contextPath.isEmpty()) {
// If we are in a nonempty context (i.e. nested query under elemMatch), and our variable
// refers to a field above that context, then mongo language can't handle it, and we need
// to convert to JS
FieldTreeNode trc=fieldNode.getParent();
boolean fieldIsUnderContext=false;
while(trc!=null) {
if(trc==context) {
fieldIsUnderContext=true;
break;
} else {
trc=trc.getParent();
}
}
if(!fieldIsUnderContext)
throw new NeedsJS();
}
return new FieldInfo(s==null?p.immutableCopy():s.immutableCopy(),fieldNode);
}