1111
1212import java .util .ArrayList ;
1313import java .util .List ;
14-
1514import net .sf .jsqlparser .expression .BinaryExpression ;
1615import net .sf .jsqlparser .expression .Expression ;
1716import net .sf .jsqlparser .expression .NotExpression ;
2221class CloneHelper {
2322
2423 public Expression modify (Expression express ) {
25- if (express instanceof NotExpression ) {
24+ if (express instanceof NotExpression ) {
2625 return new NotExpression (modify (((NotExpression ) express ).getExpression ()));
2726 }
28- if (express instanceof Parenthesis ) {
27+ if (express instanceof Parenthesis ) {
2928 Parenthesis parenthesis = (Parenthesis ) express ;
3029 Expression result = modify (parenthesis .getExpression ());
31- if (parenthesis .isNot ()) {
32- return new NotExpression (result );
33- }
3430 return result ;
3531 }
36- if (express instanceof AndExpression ) {
32+ if (express instanceof AndExpression ) {
3733 AndExpression and = (AndExpression ) express ;
3834 List <Expression > list = new ArrayList <Expression >();
3935 list .add (modify (and .getLeftExpression ()));
4036 list .add (modify (and .getRightExpression ()));
4137 MultiAndExpression result = new MultiAndExpression (list );
42- if (and .isNot ()) {
38+ if (and .isNot ()) {
4339 return new NotExpression (result );
4440 }
4541 return result ;
4642 }
47- if (express instanceof OrExpression ) {
43+ if (express instanceof OrExpression ) {
4844 OrExpression or = (OrExpression ) express ;
4945 List <Expression > list = new ArrayList <Expression >();
5046 list .add (modify (or .getLeftExpression ()));
5147 list .add (modify (or .getRightExpression ()));
5248 MultiOrExpression result = new MultiOrExpression (list );
53- if (or .isNot ()) {
49+ if (or .isNot ()) {
5450 return new NotExpression (result );
5551 }
5652 return result ;
5753 }
58- if (express instanceof BinaryExpression ) {
54+ if (express instanceof BinaryExpression ) {
5955 BinaryExpression binary = (BinaryExpression ) express ;
60- if (binary .isNot ()) {
56+ if (binary .isNot ()) {
6157 binary .removeNot ();
6258 return new NotExpression (modify (binary ));
63- }
59+ }
6460 }
6561 return express ;
6662 }
67-
63+
6864 /**
69- * This method is used to copy the expression which happens at
70- * step four. I only copy the conditional expressions since the
71- * CNF only changes the conditional part.
65+ * This method is used to copy the expression which happens at step four. I only copy the
66+ * conditional expressions since the CNF only changes the conditional part.
67+ *
7268 * @param express the expression that will be copied.
7369 * @return the copied expression.
7470 */
7571 public Expression shallowCopy (Expression express ) {
76- if (express instanceof MultipleExpression ) {
72+ if (express instanceof MultipleExpression ) {
7773 MultipleExpression multi = (MultipleExpression ) express ;
7874 List <Expression > list = new ArrayList <Expression >();
79- for (int i = 0 ; i < multi .size (); i ++) {
75+ for (int i = 0 ; i < multi .size (); i ++) {
8076 list .add (shallowCopy (multi .getChild (i )));
8177 }
82- if (express instanceof MultiAndExpression ) {
78+ if (express instanceof MultiAndExpression ) {
8379 return new MultiAndExpression (list );
8480 }
8581 /* since there only two possibilities of the multiple expression,
@@ -88,33 +84,34 @@ public Expression shallowCopy(Expression express) {
8884 }
8985 return express ;
9086 }
91-
87+
9288 /**
93- * This helper method is used to change the multiple expression into
94- * the binary form, respectively and return the root of the expression tree.
89+ * This helper method is used to change the multiple expression into the binary form,
90+ * respectively and return the root of the expression tree.
91+ *
9592 * @param isMultiOr variable tells whether the expression is or.
9693 * @param exp the expression that needs to be converted.
9794 * @return the root of the expression tree.
9895 */
9996 public Expression changeBack (Boolean isMultiOr , Expression exp ) {
100- if (!(exp instanceof MultipleExpression )) {
97+ if (!(exp instanceof MultipleExpression )) {
10198 return exp ;
10299 }
103100 MultipleExpression changed = (MultipleExpression ) exp ;
104101 Expression result = changed .getChild (0 );
105- for (int i = 1 ; i < changed .size (); i ++) {
102+ for (int i = 1 ; i < changed .size (); i ++) {
106103 Expression left = result ;
107104 Expression right = changed .getChild (i );
108- if (isMultiOr ) {
105+ if (isMultiOr ) {
109106 result = new OrExpression (left , right );
110107 } else {
111108 result = new AndExpression (left , right );
112109 }
113110 }
114- if (isMultiOr ) {
111+ if (isMultiOr ) {
115112 return new Parenthesis (result );
116113 }
117114 return result ;
118115 }
119-
116+
120117}
0 commit comments