1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.graph.query.parse;
25
26 import net.jcip.annotations.Immutable;
27 import org.modeshape.common.text.Position;
28 import org.modeshape.common.util.CheckArg;
29 import org.modeshape.common.util.ObjectUtil;
30 import org.modeshape.graph.query.model.SelectorName;
31
32
33
34
35 @Immutable
36 class ColumnExpression {
37
38 private final SelectorName selectorName;
39 private final String propertyName;
40 private final String columnName;
41 private final Position position;
42
43
44
45
46
47
48
49
50
51 ColumnExpression( SelectorName selectorName,
52 String propertyName,
53 String columnName,
54 Position position ) {
55 CheckArg.isNotNull(propertyName, "propertyName");
56 CheckArg.isNotNull(columnName, "columnName");
57 CheckArg.isNotNull(position, "position");
58 this.selectorName = selectorName;
59 this.propertyName = propertyName;
60 this.columnName = columnName;
61 this.position = position;
62 }
63
64
65
66
67
68
69 public Position getPosition() {
70 return position;
71 }
72
73
74
75
76 public final SelectorName getSelectorName() {
77 return selectorName;
78 }
79
80
81
82
83 public final String getPropertyName() {
84 return propertyName;
85 }
86
87
88
89
90 public final String getColumnName() {
91 return columnName;
92 }
93
94
95
96
97
98
99 @Override
100 public boolean equals( Object obj ) {
101 if (obj == this) return true;
102 if (obj instanceof ColumnExpression) {
103 ColumnExpression that = (ColumnExpression)obj;
104 if (!ObjectUtil.isEqualWithNulls(this.selectorName, that.selectorName)) return false;
105 if (!ObjectUtil.isEqualWithNulls(this.propertyName, that.propertyName)) return false;
106 if (!ObjectUtil.isEqualWithNulls(this.columnName, that.columnName)) return false;
107 return true;
108 }
109 return false;
110 }
111
112
113
114
115
116
117 @Override
118 public String toString() {
119 StringBuilder sb = new StringBuilder();
120 if (selectorName != null) {
121 sb.append(selectorName.name());
122 sb.append('.');
123 }
124 sb.append(propertyName);
125 if (columnName != null) {
126 sb.append(" AS ").append(columnName);
127 }
128 return sb.toString();
129 }
130 }