1919 *
2020 * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
2121 */
22+ import com .ibm .oti .util .regex .Regex ;
2223
23- import java .util .regex .Matcher ;
24- import java .util .regex .Pattern ;
25- import java .util .regex .PatternSyntaxException ;
24+ class Output extends TestCondition {
2625
27- import com .ibm .oti .util .regex .*;
26+ private static boolean evalBoolean (String expr ) {
27+ return !"no" .equalsIgnoreCase (TestSuite .evaluateVariables (expr ));
28+ }
2829
29- class Output extends TestCondition {
30- private String _type ;
31- private String _matchRegex ;
32- private String _matchJavaUtilPattern ;
33- private String _matchCase ;
34- private String _output ; // the output string taken from the file
35- private String _showRegexMatch ;
36-
37- public Output ( String matchRegex , String matchJavaUtilPattern , String showRegexMatch , String matchCase , String type ) {
30+ private final String _type ;
31+ private final String _matchRegex ;
32+ private final String _matchJavaUtilPattern ;
33+ private final String _matchCase ;
34+ private String _output ; // the output string taken from the file
35+ private final String _showRegexMatch ;
36+
37+ public Output (String matchRegex , String matchJavaUtilPattern , String showRegexMatch , String matchCase , String type ) {
3838 _matchRegex = matchRegex ;
3939 _matchJavaUtilPattern = matchJavaUtilPattern ;
4040 _showRegexMatch = showRegexMatch ;
@@ -43,32 +43,32 @@ public Output( String matchRegex, String matchJavaUtilPattern, String showRegexM
4343 _output = "" ;
4444 }
4545
46- void setOutput ( String s ) {
46+ void setOutput (String s ) {
4747 _output = s ;
4848 }
49-
49+
5050 int getType () {
51- return parseType ( TestSuite .evaluateVariables ( _type ) );
51+ return parseType (TestSuite .evaluateVariables (_type ) );
5252 }
53-
53+
5454 public boolean isJavaUtilPattern () {
55- return !( "no" . equalsIgnoreCase ( TestSuite . evaluateVariables ( _matchJavaUtilPattern ) ) );
55+ return evalBoolean ( _matchJavaUtilPattern );
5656 }
57-
58- boolean match ( Object o ) {
57+
58+ boolean match (Object o ) {
5959 String candidate = (String ) o ;
60- boolean matchRegex = !( "no" . equalsIgnoreCase ( TestSuite . evaluateVariables ( _matchRegex )) );
61- boolean matchCase = !( "no" . equalsIgnoreCase ( TestSuite . evaluateVariables ( _matchCase )) );
62- boolean matchJavaUtilPattern = !( "no" . equalsIgnoreCase ( TestSuite . evaluateVariables ( _matchJavaUtilPattern )) );
63- boolean showRegexMatch = !( "no" . equalsIgnoreCase ( TestSuite . evaluateVariables ( _showRegexMatch )) );
60+ boolean matchRegex = evalBoolean ( _matchRegex );
61+ boolean matchCase = evalBoolean ( _matchCase );
62+ boolean matchJavaUtilPattern = evalBoolean ( _matchJavaUtilPattern );
63+ boolean showRegexMatch = evalBoolean ( _showRegexMatch );
6464 String string = TestSuite .evaluateVariables (_output );
6565
66- if (( matchRegex ) && ( !matchJavaUtilPattern ) ) {
66+ if (matchRegex && !matchJavaUtilPattern ) {
6767 try {
6868 Regex regex = new Regex (string , matchCase );
6969 boolean retval = regex .matches (candidate );
70- if ( retval && showRegexMatch ) {
71- System .out .println ("\t Match (" + _type + "): " + candidate );
70+ if ( retval && showRegexMatch ) {
71+ System .out .println ("\t Match (" + _type + "): " + candidate );
7272 }
7373 return retval ;
7474 } catch (Exception e ) {
@@ -77,25 +77,27 @@ boolean match( Object o ) {
7777 e .printStackTrace ();
7878 return false ;
7979 }
80- } else if (( matchRegex ) && ( matchJavaUtilPattern ) ) {
80+ } else if (matchRegex && matchJavaUtilPattern ) {
8181 /* CMVC 163891: Use of java.util.regex.Pattern/Matcher must be in a separate class, to avoid
8282 * problems with the verifier when using the embedded class library.
8383 */
84- return OutputRegexHelper .ContainsMatches (candidate ,string ,matchCase ,showRegexMatch ,_type );
84+ return OutputRegexHelper .ContainsMatches (candidate , string , matchCase , showRegexMatch , _type );
8585 } else {
8686 if (!matchCase ) {
8787 string = string .toLowerCase ();
8888 candidate = candidate .toLowerCase ();
8989 }
90- boolean retval = ( candidate .indexOf (string ) >= 0 );
91- if ( retval && showRegexMatch ) {
92- System .out .println ("\t Match (" + _type + "): " + candidate );
90+ boolean retval = candidate .contains (string );
91+ if ( retval && showRegexMatch ) {
92+ System .out .println ("\t Match (" + _type + "): " + candidate );
9393 }
9494 return retval ;
9595 }
9696 }
97-
97+
98+ @ Override
9899 public String toString () {
99- return "Output match: " + TestSuite .evaluateVariables ( _output );
100+ return "Output match: " + TestSuite .evaluateVariables (_output );
100101 }
102+
101103}
0 commit comments