Skip to content

Commit 1475a5c

Browse files
committed
[new] two three
1 parent 145e6a4 commit 1475a5c

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

common-util/src/main/java/com/vonchange/common/util/Triplet.java renamed to common-util/src/main/java/com/vonchange/common/util/Three.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package com.vonchange.common.util;
22

3-
public class Triplet <A,B,C>{
3+
public class Three<A,B,C>{
44
private final A first;
55
private final B second;
66

77
private final C third;
88

9-
private Triplet(A first, B second,C third) {
9+
private Three(A first, B second, C third) {
1010
this.first = first;
1111
this.second = second;
1212
this.third=third;
1313
}
1414

15-
public static <A, B,C> Triplet<A, B,C> of(A first, B second,C third) {
16-
return new Triplet<>(first, second,third);
15+
public static <A, B,C> Three<A, B,C> of(A first, B second, C third) {
16+
return new Three<>(first, second,third);
1717
}
1818

1919

common-util/src/main/java/com/vonchange/common/util/Pair.java renamed to common-util/src/main/java/com/vonchange/common/util/Two.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
package com.vonchange.common.util;
22

3-
public final class Pair<A, B> {
3+
public final class Two<A, B> {
44

55
private A first;
66
private B second;
77

8-
public Pair(){
8+
public Two(){
99

1010
}
11-
private Pair(A first, B second) {
11+
private Two(A first, B second) {
1212
this.first = first;
1313
this.second = second;
1414
}
1515

1616
/**
17-
* Creates a new {@link Pair} for the given elements.
17+
* Creates a new {@link Two} for the given elements.
1818
*
1919
* @param first must not be {@literal null}.
2020
* @param second must not be {@literal null}.
2121
* @return
2222
*/
23-
public static <A, B> Pair<A, B> of(A first, B second) {
24-
return new Pair<>(first, second);
23+
public static <A, B> Two<A, B> of(A first, B second) {
24+
return new Two<>(first, second);
2525
}
2626

2727
/**
28-
* Returns the first element of the {@link Pair}.
28+
* Returns the first element of the {@link Two}.
2929
*
3030
* @return
3131
*/
@@ -34,7 +34,7 @@ public A getFirst() {
3434
}
3535

3636
/**
37-
* Returns the second element of the {@link Pair}.
37+
* Returns the second element of the {@link Two}.
3838
*
3939
* @return
4040
*/

jdbc-mybatis/src/main/java/com/vonchange/jdbc/core/CrudUtil.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.vonchange.jdbc.core;
22

33
import com.vonchange.common.util.MarkdownUtil;
4-
import com.vonchange.common.util.Pair;
4+
import com.vonchange.common.util.Two;
55
import com.vonchange.common.util.StringPool;
66
import com.vonchange.common.util.UtilAll;
77
import com.vonchange.common.util.bean.BeanUtil;
@@ -106,7 +106,7 @@ public static <T> SqlParam generateUpdateSql(T entity, boolean isNullUpdate, bo
106106
}
107107

108108

109-
public static Pair<String,Collection<?>> conditionSql(QueryColumn queryColumn){
109+
public static Two<String,Collection<?>> conditionSql(QueryColumn queryColumn){
110110
if(null==queryColumn||null==queryColumn.getValue()){
111111
return null;
112112
}
@@ -122,10 +122,10 @@ public static Pair<String,Collection<?>> conditionSql(QueryColumn queryColumn){
122122
if(condition.equals("between")){
123123
return betweenSql(pre,queryColumn.getValue());
124124
}
125-
return Pair.of(pre+StringPool.QUESTION_MARK+StringPool.SPACE,
125+
return Two.of(pre+StringPool.QUESTION_MARK+StringPool.SPACE,
126126
Collections.singleton(queryColumn.getValue()));
127127
}
128-
private static Pair<String,Collection<?>> inSql(String sql, Object value){
128+
private static Two<String,Collection<?>> inSql(String sql, Object value){
129129
if (!(value instanceof Collection ||value.getClass().isArray())){
130130
throw new JdbcMybatisRuntimeException("in query parameter must collection or array");
131131
}
@@ -144,9 +144,9 @@ private static Pair<String,Collection<?>> inSql(String sql, Object value){
144144
collection.add(o);
145145
}
146146
}
147-
return Pair.of(inSb.substring(0,inSb.length()-1)+")",collection);
147+
return Two.of(inSb.substring(0,inSb.length()-1)+")",collection);
148148
}
149-
private static Pair<String,Collection<?>> betweenSql(String sql, Object value) {
149+
private static Two<String,Collection<?>> betweenSql(String sql, Object value) {
150150
if (!(value instanceof Collection||value.getClass().isArray())){
151151
throw new JdbcMybatisRuntimeException("between query parameter must collection or array");
152152
}
@@ -166,7 +166,7 @@ private static Pair<String,Collection<?>> betweenSql(String sql, Object value) {
166166
if(collection.size()>2||collection.size()<1){
167167
throw new JdbcMybatisRuntimeException("between query param error");
168168
}
169-
return Pair.of(betweenSql,collection);
169+
return Two.of(betweenSql,collection);
170170
}
171171

172172
private static String mybatisNamedParam(String fieldName){

jdbc-mybatis/src/main/java/com/vonchange/jdbc/util/NameQueryUtil.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.vonchange.common.util.Assert;
44
import com.vonchange.common.util.ClazzUtils;
5-
import com.vonchange.common.util.Pair;
5+
import com.vonchange.common.util.Two;
66
import com.vonchange.common.util.StringPool;
77
import com.vonchange.common.util.UtilAll;
88
import com.vonchange.common.util.bean.BeanUtil;
@@ -92,8 +92,8 @@ public static String orderSql(String orderBy,Class<?> entityType,EntityInfo enti
9292
}
9393
columnsMap.putAll(orderMap);
9494
int i =0;
95-
List<Pair<String,String>> orderColumn=new ArrayList<>();
96-
Pair<String,String> pair=new Pair<>();
95+
List<Two<String,String>> orderColumn=new ArrayList<>();
96+
Two<String,String> two =new Two<>();
9797
while (i<splits.length) {
9898
String mapKey=splits[i];
9999
i++;
@@ -115,15 +115,15 @@ public static String orderSql(String orderBy,Class<?> entityType,EntityInfo enti
115115
throw new JdbcMybatisRuntimeException("{} can not generate order by",orderBy);
116116
}
117117
if(sqlMatch.getEnumStep().equals(EnumStep.Column)){
118-
pair.setFirst(sqlMatch.getSplit());
118+
two.setFirst(sqlMatch.getSplit());
119119
}
120120
if(sqlMatch.getEnumStep().equals(EnumStep.ORDER)){
121-
pair.setSecond(sqlMatch.getSplit());
122-
orderColumn.add(pair);
123-
pair=new Pair<>();
121+
two.setSecond(sqlMatch.getSplit());
122+
orderColumn.add(two);
123+
two =new Two<>();
124124
}
125125
}
126-
orderColumn.add(pair);
126+
orderColumn.add(two);
127127

128128
return " order by "+orderColumn.stream().filter(item->null!=item.getFirst()).map(item->item.getFirst()+StringPool.SPACE+
129129
(null==item.getSecond()?StringPool.EMPTY:item.getSecond()))
@@ -193,7 +193,7 @@ public static <S> SqlParam exampleSql(EnumNameQueryType enumNameQueryType,
193193
List<Object> values = new ArrayList<>();
194194
List<String> querySql=new ArrayList<>();
195195
QueryColumn queryColumn;
196-
Pair<String,Collection<?>> pair;
196+
Two<String,Collection<?>> two;
197197
for (BaseEntityField baseEntityField : baseEntityFields) {
198198
queryColumn = fieldQuery(example,baseEntityField);
199199
if(null==queryColumn){
@@ -203,9 +203,9 @@ public static <S> SqlParam exampleSql(EnumNameQueryType enumNameQueryType,
203203
orders.add(queryColumn.getColumn());
204204
continue;
205205
}
206-
pair=CrudUtil.conditionSql(queryColumn);
207-
querySql.add(pair.getFirst());
208-
values.addAll(pair.getSecond());
206+
two =CrudUtil.conditionSql(queryColumn);
207+
querySql.add(two.getFirst());
208+
values.addAll(two.getSecond());
209209
}
210210
if(!querySql.isEmpty()){
211211
sql=sql+ " where " + String.join(" and ", querySql);
@@ -323,9 +323,9 @@ public static SqlParam nameSql(String method, Class<?> entityType, List<Object>
323323
for (int columnIndex = 0; columnIndex < queryColumns.size(); columnIndex++) {
324324
QueryColumn queryColumn1= queryColumns.get(columnIndex);
325325
queryColumn1.setValue(params.get(columnIndex));
326-
Pair<String,Collection<?>> pair = CrudUtil.conditionSql(queryColumn1);
327-
sqlBuilder.append(pair.getFirst());
328-
values.addAll(pair.getSecond());
326+
Two<String,Collection<?>> two = CrudUtil.conditionSql(queryColumn1);
327+
sqlBuilder.append(two.getFirst());
328+
values.addAll(two.getSecond());
329329
}
330330

331331
log.debug("gen sql {}",sqlBuilder);

0 commit comments

Comments
 (0)