33import java .util .List ;
44
55import org .apache .commons .lang3 .tuple .ImmutablePair ;
6+ import org .apache .commons .lang3 .tuple .ImmutableTriple ;
7+ import org .rest .common .ClientOperation ;
68
79import com .google .common .base .Preconditions ;
810import com .google .common .collect .Lists ;
@@ -22,7 +24,7 @@ private SearchCommonUtil(){
2224 }
2325
2426 //
25- public static List < ImmutablePair < String , ? >> parseQueryString ( final String queryString ){
27+ public static List < ImmutablePair < String , ? >> parseQueryStringOld ( final String queryString ){
2628 Preconditions .checkNotNull ( queryString );
2729 Preconditions .checkState ( queryString .matches ( "(id~?=[0-9]+)?,?(name~?=[0-9a-zA-Z]+)?" ) );
2830
@@ -37,6 +39,43 @@ private SearchCommonUtil(){
3739 return tuplesList ;
3840 }
3941
42+ public static List < ImmutableTriple < String , ClientOperation , ? >> parseQueryString ( final String queryString ){
43+ Preconditions .checkNotNull ( queryString );
44+ Preconditions .checkState ( queryString .matches ( "((id~?=[0-9]+)?,?)*((name~?=[0-9a-zA-Z]+),?)*" ) );
45+
46+ final List < ImmutableTriple < String , ClientOperation , ? >> tuplesList = Lists .newArrayList ();
47+ final String [] tuples = queryString .split ( SEPARATOR );
48+ for ( final String tuple : tuples ){
49+ final String [] keyAndValue = tuple .split ( OP );
50+ Preconditions .checkState ( keyAndValue .length == 2 );
51+ tuplesList .add ( constructTriple ( keyAndValue [0 ], keyAndValue [1 ] ) );
52+ }
53+
54+ return tuplesList ;
55+ }
56+
57+ public static ImmutableTriple < String , ClientOperation , ? > constructTriple ( final String key , final String value ){
58+ boolean negated = false ;
59+ if ( key .endsWith ( NEGATION ) ){
60+ negated = true ;
61+ }
62+
63+ if ( key .startsWith ( ID ) ){
64+ if ( negated ){
65+ return new ImmutableTriple < String , ClientOperation , Long >( key .substring ( 0 , key .length () - 1 ), ClientOperation .NEG_EQ , Long .parseLong ( value ) );
66+ }
67+ return new ImmutableTriple < String , ClientOperation , Long >( key , ClientOperation .EQ , Long .parseLong ( value ) );
68+ }
69+ else if ( key .startsWith ( NAME ) ){
70+ if ( negated ){
71+ return new ImmutableTriple < String , ClientOperation , String >( key .substring ( 0 , key .length () - 1 ), ClientOperation .NEG_EQ , value );
72+ }
73+ return new ImmutableTriple < String , ClientOperation , String >( key , ClientOperation .EQ , value );
74+ }
75+
76+ return null ;
77+ }
78+
4079 private static ImmutablePair < String , ? > constructTuple ( final String key , final String value ){
4180 if ( key .endsWith ( ID ) ){
4281 return new ImmutablePair < String , Long >( key , Long .parseLong ( value ) );
0 commit comments