Class TransposePathElement
- java.lang.Object
-
- com.bazaarvoice.jolt.common.pathelement.BasePathElement
-
- com.bazaarvoice.jolt.common.pathelement.TransposePathElement
-
- All Implemented Interfaces:
EvaluatablePathElement
,MatchablePathElement
,PathElement
public class TransposePathElement extends BasePathElement implements MatchablePathElement, EvaluatablePathElement
This PathElement is used by Shiftr to Transpose data. It can be used on the Left and Right hand sides of the spec. Input { "author" : "Stephen Hawking", "book" : "A Brief History of Time" } Wanted { "Stephen Hawking" : "A Brief History of Time" } The first part of the process is to allow a CompositeShiftr node to look down the input JSON tree. Spec { "@author" : "@book" } Secondly, we can look up the tree, and come down a different path to locate data. For example of this see the following ShiftrUnit tests : LHS Lookup : json/shiftr/filterParents.json RHS Lookup : json/shiftr/transposeComplex6_rhs-complex-at.json CanonicalForm Expansion Sugar "@2 -> "@(2,) "@(2) -> "@(2,) "@author" -> "@(0,author)" "@(author)" -> "@(0,author)" Splenda "@(a.b)" -> "@(0,a.b)" "@(a.&2.c)" -> "@(0,a.&(2,0).c)"
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
canonicalForm
private TransposeReader
subPathReader
private int
upLevel
-
Constructor Summary
Constructors Modifier Constructor Description private
TransposePathElement(java.lang.String originalKey, int upLevel, java.lang.String subPath)
Private constructor used after parsing is done.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
evaluate(WalkedPath walkedPath)
Evaluate this key as if it is an write path element.java.lang.String
getCanonicalForm()
Get the canonical form of this PathElement.private static TransposePathElement
innerParse(java.lang.String originalKey, java.lang.String meat)
Parse the core of the TransposePathElement key, once basic errors have been checked and syntax has been handled.MatchedElement
match(java.lang.String dataKey, WalkedPath walkedPath)
See if this PathElement matches the given dataKey.Optional<java.lang.Object>
objectEvaluate(WalkedPath walkedPath)
This method is used when the TransposePathElement is used on the LFH as data.static TransposePathElement
parse(java.lang.String key)
Parse a text value from a Spec, into a TransposePathElement.-
Methods inherited from class com.bazaarvoice.jolt.common.pathelement.BasePathElement
getRawKey, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.bazaarvoice.jolt.common.pathelement.PathElement
getRawKey
-
-
-
-
Field Detail
-
upLevel
private final int upLevel
-
subPathReader
private final TransposeReader subPathReader
-
canonicalForm
private final java.lang.String canonicalForm
-
-
Method Detail
-
parse
public static TransposePathElement parse(java.lang.String key)
Parse a text value from a Spec, into a TransposePathElement.- Parameters:
key
- rawKey from a Jolt Spec file- Returns:
- a TransposePathElement
-
innerParse
private static TransposePathElement innerParse(java.lang.String originalKey, java.lang.String meat)
Parse the core of the TransposePathElement key, once basic errors have been checked and syntax has been handled.- Parameters:
originalKey
- The original text for reference.meat
- The string to actually parse into a TransposePathElement- Returns:
- TransposePathElement
-
objectEvaluate
public Optional<java.lang.Object> objectEvaluate(WalkedPath walkedPath)
This method is used when the TransposePathElement is used on the LFH as data. Aka, normal "evaluate" returns either a Number or a String.- Parameters:
walkedPath
- WalkedPath to evaluate against- Returns:
- The data specified by this TransposePathElement.
-
evaluate
public java.lang.String evaluate(WalkedPath walkedPath)
Description copied from interface:EvaluatablePathElement
Evaluate this key as if it is an write path element.- Specified by:
evaluate
in interfaceEvaluatablePathElement
- Parameters:
walkedPath
- "up the tree" list of LiteralPathElements, that may be used by this key as it is computing- Returns:
- String path element to use for write tree building
-
match
public MatchedElement match(java.lang.String dataKey, WalkedPath walkedPath)
Description copied from interface:MatchablePathElement
See if this PathElement matches the given dataKey. If it does not match, this method returns null. If this PathElement does match, it returns a LiteralPathElement with subKeys filled in.- Specified by:
match
in interfaceMatchablePathElement
- Parameters:
dataKey
- String key value from the input datawalkedPath
- "up the tree" list of LiteralPathElements, that may be used by this key as it is computing its match- Returns:
- null or a matched LiteralPathElement
-
getCanonicalForm
public java.lang.String getCanonicalForm()
Description copied from interface:PathElement
Get the canonical form of this PathElement. Really only interesting for the Reference Path element, where it will expand "&" to "&0(0)".- Specified by:
getCanonicalForm
in interfacePathElement
- Returns:
- canonical String version of this PathElement
-
-