]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/utils/OrderedSetUtils.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / utils / OrderedSetUtils.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.db.common.utils;\r
13 \r
14 import java.util.ArrayList;\r
15 import java.util.Collection;\r
16 import java.util.Collections;\r
17 import java.util.HashSet;\r
18 import java.util.List;\r
19 import java.util.ListIterator;\r
20 import java.util.Set;\r
21 \r
22 import org.simantics.databoard.Bindings;\r
23 import org.simantics.db.AsyncReadGraph;\r
24 import org.simantics.db.ReadGraph;\r
25 import org.simantics.db.Resource;\r
26 import org.simantics.db.WriteGraph;\r
27 import org.simantics.db.WriteOnlyGraph;\r
28 import org.simantics.db.common.request.ReadRequest;\r
29 import org.simantics.db.exception.DatabaseException;\r
30 import org.simantics.db.exception.RuntimeDatabaseException;\r
31 import org.simantics.db.exception.ValidationException;\r
32 import org.simantics.db.function.DbFunction;\r
33 import org.simantics.db.procedure.AsyncMultiProcedure;\r
34 import org.simantics.layer0.Layer0;\r
35 import org.simantics.utils.datastructures.Pair;\r
36 \r
37 public class OrderedSetUtils {\r
38 \r
39     /**\r
40      * Returns true, if <tt>l</tt> contains the element <tt>el</tt>.\r
41      */\r
42     public static boolean contains(ReadGraph g, Resource l, Resource el) throws DatabaseException {\r
43         return g.hasStatement(el, l) && !l.equals(el);\r
44     }\r
45 \r
46     /**\r
47      * Returns the next element in the ordered set or <tt>l</tt>,\r
48      * if <tt>el</tt> is the last element. Called for <tt>el</tt>, returns\r
49      * the first element in the set.\r
50      */\r
51     public static Resource next(ReadGraph g, Resource l, Resource el) throws DatabaseException {\r
52         Collection<Resource> nexts = g.getObjects(el, l);\r
53         if(nexts.size() != 1)\r
54             throw new InvalidOrderedSetException("Invalid list element: " + l + " " + el + " " + nexts.size() + " successors.");\r
55         for(Resource r : nexts)\r
56             return r;\r
57         return null;\r
58     }\r
59 \r
60     public static void forNext(AsyncReadGraph g, final Resource l, Resource el, final AsyncMultiProcedure<Resource> procedure) {\r
61         g.forEachObject(el, l, new AsyncMultiProcedure<Resource>() {\r
62 \r
63             @Override\r
64             public void exception(AsyncReadGraph graph, Throwable t) {\r
65                 procedure.exception(graph, t);\r
66             }\r
67 \r
68             @Override\r
69             public void finished(AsyncReadGraph graph) {\r
70             }\r
71 \r
72             @Override\r
73             public void execute(AsyncReadGraph graph, Resource nel) {\r
74                 if(!nel.equals(l)) {\r
75                     procedure.execute(graph, nel);\r
76                     forNext(graph, l, nel, procedure);\r
77                 }\r
78             }\r
79         });\r
80 //        Collection<Resource> nexts = g.getObjects(el, l);\r
81 //        if(nexts.size() != 1)\r
82 //            throw new NoSingleResultException("Invalid list element: " + nexts.size() + " successors.");\r
83 //        for(Resource r : nexts)\r
84 //            return r;\r
85 //        return null;\r
86     }\r
87 \r
88     /**\r
89      * Returns the previouse element in the ordered set or <tt>l</tt>,\r
90      * if <tt>el</tt> is the first element. Called for <tt>el</tt>, returns\r
91      * the last element in the set.\r
92      */\r
93     public static Resource prev(ReadGraph g, Resource l, Resource el) throws DatabaseException {\r
94         Collection<Resource> prevs = g.getObjects(el, g.getInverse(l));\r
95         if(prevs.size() != 1) {\r
96             throw new InvalidOrderedSetException("Invalid list element, " + prevs.size() + " predecessors.");\r
97         }\r
98         for(Resource r : prevs)\r
99             return r;\r
100         return null;\r
101     }\r
102 \r
103     /**\r
104      * Adds a given elements <tt>el</tt> to the list <tt>l</tt>. Returns\r
105      * true, if the element was really added.\r
106      */\r
107     public static boolean add(WriteGraph g, Resource l, Resource el) throws DatabaseException {\r
108         if(g.hasStatement(el, l))\r
109             return false;\r
110         Resource back = prev(g, l, l);\r
111         g.denyStatement(back, l, l);\r
112         g.claim(back, l, el);\r
113         g.claim(el, l, l);\r
114         return true;\r
115     }\r
116 \r
117     /**\r
118      * Adds a given elements <tt>el</tt> to the list <tt>l</tt>. Returns\r
119      * true, if the element was really added.\r
120      */\r
121     public static boolean addFirst(WriteGraph g, Resource l, Resource el) throws DatabaseException {\r
122         return addAfter(g, l, l, el);\r
123     }\r
124 \r
125     public static boolean addAll(WriteGraph g, Resource l, Iterable<Resource> els) throws DatabaseException {\r
126         for(Resource r : els)\r
127             if(g.hasStatement(r, l))\r
128                 return false;\r
129         Resource cur = prev(g, l, l);\r
130         g.denyStatement(cur, l, l);\r
131         for(Resource r : els) {\r
132             g.claim(cur, l, r);\r
133             cur = r;\r
134         }\r
135         g.claim(cur, l, l);\r
136         return true;\r
137     }\r
138 \r
139     public static boolean addAllNew(WriteGraph g, Resource l, Iterable<Resource> els) throws DatabaseException {\r
140         Resource cur = prev(g, l, l);\r
141         Resource inv = g.getInverse(l);\r
142         g.deny(cur, l, inv, l);\r
143         for(Resource r : els) {\r
144             g.claim(cur, l, inv, r);\r
145             cur = r;\r
146         }\r
147         g.claim(cur, l, inv, l);\r
148         return true;\r
149     }\r
150 \r
151     public static boolean addAfter(WriteGraph g, Resource l, Resource pos, Resource el) throws DatabaseException {\r
152         if(g.hasStatement(el, l))\r
153             return false;\r
154         Resource next = next(g, l, pos);\r
155         g.denyStatement(pos, l, next);\r
156         g.claim(pos, l, el);\r
157         g.claim(el, l, next);\r
158         return true;\r
159     }\r
160 \r
161     public static boolean addBefore(WriteGraph g, Resource l, Resource pos, Resource el) throws DatabaseException {\r
162         if(g.hasStatement(el, l))\r
163             return false;\r
164         Resource prev = prev(g, l, pos);\r
165         g.denyStatement(prev, l, pos);\r
166         g.claim(prev, l, el);\r
167         g.claim(el, l, pos);\r
168         return true;\r
169     }\r
170 \r
171     /**\r
172      * Removes a given elements <tt>el</tt> from the list <tt>l</tt>. Returns\r
173      * true, if the element was really removed.\r
174      */\r
175     public static boolean remove(WriteGraph g, Resource l, Resource el) throws DatabaseException {\r
176         Collection<Resource> nexts = g.getObjects(el, l);\r
177         if(nexts.size() == 0)\r
178             return false;\r
179         if(nexts.size() != 1)\r
180             throw new InvalidOrderedSetException("Invalid list element.");\r
181         Collection<Resource> prevs = g.getObjects(el, g.getInverse(l));\r
182         if(prevs.size() != 1)\r
183             throw new InvalidOrderedSetException("Invalid list element.");\r
184 \r
185         for(Resource p : prevs)\r
186             for(Resource n : nexts) {\r
187                 g.denyStatement(p, l, el);\r
188                 g.denyStatement(el, l, n);\r
189                 g.claim(p, l, n);\r
190                 return true;\r
191             }\r
192         return true;\r
193     }\r
194 \r
195     public static List<Resource> removeList(WriteGraph g, Resource l) throws DatabaseException {\r
196         List<Resource> els = toList(g, l);\r
197         for(Resource el : els)\r
198             g.deny(el, l);\r
199         g.deny(l, l);\r
200         Resource inv = g.getInverse(l);\r
201         g.deny(l);\r
202         g.deny(inv);\r
203         return els;\r
204     }\r
205 \r
206     public static void replace(WriteGraph g, Resource l, Resource oldEl, Resource newEl) throws DatabaseException {\r
207         Collection<Resource> nexts = g.getObjects(oldEl, l);\r
208         if(nexts.size() != 1)\r
209             throw new InvalidOrderedSetException("Invalid list element.");\r
210         Collection<Resource> prevs = g.getObjects(oldEl, g.getInverse(l));\r
211         if(prevs.size() != 1)\r
212             throw new InvalidOrderedSetException("Invalid list element.");\r
213 \r
214         for(Resource p : prevs)\r
215             for(Resource n : nexts) {\r
216                 g.denyStatement(p, l, oldEl);\r
217                 g.denyStatement(oldEl, l, n);\r
218                 g.claim(p, l, newEl);\r
219                 g.claim(newEl, l, n);\r
220                 return;\r
221             }\r
222     }\r
223 \r
224     /**\r
225      * Converts ordered set into a list.\r
226      */\r
227     public static List<Resource> toList(ReadGraph g, Resource l) throws DatabaseException {\r
228         ArrayList<Resource> ret = new ArrayList<Resource>();\r
229         Resource cur = l;\r
230         while(true) {\r
231             cur = next(g, l, cur);\r
232             if(cur.equals(l))\r
233                 return ret;\r
234             ret.add(cur);\r
235         }\r
236     }\r
237 \r
238     /**\r
239      * Converts ordered set into a list.\r
240      */\r
241     public static void forEach(AsyncReadGraph g, final Resource l, final AsyncMultiProcedure<Resource> procedure) {\r
242         g.asyncRequest(new ReadRequest() {\r
243 \r
244             @Override\r
245             public void run(ReadGraph graph) throws DatabaseException {\r
246                 for(Resource r : toList(graph, l))\r
247                     procedure.execute(graph, r);\r
248             }\r
249 \r
250         });\r
251     }\r
252 \r
253     /**\r
254      * Creates an empty ordered set.\r
255      */\r
256     public static Resource create(WriteOnlyGraph g, Resource type) throws DatabaseException {\r
257         Layer0 l0 = g.getService(Layer0.class);\r
258         Resource l = g.newResource();\r
259         g.claim(l, l0.InstanceOf, null, type);\r
260         g.claim(l, l0.SubrelationOf, null, l0.HasNext);\r
261         Resource invL = g.newResource();\r
262         g.claim(invL, l0.SubrelationOf, null, l0.HasPrevious);\r
263         g.claim(l, l0.InverseOf, l0.InverseOf, invL);\r
264         g.claim(l, l, invL, l);\r
265         return l;\r
266     }\r
267 \r
268     /**\r
269      * Creates an ordered set containing the given elements.\r
270      * It is assumed that the elements do not contain duplicates.\r
271      */\r
272     @Deprecated\r
273     public static Resource create(WriteOnlyGraph g, Resource type, Iterable<Resource> c) throws DatabaseException {\r
274         Layer0 l0 = g.getService(Layer0.class);\r
275         Resource l = g.newResource();\r
276         g.claim(l, l0.InstanceOf, null, type);\r
277         g.claim(l, l0.SubrelationOf, null, l0.HasNext);\r
278         Resource invL = g.newResource();\r
279         g.claim(invL, l0.SubrelationOf, null, l0.HasPrevious);\r
280         g.claim(l, l0.InverseOf, l0.InverseOf, invL);\r
281         Resource cur = l;\r
282         for(Resource r : c) {\r
283             g.claim(cur, l, invL, r);\r
284             cur = r;\r
285         }\r
286         g.claim(cur, l, invL, l);\r
287         return l;\r
288     }\r
289 \r
290     public static Resource create(WriteOnlyGraph g, Resource type, String name, Iterable<Resource> c) throws DatabaseException {\r
291         return createExisting(g, g.newResource(), type, name, c);\r
292     }\r
293 \r
294     public static Resource createExisting(WriteOnlyGraph g, Resource l, Resource type, String name, Iterable<Resource> c) throws DatabaseException {\r
295         Layer0 l0 = g.getService(Layer0.class);\r
296         g.claim(l, l0.InstanceOf, null, type);\r
297         g.claim(l, l0.SubrelationOf, null, l0.HasNext);\r
298         g.addLiteral(l, l0.HasName, l0.NameOf, l0.String, name, Bindings.STRING);\r
299         Resource invL = g.newResource();\r
300         g.claim(invL, l0.SubrelationOf, null, l0.HasPrevious);\r
301         g.addLiteral(invL, l0.HasName, l0.NameOf, l0.String, "Inverse", Bindings.STRING);\r
302         g.claim(l, l0.InverseOf, l0.InverseOf, invL);\r
303         g.claim(l, l0.ConsistsOf, l0.PartOf, invL);\r
304         Resource cur = l;\r
305         for(Resource r : c) {\r
306             g.claim(cur, l, invL, r);\r
307             cur = r;\r
308         }\r
309         g.claim(cur, l, invL, l);\r
310         return l;\r
311     }\r
312     \r
313     public static Resource create(WriteOnlyGraph g, Resource type, Resource ... c) throws DatabaseException {\r
314         Layer0 l0 = g.getService(Layer0.class);\r
315         Resource l = g.newResource();\r
316         g.claim(l, l0.InstanceOf, null, type);\r
317         g.claim(l, l0.SubrelationOf, null, l0.HasNext);\r
318         Resource invL = g.newResource();\r
319         g.claim(invL, l0.SubrelationOf, null, l0.HasPrevious);\r
320         g.claim(l, l0.InverseOf, l0.InverseOf, invL);\r
321         Resource cur = l;\r
322         for(Resource r : c) {\r
323             g.claim(cur, l, invL, r);\r
324             cur = r;\r
325         }\r
326         g.claim(cur, l, invL, l);\r
327         return l;\r
328     }\r
329 \r
330     public static Resource createExisting(WriteGraph g, Resource l, Resource ... c) throws DatabaseException {\r
331         Layer0 l0 = Layer0.getInstance(g);\r
332         g.claim(l, l0.SubrelationOf, null, l0.HasNext);\r
333         Resource invL = g.newResource();\r
334         g.claim(invL, l0.SubrelationOf, null, l0.HasPrevious);\r
335         g.claim(l, l0.InverseOf, l0.InverseOf, invL);\r
336         Resource cur = l;\r
337         for(Resource r : c) {\r
338             g.claim(cur, l, invL, r);\r
339             cur = r;\r
340         }\r
341         g.claim(cur, l, invL, l);\r
342         return l;\r
343     }\r
344     \r
345 //    public static Resource create(GraphWriter graph, Resource type, Iterable<Resource> c) throws DatabaseException {\r
346 //        ReadGraph g = w.getGraph();\r
347 //        Builtins b = g.getBuiltins();\r
348 //        Resource l = w.create(type).get();\r
349 //        w.let(b.SubrelationOf, b.IsRelatedTo);\r
350 //        w.createInverse(l).let(b.SubrelationOf, g.getInverse(b.IsRelatedTo));\r
351 //\r
352 //        Resource cur = l;\r
353 //        for(Resource r : c) {\r
354 //            w.stat(cur, l, r);\r
355 //            cur = r;\r
356 //        }\r
357 //        w.stat(cur, l, l);\r
358 //        return l;\r
359 //    }\r
360 \r
361     public static class OrderedSetIterator implements ListIterator<Resource> {\r
362 \r
363         ReadGraph g;\r
364         Resource l;\r
365         Resource prev;\r
366         Resource next;\r
367         int index;\r
368         boolean direction;\r
369 \r
370         WriteGraph getWriteGraph() {\r
371             if (!(g instanceof WriteGraph))\r
372                 throw new UnsupportedOperationException("");\r
373             return (WriteGraph) g;\r
374         }\r
375 \r
376         public OrderedSetIterator(ReadGraph g, Resource l) throws DatabaseException {\r
377             this.g = g;\r
378             this.l = l;\r
379             this.prev = l;\r
380             this.next = OrderedSetUtils.next(g, l, l);\r
381             this.index = 0;\r
382         }\r
383 \r
384         @Override\r
385         public boolean hasNext() {\r
386             return !next.equals(l);\r
387         }\r
388 \r
389         @Override\r
390         public Resource next() {\r
391             prev = next;\r
392             try {\r
393                 next = OrderedSetUtils.next(g, l, next);\r
394             } catch (DatabaseException e) {\r
395                 throw new RuntimeDatabaseException(e);\r
396             }\r
397             ++index;\r
398             direction = true;\r
399             return prev;\r
400         }\r
401 \r
402         @Override\r
403         public void remove() {\r
404             try {\r
405                 WriteGraph wg = getWriteGraph();\r
406                 if(direction) {\r
407                     OrderedSetUtils.remove(wg, l, prev);\r
408                     prev = OrderedSetUtils.prev(wg, l, next);\r
409                 }\r
410                 else {\r
411                     OrderedSetUtils.remove(wg, l, next);\r
412                     next = OrderedSetUtils.next(wg, l, prev);\r
413                 }\r
414             } catch (DatabaseException e) {\r
415                 throw new RuntimeDatabaseException(e);\r
416             }\r
417         }\r
418 \r
419         @Override\r
420         public void add(Resource e) {\r
421             try {\r
422                 WriteGraph wg = getWriteGraph();\r
423                 wg.denyStatement(prev, l, next);\r
424                 wg.claim(prev, l, e);\r
425                 wg.claim(e, l, next);\r
426                 prev = e;\r
427             } catch (DatabaseException ex) {\r
428                 throw new RuntimeDatabaseException(ex);\r
429             }\r
430         }\r
431 \r
432         @Override\r
433         public boolean hasPrevious() {\r
434             return !prev.equals(l);\r
435         }\r
436 \r
437         @Override\r
438         public int nextIndex() {\r
439             return index;\r
440         }\r
441 \r
442         @Override\r
443         public Resource previous() {\r
444             try {\r
445                 next = prev;\r
446                 prev = OrderedSetUtils.prev(g, l, prev);\r
447                 --index;\r
448                 direction = false;\r
449                 return next;\r
450             } catch (DatabaseException ex) {\r
451                 throw new RuntimeDatabaseException(ex);\r
452             }\r
453         }\r
454 \r
455         @Override\r
456         public int previousIndex() {\r
457             return index-1;\r
458         }\r
459 \r
460         @Override\r
461         public void set(Resource e) {\r
462             try {\r
463                 WriteGraph wg = getWriteGraph();\r
464                 if(direction) {\r
465                     OrderedSetUtils.replace(wg, l, prev, e);\r
466                     prev = e;\r
467                 }\r
468                 else {\r
469                     OrderedSetUtils.replace(wg, l, next, e);\r
470                     next = e;\r
471                 }\r
472             } catch (DatabaseException ex) {\r
473                 throw new RuntimeDatabaseException(ex);\r
474             }\r
475         }\r
476 \r
477     }\r
478 \r
479     public static ListIterator<Resource> iterator(ReadGraph g, Resource l) throws DatabaseException {\r
480         return new OrderedSetIterator(g, l);\r
481     }\r
482 \r
483     public static boolean set(WriteGraph g, Resource l, Iterable<Resource> els) throws DatabaseException {\r
484 \r
485         // Compute delta\r
486         Set<Pair<Resource,Resource>> removed = new HashSet<Pair<Resource,Resource>>();\r
487         Collection<Pair<Resource,Resource>> added = new ArrayList<Pair<Resource,Resource>>();\r
488         Resource cur = l;\r
489         do {\r
490             Resource temp = next(g, l, cur);\r
491             removed.add(new Pair<Resource,Resource>(cur, temp));\r
492             cur = temp;\r
493         } while(!cur.equals(l));\r
494 \r
495         cur = l;\r
496         for(Resource temp : els) {\r
497             Pair<Resource,Resource> pair = new Pair<Resource, Resource>(cur, temp);\r
498             if(!removed.remove(pair))\r
499                 added.add(pair);\r
500             cur = temp;\r
501         }\r
502 \r
503         {\r
504             Pair<Resource,Resource> pair = new Pair<Resource, Resource>(cur, l);\r
505             if(!removed.remove(pair))\r
506                 added.add(pair);\r
507         }\r
508 \r
509         // Apply\r
510         if(added.isEmpty() && removed.isEmpty())\r
511                 return false;\r
512         for(Pair<Resource,Resource> pair : removed)\r
513             g.denyStatement(pair.first, l, pair.second);\r
514         for(Pair<Resource,Resource> pair : added)\r
515             g.claim(pair.first, l, pair.second);\r
516         return true;\r
517     }\r
518 \r
519     /**\r
520      * Retrieves the owner list the specified list element\r
521      * \r
522      * @param g\r
523      * @param el a possible element of a list of the specified type\r
524      * @param listBaseRelation a base relation of the list to look for\r
525      * @return\r
526      */\r
527     public static Resource getSingleOwnerList(ReadGraph g, Resource el, Resource listBaseRelation) throws DatabaseException {\r
528         Collection<Resource> result = getOwnerLists(g, el, listBaseRelation);\r
529         if (result.size() != 1)\r
530             throw new ValidationException(NameUtils.getSafeName(g, el) + " is part of " + result.size() + " lists of base type " + NameUtils.getSafeName(g, listBaseRelation) + ", expected only one list.");\r
531         return result.iterator().next();\r
532     }\r
533 \r
534     public static Resource getSingleOwnerList(ReadGraph g, Resource el) throws DatabaseException {\r
535         Layer0 l0 = Layer0.getInstance(g);\r
536         Collection<Resource> result = getOwnerLists(g, el, l0.OrderedSet);\r
537         if (result.size() != 1)\r
538             throw new ValidationException(NameUtils.getSafeName(g, el) + " is part of " + result.size() + " lists of base type L0.OrderedSet, expected only one list.");\r
539         return result.iterator().next();\r
540     }\r
541     \r
542     public static Collection<Resource> getSubjects(ReadGraph g, Resource object) throws DatabaseException {\r
543         Collection<Resource> result = new ArrayList<Resource>(1);\r
544         Layer0 l0 = Layer0.getInstance(g);\r
545         for(Resource pred : g.getPredicates(object)) {\r
546             if(g.isInstanceOf(pred, l0.OrderedSet) && !pred.equals(object))\r
547                 result.add(pred);\r
548         }\r
549         return result;\r
550     }\r
551 \r
552     private static void forSubjects(ReadGraph g, Resource object, DbFunction<Resource, Boolean> consumer) throws DatabaseException {\r
553         for (Resource pred : g.getPredicates(object)) {\r
554             if (!pred.equals(object))\r
555                 if (!consumer.apply(pred))\r
556                     break;\r
557         }\r
558     }\r
559 \r
560     /**\r
561      * Retrieves the owner list the specified list element\r
562      * \r
563      * @param g\r
564      * @param el a possible element of a list of the specified type\r
565      * @param listBaseRelation a base relation of the list to look for\r
566      * @return\r
567      */\r
568     public static Collection<Resource> getOwnerLists(ReadGraph g, Resource el, Resource listBaseRelation) throws DatabaseException {\r
569         Collection<Resource> result = null;\r
570         Collection<Resource> rs = getSubjects(g, el);\r
571         for (Resource r : rs) {\r
572             if (g.isInstanceOf(r, listBaseRelation)) {\r
573                 if (result == null)\r
574                     result = new ArrayList<Resource>(2);\r
575                 result.add(r);\r
576             }\r
577         }\r
578         if (result == null)\r
579             result = Collections.emptyList();\r
580         return result;\r
581     }\r
582 \r
583     private static class PossibleOwnerList implements DbFunction<Resource, Boolean> {\r
584         private ReadGraph graph;\r
585         private final Resource listBaseRelation;\r
586         public Layer0 L0;\r
587         public Resource result;\r
588 \r
589         PossibleOwnerList(ReadGraph graph, Resource listBaseRelation) {\r
590             this.graph = graph;\r
591             this.listBaseRelation = listBaseRelation;\r
592             this.L0 = Layer0.getInstance(graph);\r
593         }\r
594 \r
595         @Override\r
596         public Boolean apply(Resource t) throws DatabaseException {\r
597             Set<Resource> types = graph.getTypes(t);\r
598             if (types.contains(L0.OrderedSet) && types.contains(listBaseRelation)) {\r
599                 if (result != null) {\r
600                     result = null;\r
601                     return false;\r
602                 }\r
603                 result = t;\r
604             }\r
605             return true;\r
606         }\r
607     }\r
608 \r
609     /**\r
610      * Retrieves a possible single owner list the specified list element\r
611      * \r
612      * @param g\r
613      * @param el\r
614      *            a possible element of a list of the specified type\r
615      * @param listBaseRelation\r
616      *            a base relation of the list to look for\r
617      * @return <code>null</code> if there is zero or more than one owner lists\r
618      *         with specified base relation\r
619      */\r
620     public static Resource getPossibleOwnerList(ReadGraph g, Resource el, Resource listBaseRelation) throws DatabaseException {\r
621         PossibleOwnerList proc = new PossibleOwnerList(g, listBaseRelation);\r
622         forSubjects(g, el, proc);\r
623         return proc.result;\r
624     }\r
625 \r
626 }\r