Skip to content

Commit 5a5a91d

Browse files
authored
Merge pull request #142 from rdfjs/fix/equals
Rigorously define equals method on Term and Quad
2 parents aa3df2a + bdd96e1 commit 5a5a91d

File tree

1 file changed

+54
-22
lines changed

1 file changed

+54
-22
lines changed

index.html

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ <h3><dfn>Term</dfn> interface</h3>
131131
interface Term {
132132
attribute string termType;
133133
attribute string value;
134-
boolean equals(Term other);
134+
boolean equals(optional Term? other);
135135
};
136136
</pre>
137137

@@ -148,8 +148,18 @@ <h3><dfn>Term</dfn> interface</h3>
148148
<dfn>value</dfn> is refined by each interface which extends Term.
149149
</p>
150150
<p>
151-
<dfn>equals()</dfn> returns <code>true</code> if and only if <code>other</code> has the same
152-
<code>termType</code> and the same contents (as defined by concrete subclasses).
151+
<dfn>equals()</dfn> returns <code>true</code>
152+
when called with parameter <code>other</code>
153+
on an object <code>term</code> if all of the conditions below hold:
154+
</p>
155+
<ul>
156+
<li><code>other</code> is <em>neither</em> <code>null</code> nor <code>undefined</code>;</li>
157+
<li><code>term.termType</code> is the same string as <code>other.termType</code>;</li>
158+
<li><code>other</code> follows the additional constraints of the specific <code>Term</code> interface implemented by <code>term</code>
159+
(e.g., <a>NamedNode</a>, <a>Literal</a>, …);</li>
160+
</ul>
161+
<p>
162+
otherwise, it returns <code>false</code>.
153163
</p>
154164
</section>
155165

@@ -160,7 +170,7 @@ <h3><dfn>NamedNode</dfn> interface</h3>
160170
interface NamedNode : Term {
161171
attribute string termType;
162172
attribute string value;
163-
boolean equals(Term other);
173+
boolean equals(optional Term? other);
164174
};
165175
</pre>
166176

@@ -171,8 +181,10 @@ <h3><dfn>NamedNode</dfn> interface</h3>
171181
<dfn>value</dfn> the IRI of the named node (example: <code>"http://example.org/resource"</code>).
172182
</p>
173183
<p>
174-
<dfn>equals()</dfn> returns <code>true</code> if and only if <code>other</code> has
175-
<code>termType</code> <code>"NamedNode"</code> and the same <code></code>value</code>.
184+
<dfn>equals()</dfn> returns <code>true</code> if
185+
all general <a>Term.equals</a> conditions hold
186+
and <code>term.value</code> is the same string as <code>other.value</code>;
187+
otherwise, it returns <code>false</code>.
176188
</p>
177189
</section>
178190

@@ -183,7 +195,7 @@ <h3><dfn>BlankNode</dfn> interface</h3>
183195
interface BlankNode : Term {
184196
attribute string termType;
185197
attribute string value;
186-
boolean equals(Term other);
198+
boolean equals(optional Term? other);
187199
};
188200
</pre>
189201

@@ -196,8 +208,10 @@ <h3><dfn>BlankNode</dfn> interface</h3>
196208
sourced from RDF/XML, do not change the blank node name (example: <code>"blank3"</code>)
197209
</p>
198210
<p>
199-
<dfn>equals()</dfn> returns <code>true</code> if and only if <code>other</code> has
200-
<code>termType</code> <code>"BlankNode"</code> and the same <code>value</code>.
211+
<dfn>equals()</dfn> returns <code>true</code> if
212+
all general <a>Term.equals</a> conditions hold
213+
and <code>term.value</code> is the same string as <code>other.value</code>;
214+
otherwise, it returns <code>false</code>.
201215
</p>
202216
</section>
203217

@@ -210,7 +224,7 @@ <h3><dfn>Literal</dfn> interface</h3>
210224
attribute string value;
211225
attribute string language;
212226
attribute NamedNode datatype;
213-
boolean equals(Term other);
227+
boolean equals(optional Term? other);
214228
};
215229
</pre>
216230

@@ -235,9 +249,12 @@ <h3><dfn>Literal</dfn> interface</h3>
235249
<code>"http://www.w3.org/2001/XMLSchema#string"</code>.
236250
</p>
237251
<p>
238-
<dfn>equals()</dfn> returns <code>true</code> if and only if <code>other</code> has
239-
<code>termType</code> <code>"Literal"</code> and the same <code>value</code>,
240-
<code>language</code>, and <code>datatype</code>.
252+
<dfn>equals()</dfn> returns <code>true</code> if
253+
all general <a>Term.equals</a> conditions hold,
254+
<code>term.value</code> is the same string as <code>other.value</code>,
255+
<code>term.language</code> is the same string as <code>other.language</code>, and
256+
<code>term.datatype.equals(other.datatype)</code> evaluates to <code>true</code>;
257+
otherwise, it returns <code>false</code>.
241258
</p>
242259
</section>
243260

@@ -248,7 +265,7 @@ <h3><dfn>Variable</dfn> interface</h3>
248265
interface Variable : Term {
249266
attribute string termType;
250267
attribute string value;
251-
boolean equals(Term other);
268+
boolean equals(optional Term? other);
252269
};
253270
</pre>
254271

@@ -260,8 +277,10 @@ <h3><dfn>Variable</dfn> interface</h3>
260277
<code>"a"</code>).
261278
</p>
262279
<p>
263-
<dfn>equals()</dfn> returns <code>true</code> if and only if <code>other</code> has
264-
<code>termType</code> <code>"Variable"</code> and the same <code>value</code>.
280+
<dfn>equals()</dfn> returns <code>true</code> if
281+
all general <a>Term.equals</a> conditions hold
282+
and <code>term.value</code> is the same string as <code>other.value</code>;
283+
otherwise, it returns <code>false</code>.
265284
</p>
266285
</section>
267286

@@ -272,7 +291,7 @@ <h3><dfn>DefaultGraph</dfn> interface</h3>
272291
interface DefaultGraph : Term {
273292
attribute string termType;
274293
attribute string value;
275-
boolean equals(Term other);
294+
boolean equals(optional Term? other);
276295
};
277296
</pre>
278297

@@ -287,8 +306,9 @@ <h3><dfn>DefaultGraph</dfn> interface</h3>
287306
<dfn>value</dfn> contains an empty string as constant value.
288307
</p>
289308
<p>
290-
<dfn>equals()</dfn> returns <code>true</code> if and only if <code>other</code> has
291-
<code>termType</code> <code>"DefaultGraph"</code>.
309+
<dfn>equals()</dfn> returns <code>true</code> if
310+
all general <a>Term.equals</a> conditions hold;
311+
otherwise, it returns <code>false</code>.
292312
</p>
293313
</section>
294314

@@ -301,7 +321,7 @@ <h3><dfn>Quad</dfn> interface</h3>
301321
attribute Term predicate;
302322
attribute Term object;
303323
attribute Term graph;
304-
boolean equals(Quad other);
324+
boolean equals(optional Quad? other);
305325
};
306326
</pre>
307327

@@ -325,8 +345,20 @@ <h3><dfn>Quad</dfn> interface</h3>
325345
<code>Triple</code> MUST be represented as <code>Quad</code> with <code>graph</code> set to a <code>DefaultGraph</code>
326346
</p>
327347
<p>
328-
<dfn>equals()</dfn> returns <code>true</code> if and only if the argument is a) of the same
329-
type b) has all components equal.
348+
<dfn>equals()</dfn> returns <code>true</code>
349+
when called with parameter <code>other</code>
350+
on an object <code>quad</code> if
351+
all of the conditions below hold:
352+
</p>
353+
<ul>
354+
<li><code>other</code> is <em>neither</em> <code>null</code> nor <code>undefined</code>;</li>
355+
<li><code>quad.subject.equals(other.subject)</code> evaluates to <code>true</code>;</li>
356+
<li><code>quad.predicate.equals(other.predicate)</code> evaluates to <code>true</code>;</li>
357+
<li><code>quad.object.equals(other.object)</code> evaluates to a <code>true</code>;</li>
358+
<li><code>quad.graph.equals(other.graph)</code> evaluates to a <code>true</code>;</li>
359+
</ul>
360+
<p>
361+
otherwise, it returns <code>false</code>.
330362
</p>
331363
</section>
332364

0 commit comments

Comments
 (0)