public static PathElement parseSingleKeyLHS ( String origKey ) { String elementKey ; // the String to use to actually make Elements String keyToInspect ; // the String to use to determine which kind of Element to create if ( origKey . contains ( "\\" ) ) { // only do the extra work of processing for escaped chars, if there is one. keyToInspect = removeEscapedValues ( origKey ) ; elementKey = removeEscapeChars ( origKey ) ; } else { keyToInspect = origKey ; elementKey = origKey ; } //// LHS single values if ( "@" . equals ( keyToInspect ) ) { return new AtPathElement ( elementKey ) ; } else if ( "*" . equals ( keyToInspect ) ) { return new StarAllPathElement ( elementKey ) ; } else if ( keyToInspect . startsWith ( "[" ) ) { if ( StringTools . countMatches ( keyToInspect , "[" ) != 1 || StringTools . countMatches ( keyToInspect , "]" ) != 1 ) { throw new SpecException ( "Invalid key:" + origKey + " has too many [] references." ) ; } return new ArrayPathElement ( elementKey ) ; } //// LHS multiple values else if ( keyToInspect . startsWith ( "@" ) || keyToInspect . contains ( "@(" ) ) { // The traspose path element gets the origKey so that it has it's escapes. return TransposePathElement . parse ( origKey ) ; } else if ( keyToInspect . contains ( "@" ) ) { throw new SpecException ( "Invalid key:" + origKey + " can not have an @ other than at the front." ) ; } else if ( keyToInspect . contains ( "$" ) ) { return new DollarPathElement ( elementKey ) ; } else if ( keyToInspect . contains ( "[" ) ) { if ( StringTools . countMatches ( keyToInspect , "[" ) != 1 || StringTools . countMatches ( keyToInspect , "]" ) != 1 ) { throw new SpecException ( "Invalid key:" + origKey + " has too many [] references." ) ; } return new ArrayPathElement ( elementKey ) ; } else if ( keyToInspect . contains ( "&" ) ) { if ( keyToInspect . contains ( "*" ) ) { throw new SpecException ( "Invalid key:" + origKey + ", Can't mix * with & ) " ) ; } return new AmpPathElement ( elementKey ) ; } else if ( keyToInspect . contains ( "*" ) ) { int numOfStars = StringTools . countMatches ( keyToInspect , "*" ) ; if ( numOfStars == 1 ) { return new StarSinglePathElement ( elementKey ) ; } else if ( numOfStars == 2 ) { return new StarDoublePathElement ( elementKey ) ; } else { return new StarRegexPathElement ( elementKey ) ; } } else if ( keyToInspect . contains ( "#" ) ) { return new HashPathElement ( elementKey ) ; } else { return new LiteralPathElement ( elementKey ) ; } }
Visible for Testing .