And.java

biz/hammurapi/sql/syntax/And.java

Violations

Inspector Message Severity Location
Java Inspector 048 Copyrights information should be present in each file. 1
Java Inspector 086 Use equals() instead of == or != to compare objects. 1 75:32
Java Inspector 015 Do not change parameter value. For comprehensibility, formal parameters should be final 2 34:25
Java Inspector 073 [java.lang.StringBuffer] In Java 5 use StringBuilder instead of StringBuffer if access is single-threaded, e.g. StringBuffer is used as a local variable . 2 41:17
Java Inspector 082 Parenthesis are redundant. 2 66:36
Java Inspector 089 Undocumented top level type 2 11:1
Java Inspector 089 Undocumented constructor 2 15:9
Java Inspector 089 Undocumented constructor 2 19:9
Java Inspector 089 Undocumented constructor 2 23:9
Java Inspector 089 Undocumented method 2 27:9
Java Inspector 089 Undocumented method 2 31:9
Java Inspector 089 Undocumented method 2 40:9
Java Inspector 089 Undocumented method 2 62:9
Java Inspector 089 Undocumented method 2 70:9
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 72:25
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 74:25
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 76:25
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 80:33
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 82:25
Java Inspector 025 Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] 3 63:35
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 46:44
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 48:44
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 54:44
Java Inspector 051 It is good practice to call in any case super() in a constructor. 3 15:9
Java Inspector 051 It is good practice to call in any case super() in a constructor. 3 19:9
Java Inspector 051 It is good practice to call in any case super() in a constructor. 3 23:9

Source code

1package biz.hammurapi.sql.syntax;
2
3import java.io.Serializable;
4import java.sql.PreparedStatement;
5import java.sql.SQLException;
6import java.util.ArrayList;
7import java.util.Arrays;
8import java.util.Iterator;
9import java.util.List;
10
11public class And implements StatementFragment, Serializable {
12
13 private List fragments = new ArrayList();
14
15 public And(List fragments) {
16 this.fragments.addAll(fragments);
17 }
18
19 public And(StatementFragment[] fragments) {
20 this.fragments.addAll(Arrays.asList(fragments));
21 }
22
23 public And() {
24 // Empty AND
25 }
26
27 public void add(StatementFragment fragment) {
28 fragments.add(fragment);
29 }
30
31 public int parameterize(PreparedStatement statement, int idx) throws SQLException {
32 Iterator it = fragments.iterator();
33 while (it.hasNext()) {
34 idx = ((StatementFragment) it.next()).parameterize(statement, idx);
35 }
36
37 return idx;
38 }
39
40 public String toSqlString() {
41 StringBuffer ret = new StringBuffer();
42 Iterator it = fragments.iterator();
43 while (it.hasNext()) {
44 Object next = it.next();
45 if (next instanceof Or) {
46 ret.append("(");
47 ret.append(((Or) next).toSqlString());
48 ret.append(")");
49 } else {
50 ret.append(((StatementFragment) next).toSqlString());
51 }
52
53 if (it.hasNext()) {
54 ret.append(" AND ");
55 }
56
57 }
58
59 return ret.toString();
60 }
61
62 public int hashCode() {
63 final int prime = 31;
64 int result = 1;
65 result = prime * result
66 + ((fragments == null) ? 0 : fragments.hashCode());
67 return result;
68 }
69
70 public boolean equals(Object obj) {
71 if (this == obj)
72 return true;
73 if (obj == null)
74 return false;
75 if (getClass() != obj.getClass())
76 return false;
77 final And other = (And) obj;
78 if (fragments == null) {
79 if (other.fragments != null)
80 return false;
81 } else if (!fragments.equals(other.fragments))
82 return false;
83 return true;
84 }
85}
86