### Question:
Segment { static String createRegex(final String segment ) { StringBuilder regex = new StringBuilder( segment ); int len = regex.length(); for( int i=len-1; i>=0; i-- ) { char c = regex.charAt( i ); switch( c ) { case '*': regex.insert( i, DOT ); break; case '\\': case '.': case '{': case '}': case '$': regex.insert( i, ESC ); break; default: } } return regex.toString(); } protected  Segment( Token token ); @Override int hashCode(); @Override @SuppressWarnings( "unchecked" ) boolean equals( Object obj ); String getParamName(); Collection<Value> getValues(); Value getFirstValue(); boolean matches( Segment that ); @Override String toString(); static final int STATIC; static final int REGEX; static final int STAR; static final int DEFAULT; static final int GLOB; static final int UNKNOWN; }### Answer:
@Test public void testCreateRegex() { assertThat( Segment.createRegex( "" ), is( "" ) ); assertThat( Segment.createRegex( " " ), is( " " ) ); assertThat( Segment.createRegex( "X" ), is( "X" ) ); assertThat( Segment.createRegex( "$" ), is( "\\$" ) ); assertThat( Segment.createRegex( "{" ), is( "\\{" ) ); assertThat( Segment.createRegex( "}" ), is( "\\}" ) ); assertThat( Segment.createRegex( "$$" ), is( "\\$\\$" ) ); assertThat( Segment.createRegex( "." ), is( "\\." ) ); assertThat( Segment.createRegex( ".." ), is( "\\.\\." ) ); assertThat( Segment.createRegex( "\\" ), is( "\\\\" ) ); assertThat( Segment.createRegex( "*" ), is( ".*" ) ); assertThat( Segment.createRegex( "**" ), is( ".*.*" ) ); assertThat( Segment.createRegex( "\\.${}*" ), is( "\\\\\\.\\$\\{\\}.*" ) ); String input = "/var/lib/oozie/*.jar,/usr/lib/hadoop/client/*.jar,/usr/lib/oozie/libserver/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar"; String expect = "/var/lib/oozie/.*\\.jar,/usr/lib/hadoop/client/.*\\.jar,/usr/lib/oozie/libserver/.*\\.jar,\\$\\{catalina\\.home\\}/lib,\\$\\{catalina\\.home\\}/lib/.*\\.jar"; String output = Segment.createRegex( input ); assertThat( expect, is( output ) ); }