@@ -34,13 +34,15 @@ public class In extends AbstractSegment implements Condition {
34
34
35
35
private final Expression left ;
36
36
private final Collection <Expression > expressions ;
37
+ private final boolean notIn ;
37
38
38
- private In (Expression left , Collection <Expression > expressions ) {
39
+ private In (Expression left , Collection <Expression > expressions , boolean notIn ) {
39
40
40
41
super (toArray (left , expressions ));
41
42
42
43
this .left = left ;
43
44
this .expressions = expressions ;
45
+ this .notIn = notIn ;
44
46
}
45
47
46
48
private static Segment [] toArray (Expression expression , Collection <Expression > expressions ) {
@@ -69,7 +71,7 @@ public static In create(Expression columnOrExpression, Expression arg) {
69
71
Assert .notNull (columnOrExpression , "Comparison column or expression must not be null" );
70
72
Assert .notNull (arg , "Expression argument must not be null" );
71
73
72
- return new In (columnOrExpression , Collections .singletonList (arg ));
74
+ return new In (columnOrExpression , Collections .singletonList (arg ), false );
73
75
}
74
76
75
77
/**
@@ -84,7 +86,7 @@ public static In create(Expression columnOrExpression, Collection<? extends Expr
84
86
Assert .notNull (columnOrExpression , "Comparison column or expression must not be null" );
85
87
Assert .notNull (expressions , "Expression argument must not be null" );
86
88
87
- return new In (columnOrExpression , new ArrayList <>(expressions ));
89
+ return new In (columnOrExpression , new ArrayList <>(expressions ), false );
88
90
}
89
91
90
92
/**
@@ -99,7 +101,58 @@ public static In create(Expression columnOrExpression, Expression... expressions
99
101
Assert .notNull (columnOrExpression , "Comparison column or expression must not be null" );
100
102
Assert .notNull (expressions , "Expression argument must not be null" );
101
103
102
- return new In (columnOrExpression , Arrays .asList (expressions ));
104
+ return new In (columnOrExpression , Arrays .asList (expressions ), false );
105
+ }
106
+
107
+ /**
108
+ * Creates a new {@link In} {@link Condition} given left and right {@link Expression}s.
109
+ *
110
+ * @param columnOrExpression left hand side of the {@link Condition} must not be {@literal null}.
111
+ * @param arg right hand side (collection {@link Expression}) must not be {@literal null}.
112
+ * @return the {@link In} {@link Condition}.
113
+ */
114
+ public static In createNotIn (Expression columnOrExpression , Expression arg ) {
115
+
116
+ Assert .notNull (columnOrExpression , "Comparison column or expression must not be null" );
117
+ Assert .notNull (arg , "Expression argument must not be null" );
118
+
119
+ return new In (columnOrExpression , Collections .singletonList (arg ), true );
120
+ }
121
+
122
+ /**
123
+ * Creates a new {@link In} {@link Condition} given left and right {@link Expression}s.
124
+ *
125
+ * @param columnOrExpression left hand side of the {@link Condition} must not be {@literal null}.
126
+ * @param expressions right hand side (collection {@link Expression}) must not be {@literal null}.
127
+ * @return the {@link In} {@link Condition}.
128
+ */
129
+ public static In createNotIn (Expression columnOrExpression , Collection <? extends Expression > expressions ) {
130
+
131
+ Assert .notNull (columnOrExpression , "Comparison column or expression must not be null" );
132
+ Assert .notNull (expressions , "Expression argument must not be null" );
133
+
134
+ return new In (columnOrExpression , new ArrayList <>(expressions ), true );
135
+ }
136
+
137
+ /**
138
+ * Creates a new {@link In} {@link Condition} given left and right {@link Expression}s.
139
+ *
140
+ * @param columnOrExpression left hand side of the {@link Condition} must not be {@literal null}.
141
+ * @param expressions right hand side (collection {@link Expression}) must not be {@literal null}.
142
+ * @return the {@link In} {@link Condition}.
143
+ */
144
+ public static In createNotIn (Expression columnOrExpression , Expression ... expressions ) {
145
+
146
+ Assert .notNull (columnOrExpression , "Comparison column or expression must not be null" );
147
+ Assert .notNull (expressions , "Expression argument must not be null" );
148
+
149
+ return new In (columnOrExpression , Arrays .asList (expressions ), true );
150
+ }
151
+
152
+ @ Override
153
+ public Condition not () {
154
+
155
+ return new In (left , expressions , !notIn );
103
156
}
104
157
105
158
/*
@@ -108,6 +161,10 @@ public static In create(Expression columnOrExpression, Expression... expressions
108
161
*/
109
162
@ Override
110
163
public String toString () {
111
- return left + " IN (" + StringUtils .collectionToDelimitedString (expressions , ", " ) + ")" ;
164
+ return left + (notIn ? " NOT" : "" ) + " IN (" + StringUtils .collectionToDelimitedString (expressions , ", " ) + ")" ;
165
+ }
166
+
167
+ public boolean isNotIn () {
168
+ return notIn ;
112
169
}
113
170
}
0 commit comments