private static TransposePathElement innerParse ( String originalKey , String meat ) { char first = meat . charAt ( 0 ) ; if ( Character . isDigit ( first ) ) { // loop until we find a comma or end of string StringBuilder sb = new StringBuilder ( ) . append ( first ) ; for ( int index = 1 ; index < meat . length ( ) ; index ++ ) { char c = meat . charAt ( index ) ; // when we find a / the first comma, stop looking for integers, and just assume the rest is a String path if ( ' ' == c ) { int upLevel ; try { upLevel = Integer . valueOf ( sb . toString ( ) ) ; } catch ( NumberFormatException nfe ) { // I don't know how this exception would get thrown, as all the chars were checked by isDigit, but oh well throw new SpecException ( "@ path element with non/mixed numeric key is not valid, key=" + originalKey ) ; } return new TransposePathElement ( originalKey , upLevel , meat . substring ( index + 1 ) ) ; } else if ( Character . isDigit ( c ) ) { sb . append ( c ) ; } else { throw new SpecException ( "@ path element with non/mixed numeric key is not valid, key=" + originalKey ) ; } } // if we got out of the for loop, then the whole thing was a number. return new TransposePathElement ( originalKey , Integer . valueOf ( sb . toString ( ) ) , null ) ; } else { return new TransposePathElement ( originalKey , 0 , meat ) ; } }
Parse the core of the TransposePathElement key once basic errors have been checked and syntax has been handled .