1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shardingsphere.encrypt.rewrite.token.pojo;
19
20 import lombok.Getter;
21 import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
22 import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.Substitutable;
23
24 import java.util.Collection;
25 import java.util.Map;
26 import java.util.Objects;
27
28
29
30
31 public final class EncryptPredicateFunctionRightValueToken extends SQLToken implements Substitutable {
32
33 @Getter
34 private final int stopIndex;
35
36 private final String functionName;
37
38 private final Map<Integer, Object> indexValues;
39
40 private final Collection<Integer> paramMarkerIndexes;
41
42 public EncryptPredicateFunctionRightValueToken(final int startIndex, final int stopIndex, final String functionName,
43 final Map<Integer, Object> indexValues, final Collection<Integer> paramMarkerIndexes) {
44 super(startIndex);
45 this.stopIndex = stopIndex;
46 this.functionName = functionName;
47 this.indexValues = indexValues;
48 this.paramMarkerIndexes = paramMarkerIndexes;
49 }
50
51 @Override
52 public String toString() {
53 StringBuilder result = new StringBuilder();
54 result.append(functionName).append(" (");
55 for (int i = 0; i < indexValues.size() + paramMarkerIndexes.size(); i++) {
56 if (paramMarkerIndexes.contains(i)) {
57 result.append('?');
58 } else {
59 if (indexValues.get(i) instanceof String) {
60 result.append('\'').append(indexValues.get(i)).append('\'');
61 } else {
62 result.append(indexValues.get(i));
63 }
64 }
65 result.append(", ");
66 }
67 result.delete(result.length() - 2, result.length()).append(')');
68 return result.toString();
69 }
70
71 @Override
72 public boolean equals(final Object obj) {
73 return obj instanceof EncryptPredicateFunctionRightValueToken && ((EncryptPredicateFunctionRightValueToken) obj).getStartIndex() == getStartIndex()
74 && ((EncryptPredicateFunctionRightValueToken) obj).getStopIndex() == stopIndex && ((EncryptPredicateFunctionRightValueToken) obj).indexValues.equals(indexValues)
75 && ((EncryptPredicateFunctionRightValueToken) obj).paramMarkerIndexes.equals(paramMarkerIndexes);
76 }
77
78 @Override
79 public int hashCode() {
80 return Objects.hash(getStartIndex(), stopIndex, indexValues, paramMarkerIndexes);
81 }
82 }