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 public abstract class SimpleNode<T> extends LeafNode
35 {
36
37 protected Value<T> value;
38
39
40 public static final boolean EVAL_GREATER = true;
41
42
43 public static final boolean EVAL_LESSER = false;
44
45
46
47
48
49
50
51
52
53 protected SimpleNode( String attribute, Value<T> value, AssertionType assertionType )
54 {
55 super( attribute, assertionType );
56 this.value = value;
57 }
58
59
60
61
62
63
64
65
66
67 protected SimpleNode( AttributeType attributeType, Value<T> value, AssertionType assertionType )
68 {
69 super( attributeType, assertionType );
70 this.value = value;
71 }
72
73
74
75
76
77 @SuppressWarnings("unchecked")
78 @Override
79 public ExprNode clone()
80 {
81 ExprNode clone = super.clone();
82
83
84 ( ( SimpleNode<T> ) clone ).value = value.clone();
85
86 return clone;
87 }
88
89
90
91
92
93
94
95 public final Value<T> getValue()
96 {
97 return value;
98 }
99
100
101
102
103
104 public Value<?> getEscapedValue()
105 {
106 return escapeFilterValue( value );
107 }
108
109
110
111
112
113
114
115 public void setValue( Value<T> value )
116 {
117 this.value = value;
118 }
119
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 public StringBuilder printRefinementToBuffer( StringBuilder buf )
150 {
151 if ( isSchemaAware )
152 {
153 if ( !attributeType.getOid().equals( SchemaConstants.OBJECT_CLASS_AT_OID ) )
154 {
155 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04162, attribute ) );
156 }
157 }
158 else
159 {
160 if ( ( attribute == null )
161 || !( SchemaConstants.OBJECT_CLASS_AT.equalsIgnoreCase( attribute )
162 || SchemaConstants.OBJECT_CLASS_AT_OID.equalsIgnoreCase( attribute ) ) )
163 {
164 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04162, attribute ) );
165 }
166 }
167
168 buf.append( "item: " ).append( value );
169
170 return buf;
171 }
172
173
174
175
176
177
178 public int hashCode()
179 {
180 int h = 37;
181
182 h = h * 17 + super.hashCode();
183 h = h * 17 + ( value == null ? 0 : value.hashCode() );
184
185 return h;
186 }
187
188
189
190
191
192 public boolean equals( Object other )
193 {
194 if ( this == other )
195 {
196 return true;
197 }
198
199 if ( !( other instanceof SimpleNode<?> ) )
200 {
201 return false;
202 }
203
204 if ( other.getClass() != this.getClass() )
205 {
206 return false;
207 }
208
209 if ( !super.equals( other ) )
210 {
211 return false;
212 }
213
214 SimpleNode<?> otherNode = ( SimpleNode<?> ) other;
215
216 if ( value == null )
217 {
218 return otherNode.value == null;
219 }
220 else
221 {
222 return value.equals( otherNode.value );
223 }
224 }
225 }