本文整理匯總了Java中org.ojai.FieldSegment類的典型用法代碼示例。如果您正苦於以下問題:Java FieldSegment類的具體用法?Java FieldSegment怎麽用?Java FieldSegment使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FieldSegment類屬於org.ojai包,在下文中一共展示了FieldSegment類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: schemaPathToFieldPath
import org.ojai.FieldSegment; //導入依賴的package包/類
/**
* Returns {@link FieldPath} equivalent of the specified {@link SchemaPath}.
*
* @param schemaPath {@link SchemaPath} instance that should be converted
* @return {@link FieldPath} equivalent of the specified {@link SchemaPath}.
*/
public static FieldPath schemaPathToFieldPath(SchemaPath schemaPath) {
Deque<PathSegment> pathSegments = Queues.newArrayDeque();
PathSegment pathSegment = schemaPath.getRootSegment();
while (pathSegment != null) {
pathSegments.push(pathSegment);
pathSegment = pathSegment.getChild();
}
FieldSegment child = null;
while (!pathSegments.isEmpty()) {
pathSegment = pathSegments.pop();
if (pathSegment.isNamed()) {
child = new FieldSegment.NameSegment(((PathSegment.NameSegment) pathSegment).getPath(), child, false);
} else {
child = new FieldSegment.IndexSegment(String.valueOf(((PathSegment.ArraySegment) pathSegment).getIndex()), child);
}
}
return new FieldPath((FieldSegment.NameSegment) child);
}
示例2: TypeMappedJsonDocumentReader
import org.ojai.FieldSegment; //導入依賴的package包/類
TypeMappedJsonDocumentReader(JsonDocumentStream stream, Map<FieldPath, Type> hashMap) {
super(stream);
if (hashMap == null) {
throw new IllegalArgumentException("A FieldPath => Type map must be provided.");
}
for (Entry<FieldPath, Type> entry : hashMap.entrySet()) {
for (FieldSegment seg : entry.getKey()) {
if (seg.isArray()) {
throw new IllegalArgumentException("A FieldPath with indexed segment is not supported.");
}
}
if (!entry.getValue().isScalar()) {
throw new IllegalArgumentException("A mapping to a container type (ARRAY, MAP) is not supported.");
}
}
this.typeMap = hashMap;
}
示例3: addOrGetChild
import org.ojai.FieldSegment; //導入依賴的package包/類
public void addOrGetChild(final FieldSegment child) {
final MutableFieldSegment segment = new MutableFieldSegment(child);
ProjectionTree subTree = getChildren().get(segment);
if (subTree == null) {
subTree = new ProjectionTree(child, this);
children.put(segment, subTree);
}
if (child.isLeaf()) {
/*
* Trim the branch in this projection tree if a suffix of an existing field path is encountered
* i.e. ("a.b.c", "a.b") => ("a.b").
*/
subTree.setLeafSegment();
} else if (!subTree.isLeafSegment()) { // do not descent if a suffix field path already exists.
subTree.addOrGetChild(child.getChild());
}
}
示例4: testEmptyFieldPath
import org.ojai.FieldSegment; //導入依賴的package包/類
@Test
public void testEmptyFieldPath() {
FieldSegment root = EMPTY.getRootSegment();
assertNotNull(root);
assertTrue(root.isLastPath());
assertTrue(root.isLeaf());
assertEquals("", EMPTY.asPathString());
FieldPath fp = FieldPath.parseFrom("``");
assertSame(fp, EMPTY);
fp = FieldPath.parseFrom("\"\"");
assertSame(fp, EMPTY);
fp = FieldPath.parseFrom("");
assertSame(fp, EMPTY);
}
示例5: testFieldPathEscapedWithoutQuote
import org.ojai.FieldSegment; //導入依賴的package包/類
@Test
public void testFieldPathEscapedWithoutQuote() {
FieldPath fp = FieldPath.parseFrom("a\\.b\\[4\\]");
Iterator<FieldSegment> segItr = fp.iterator();
assertTrue(segItr.hasNext());
FieldSegment seg = segItr.next();
assertTrue(seg.isNamed());
assertEquals("a.b[4]", seg.getNameSegment().getName());
assertFalse(segItr.hasNext());
assertEquals("a\\.b\\[4\\]", fp.asPathString());
assertEquals("a\\.b\\[4\\]", fp.toString());
assertEquals("a\\.b\\[4\\]", fp.asPathString(false));
assertEquals("\"a.b[4]\"", fp.asPathString(true));
assertEquals("\"a\\.b\\[4\\]\"", fp.asJsonString());
}
示例6: testFieldPathEscapedControlCharsMedley
import org.ojai.FieldSegment; //導入依賴的package包/類
@Test
public void testFieldPathEscapedControlCharsMedley() {
FieldPath fp = FieldPath.parseFrom("`a\\\"`" // quoted with back-tick
+ "."
+ "\"\\u000F\\`\\\"\\b\\f\\n\\r\\t\\\\\\//000C\"" // quoted with double-quote
+ "."
+ "c\\u0034 \\`p"); // unquoted
Iterator<FieldSegment> segItr = fp.iterator();
assertTrue(segItr.hasNext());
FieldSegment seg = segItr.next();
assertTrue(seg.isNamed());
assertEquals("a\"", seg.getNameSegment().getName());
assertTrue(segItr.hasNext());
seg = segItr.next();
assertTrue(seg.isNamed());
assertEquals("\u000F`\"\b\f\n\r\t\\//000C", seg.getNameSegment().getName());
assertTrue(segItr.hasNext());
seg = segItr.next();
assertTrue(seg.isNamed());
assertEquals("c4 `p", seg.getNameSegment().getName());
assertFalse(segItr.hasNext());
}
示例7: getFieldPathForProjection
import org.ojai.FieldSegment; //導入依賴的package包/類
private static FieldPath getFieldPathForProjection(SchemaPath column) {
Stack<PathSegment.NameSegment> pathSegments = new Stack<PathSegment.NameSegment>();
PathSegment seg = column.getRootSegment();
while (seg != null && seg.isNamed()) {
pathSegments.push((PathSegment.NameSegment) seg);
seg = seg.getChild();
}
FieldSegment.NameSegment child = null;
while (!pathSegments.isEmpty()) {
child = new FieldSegment.NameSegment(pathSegments.pop().getPath(), child, false);
}
return new FieldPath(child);
}
示例8: delete
import org.ojai.FieldSegment; //導入依賴的package包/類
Document delete(Iterator<FieldSegment> iter) {
FieldSegment field = iter.next();
if (field == null) return null;
String key = field.getNameSegment().getName();
JsonValue kv = getRootMap().get(key);
// if value doesn't exist in map then return null
if (kv == null) {
return null;
}
// if this is the last path then return the value at this key in map
if (field.isLastPath()) {
getRootMap().remove(kv.key);
return null;
}
// this is intermediate path so based on the type return the hierarchical value
if (field.isMap()) {
if (kv.getType() != Type.MAP) {
return null;
}
return ((JsonDocument)kv).delete(iter);
}
if (kv.getType() != Type.ARRAY) {
return null;
}
((JsonList)kv).delete(iter);
return this;
}
示例9: getKeyValueAt
import org.ojai.FieldSegment; //導入依賴的package包/類
public JsonValue getKeyValueAt(Iterator<FieldSegment> iter) {
FieldSegment field = iter.next();
if (field == null) return null;
String key = field.getNameSegment().getName();
JsonValue kv = getRootMap().get(key);
if (kv == null) {
return null;
}
// if this is the last path then return the value at this key in map
if (field.isLastPath()) {
return kv;
}
// this is intermediate path so based on the type return the hierarchical value
if (field.isMap()) {
if (kv.getType() != Type.MAP) {
return null;
}
return ((JsonDocument)kv).getKeyValueAt(iter);
}
if (kv.getType() != Type.ARRAY) {
return null;
}
return ((JsonList)kv).getJsonValueAt(iter);
}
示例10: delete
import org.ojai.FieldSegment; //導入依賴的package包/類
void delete(Iterator<FieldSegment> iter) {
FieldSegment field = iter.next();
if (field == null) return ;
int index = field.getIndexSegment().getIndex();
JsonValue kv = getJsonValueAt(index);
// if value doesn't exist in array then return null
if (kv == null) {
return;
}
// if this is the last path then return the value at this key in map
if (field.isLastPath()) {
list.remove(kv.key);
}
if (field.isMap()) {
if (kv.getType() != Type.MAP) {
return;
}
((JsonDocument)kv).delete(iter);
}
if (kv.getType() != Type.ARRAY) {
return;
}
JsonList l = (JsonList) kv;
l.delete(iter);
}
示例11: getJsonValueAt
import org.ojai.FieldSegment; //導入依賴的package包/類
JsonValue getJsonValueAt(Iterator<FieldSegment> iter) {
FieldSegment field = iter.next();
if (field == null) return null;
int index = field.getIndexSegment().getIndex();
JsonValue kv = getJsonValueAt(index);
// if value doesn't exist in map then return null
if (kv == null) {
return null;
}
// if this is the last path then return the value at this index
if (field.isLastPath()) {
return kv;
}
if (field.isMap()) {
if (kv.getType() != Type.MAP) {
return null;
}
return ((JsonDocument)kv).getKeyValueAt(iter);
}
if (kv.getType() != Type.ARRAY) {
return null;
}
return ((JsonList)kv).getJsonValueAt(iter);
}
示例12: MutableFieldSegment
import org.ojai.FieldSegment; //導入依賴的package包/類
MutableFieldSegment(FieldSegment fieldSegment) {
isNamed = fieldSegment.isNamed();
if (isNamed) {
fieldName = fieldSegment.getNameSegment().getName();
} else {
fieldIndex = fieldSegment.getIndexSegment().getIndex();
}
}
示例13: testSegmentIterator
import org.ojai.FieldSegment; //導入依賴的package包/類
@Test
public void testSegmentIterator() {
FieldPath fp = FieldPath.parseFrom("a.b.\"c\"[4].x");
Iterator<FieldSegment> itr = fp.iterator();
assertTrue(itr.next().isNamed());
assertEquals("b", itr.next().getNameSegment().getName());
assertEquals("c", itr.next().getNameSegment().getName());
assertEquals(4, itr.next().getIndexSegment().getIndex());
assertEquals("x", itr.next().getNameSegment().getName());
assertFalse(itr.hasNext());
}
示例14: testFieldPathUnicodeSequence
import org.ojai.FieldSegment; //導入依賴的package包/類
@Test
public void testFieldPathUnicodeSequence() {
// Java literal string "\u0041.\u0042", parsed by FieldPath grammar
FieldPath fp = FieldPath.parseFrom("\\u0041.\\u0042");
Iterator<FieldSegment> segItr = fp.iterator();
assertTrue(segItr.hasNext());
FieldSegment seg = segItr.next();
assertTrue(seg.isNamed());
assertEquals("A", seg.getNameSegment().getName());
assertTrue(segItr.hasNext());
seg = segItr.next();
assertTrue(seg.isNamed());
assertEquals("B", seg.getNameSegment().getName());
// Unicode sequence parsed by Java literal String grammar
fp = FieldPath.parseFrom("\u0041.\u0042");
segItr = fp.iterator();
assertTrue(segItr.hasNext());
seg = segItr.next();
assertTrue(seg.isNamed());
assertEquals("A", seg.getNameSegment().getName());
assertTrue(segItr.hasNext());
seg = segItr.next();
assertTrue(seg.isNamed());
assertEquals("B", seg.getNameSegment().getName());
}
示例15: createOrInsert
import org.ojai.FieldSegment; //導入依賴的package包/類
JsonDocument createOrInsert(Iterator<FieldSegment> iter, JsonValue newKeyValue) {
FieldSegment field;
field = iter.next();
String key = field.getNameSegment().getName();
JsonValue oldKeyValue = getRootMap().get(key);
/*
* If this is the last element in the path then just
* overwrite the previous value for the same key with
* new value
*/
if (field.isLastPath()) {
newKeyValue.setKey(key);
getRootMap().put(key, newKeyValue);
return this;
}
if (field.isMap()) {
/*
* if the new value for the same field is not
* a map then delete the existing value and write new
*/
JsonDocument newDocument;
if ((oldKeyValue == null) || (oldKeyValue.getType() != Type.MAP)) {
newDocument = new JsonDocument();
newDocument.createOrInsert(iter, newKeyValue);
newDocument.setKey(key);
getRootMap().put(key, newDocument);
return this;
}
// Inserting into an existing child of map type
newDocument = (JsonDocument) oldKeyValue;
return newDocument.createOrInsert(iter, newKeyValue);
}
JsonList newList;
if ((oldKeyValue == null) || (oldKeyValue.getType() != Type.ARRAY)) {
newList = new JsonList();
newList.createOrInsert(iter, newKeyValue);
newList.setKey(key);
getRootMap().put(key, newList);
return this;
}
newList = (JsonList)oldKeyValue;
newList.createOrInsert(iter, newKeyValue);
return this;
}