-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from milosimpson/shiftr-hash4
New feature and two bug fixes
- Loading branch information
Showing
25 changed files
with
542 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
jolt-core/src/main/java/com/bazaarvoice/jolt/shiftr/reference/AmpReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
package com.bazaarvoice.jolt.shiftr.reference; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* This class parses the Jolt & syntax into useful programmatic constructs. | ||
* | ||
* Valid Syntax is : & &1 &(1) &(1,1) | ||
*/ | ||
public class AmpReference extends BaseReference { | ||
public class AmpReference extends BasePathAndGroupReference { | ||
|
||
public static final Character TOKEN = '&'; | ||
|
||
public AmpReference( String refStr ) { | ||
super(refStr); | ||
} | ||
|
||
@Override | ||
protected char getToken() { | ||
return '&'; | ||
return TOKEN; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
jolt-core/src/main/java/com/bazaarvoice/jolt/shiftr/reference/BasePathReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.bazaarvoice.jolt.shiftr.reference; | ||
|
||
import com.bazaarvoice.jolt.exception.SpecException; | ||
|
||
public abstract class BasePathReference implements PathReference { | ||
|
||
private final int pathIndex; // equals 0 for "&" "&0" and "&(0,x)" | ||
|
||
protected abstract char getToken(); | ||
|
||
public BasePathReference( String refStr ) { | ||
|
||
if ( refStr == null || refStr.length() == 0 || getToken() != refStr.charAt( 0 ) ) { | ||
throw new SpecException( "Invalid reference key=" + refStr + " either blank or doesn't start with correct character=" + getToken() ); | ||
} | ||
|
||
int pathIndex = 0; | ||
|
||
try { | ||
if ( refStr.length() > 1 ) { | ||
|
||
String meat = refStr.substring( 1 ); | ||
|
||
pathIndex = Integer.parseInt( meat ); | ||
} | ||
} | ||
catch( NumberFormatException nfe ) { | ||
throw new SpecException( "Unable to parse '" + getToken() + "' reference key:" + refStr, nfe ); | ||
} | ||
|
||
if ( pathIndex < 0 ) { | ||
throw new SpecException( "Reference:" + refStr + " can not have a negative value." ); | ||
} | ||
|
||
this.pathIndex = pathIndex; | ||
} | ||
|
||
@Override | ||
public int getPathIndex() { | ||
return pathIndex; | ||
} | ||
|
||
/** | ||
* Builds the non-syntactic sugar / maximally expanded and unique form of this reference. | ||
* @return canonical form : aka "#" -> "#0 | ||
*/ | ||
public String getCanonicalForm() { | ||
return getToken() + Integer.toString( pathIndex ); | ||
} | ||
} |
6 changes: 4 additions & 2 deletions
6
jolt-core/src/main/java/com/bazaarvoice/jolt/shiftr/reference/DollarReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
package com.bazaarvoice.jolt.shiftr.reference; | ||
|
||
public class DollarReference extends BaseReference { | ||
public class DollarReference extends BasePathAndGroupReference { | ||
|
||
public static final Character TOKEN = '$'; | ||
|
||
public DollarReference( String refStr ) { | ||
super(refStr); | ||
} | ||
|
||
@Override | ||
protected char getToken() { | ||
return '$'; | ||
return TOKEN; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
jolt-core/src/main/java/com/bazaarvoice/jolt/shiftr/reference/HashReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.bazaarvoice.jolt.shiftr.reference; | ||
|
||
/** | ||
* TODO : Refactor the out to it's own class, as it really isn't a "Reference" | ||
* This is just a cheap hack at the moment. | ||
*/ | ||
public class HashReference extends BasePathReference { | ||
|
||
public static final Character TOKEN = '#'; | ||
|
||
public HashReference( String refStr ) { | ||
super(refStr); | ||
} | ||
|
||
@Override | ||
protected char getToken() { | ||
return TOKEN; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
jolt-core/src/main/java/com/bazaarvoice/jolt/shiftr/reference/PathReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.bazaarvoice.jolt.shiftr.reference; | ||
|
||
|
||
/** | ||
* Reference is used by Shiftr when lookup up values from a WalkedPath (list of LiteralPathElements). | ||
* | ||
* #, #0 are the same | ||
* | ||
* The "canonical form" is "Cx", where : | ||
* C : the character used to determine the type of Reference | ||
* x : pathIndex : which is how far up the walkedPath the look | ||
* | ||
*/ | ||
public interface PathReference { | ||
|
||
public int getPathIndex(); | ||
|
||
/** | ||
* Get the canonical form of this Reference. | ||
* | ||
* One of the uses of this method is to ensure that spec, does not contain "duplicate" keys, aka | ||
* two keys that when you unroll the syntactic sugar, are the same thing. | ||
* | ||
* @return fully expanded String representation of this Reference | ||
*/ | ||
public String getCanonicalForm(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.