1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.model.filter;
21
22
23 import org.apache.directory.api.i18n.I18n;
24 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
25 import org.apache.directory.api.ldap.model.entry.Value;
26 import org.apache.directory.api.ldap.model.schema.AttributeType;
27
28
29
30
31
32
33
34
35
36 public abstract class SimpleNode<T> extends LeafNode
37 {
38
39 protected Value<T> value;
40
41
42 public static final boolean EVAL_GREATER = true;
43
44
45 public static final boolean EVAL_LESSER = false;
46
47
48
49
50
51
52
53
54
55 protected SimpleNode( String attribute, Value<T> value, AssertionType assertionType )
56 {
57 super( attribute, assertionType );
58 this.value = value;
59 }
60
61
62
63
64
65
66
67
68
69 protected SimpleNode( AttributeType attributeType, Value<T> value, AssertionType assertionType )
70 {
71 super( attributeType, assertionType );
72 this.value = value;
73 }
74
75
76
77
78
79 @SuppressWarnings("unchecked")
80 @Override
81 public ExprNode clone()
82 {
83 ExprNode clone = super.clone();
84
85
86 ( ( SimpleNode<T> ) clone ).value = value.clone();
87
88 return clone;
89 }
90
91
92
93
94
95
96
97 public final Value<T> getValue()
98 {
99 return value;
100 }
101
102
103
104
105
106 public Value<?> getEscapedValue()
107 {
108 return escapeFilterValue( value );
109 }
110
111
112
113
114
115
116
117 public void setValue( Value<T> value )
118 {
119 this.value = value;
120 }
121
122
123
124
125
126
127
128
129 public StringBuilder printToBuffer( StringBuilder buf )
130 {
131 if ( ( null != getAnnotations() ) && getAnnotations().containsKey( "count" ) )
132 {
133 buf.append( ":[" );
134 buf.append( getAnnotations().get( "count" ).toString() );
135 buf.append( "] " );
136 }
137
138 buf.append( ')' );
139
140 return buf;
141 }
142
143
144
145
146
147
148
149 @Override
150 public StringBuilder printRefinementToBuffer( StringBuilder buf )
151 {
152 if ( isSchemaAware )
153 {
154 if ( !attributeType.getOid().equals( SchemaConstants.OBJECT_CLASS_AT_OID ) )
155 {
156 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04162, attribute ) );
157 }
158 }
159 else
160 {
161 if ( ( attribute == null )
162 || !( SchemaConstants.OBJECT_CLASS_AT.equalsIgnoreCase( attribute )
163 || SchemaConstants.OBJECT_CLASS_AT_OID.equalsIgnoreCase( attribute ) ) )
164 {
165 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04162, attribute ) );
166 }
167 }
168
169 buf.append( "item: " ).append( value );
170
171 return buf;
172 }
173
174
175
176
177
178
179 @Override
180 public int hashCode()
181 {
182 int h = 37;
183
184 h = h * 17 + super.hashCode();
185 h = h * 17 + ( value == null ? 0 : value.hashCode() );
186
187 return h;
188 }
189
190
191
192
193
194 @Override
195 public boolean equals( Object other )
196 {
197 if ( this == other )
198 {
199 return true;
200 }
201
202 if ( !( other instanceof SimpleNode<?> ) )
203 {
204 return false;
205 }
206
207 if ( other.getClass() != this.getClass() )
208 {
209 return false;
210 }
211
212 if ( !super.equals( other ) )
213 {
214 return false;
215 }
216
217 SimpleNode<?> otherNode = ( SimpleNode<?> ) other;
218
219 if ( value == null )
220 {
221 return otherNode.value == null;
222 }
223 else
224 {
225 return value.equals( otherNode.value );
226 }
227 }
228 }