Add method to expose a Post loader.
[Sone.git] / src / main / java / net / pterodactylus / sone / database / memory / MemoryDatabase.java
1 /*
2  * Sone - MemoryDatabase.java - Copyright © 2013 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.sone.database.memory;
19
20 import static com.google.common.base.Optional.fromNullable;
21 import static com.google.common.base.Preconditions.checkNotNull;
22 import static com.google.common.base.Predicates.not;
23 import static com.google.common.collect.FluentIterable.from;
24 import static java.util.Collections.emptyList;
25 import static net.pterodactylus.sone.data.Sone.LOCAL_SONE_FILTER;
26
27 import java.util.ArrayList;
28 import java.util.Collection;
29 import java.util.Collections;
30 import java.util.Comparator;
31 import java.util.HashMap;
32 import java.util.HashSet;
33 import java.util.List;
34 import java.util.Map;
35 import java.util.Set;
36 import java.util.concurrent.locks.ReadWriteLock;
37 import java.util.concurrent.locks.ReentrantReadWriteLock;
38
39 import net.pterodactylus.sone.data.Album;
40 import net.pterodactylus.sone.data.Image;
41 import net.pterodactylus.sone.data.Post;
42 import net.pterodactylus.sone.data.PostReply;
43 import net.pterodactylus.sone.data.Sone;
44 import net.pterodactylus.sone.data.impl.DefaultSoneBuilder;
45 import net.pterodactylus.sone.database.Database;
46 import net.pterodactylus.sone.database.DatabaseException;
47 import net.pterodactylus.sone.database.PostDatabase;
48 import net.pterodactylus.sone.database.SoneBuilder;
49 import net.pterodactylus.sone.freenet.wot.Identity;
50 import net.pterodactylus.util.config.Configuration;
51 import net.pterodactylus.util.config.ConfigurationException;
52
53 import com.google.common.base.Function;
54 import com.google.common.base.Optional;
55 import com.google.common.collect.ArrayListMultimap;
56 import com.google.common.collect.HashMultimap;
57 import com.google.common.collect.ListMultimap;
58 import com.google.common.collect.Maps;
59 import com.google.common.collect.Multimap;
60 import com.google.common.collect.SortedSetMultimap;
61 import com.google.common.collect.TreeMultimap;
62 import com.google.common.util.concurrent.AbstractService;
63 import com.google.inject.Inject;
64
65 /**
66  * Memory-based {@link PostDatabase} implementation.
67  *
68  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
69  */
70 public class MemoryDatabase extends AbstractService implements Database {
71
72         /** The lock. */
73         private final ReadWriteLock lock = new ReentrantReadWriteLock();
74
75         /** The configuration. */
76         private final Configuration configuration;
77
78         private final Map<String, Identity> identities = Maps.newHashMap();
79         private final Map<String, Sone> sones = new HashMap<String, Sone>();
80
81         /** All posts by their ID. */
82         private final Map<String, Post> allPosts = new HashMap<String, Post>();
83
84         /** All posts by their Sones. */
85         private final Multimap<String, Post> sonePosts = HashMultimap.create();
86
87         /** All posts by their recipient. */
88         private final Multimap<String, Post> recipientPosts = HashMultimap.create();
89
90         /** Whether posts are known. */
91         private final Set<String> knownPosts = new HashSet<String>();
92
93         /** All post replies by their ID. */
94         private final Map<String, PostReply> allPostReplies = new HashMap<String, PostReply>();
95
96         /** Replies sorted by Sone. */
97         private final SortedSetMultimap<String, PostReply> sonePostReplies = TreeMultimap.create(new Comparator<String>() {
98
99                 @Override
100                 public int compare(String leftString, String rightString) {
101                         return leftString.compareTo(rightString);
102                 }
103         }, PostReply.TIME_COMPARATOR);
104
105         /** Replies by post. */
106         private final SortedSetMultimap<String, PostReply> postReplies = TreeMultimap.create(new Comparator<String>() {
107
108                 @Override
109                 public int compare(String leftString, String rightString) {
110                         return leftString.compareTo(rightString);
111                 }
112         }, PostReply.TIME_COMPARATOR);
113
114         /** Whether post replies are known. */
115         private final Set<String> knownPostReplies = new HashSet<String>();
116
117         private final Map<String, Album> allAlbums = new HashMap<String, Album>();
118         private final ListMultimap<String, String> albumChildren = ArrayListMultimap.create();
119         private final ListMultimap<String, String> albumImages = ArrayListMultimap.create();
120
121         private final Map<String, Image> allImages = new HashMap<String, Image>();
122
123         /**
124          * Creates a new memory database.
125          *
126          * @param configuration
127          *              The configuration for loading and saving elements
128          */
129         @Inject
130         public MemoryDatabase(Configuration configuration) {
131                 this.configuration = configuration;
132         }
133
134         //
135         // DATABASE METHODS
136         //
137
138         @Override
139         public void save() throws DatabaseException {
140                 saveKnownPosts();
141                 saveKnownPostReplies();
142         }
143
144         //
145         // SERVICE METHODS
146         //
147
148         @Override
149         protected void doStart() {
150                 loadKnownPosts();
151                 loadKnownPostReplies();
152                 notifyStarted();
153         }
154
155         @Override
156         protected void doStop() {
157                 try {
158                         save();
159                         notifyStopped();
160                 } catch (DatabaseException de1) {
161                         notifyFailed(de1);
162                 }
163         }
164
165         @Override
166         public Optional<Identity> getIdentity(String identityId) {
167                 lock.readLock().lock();
168                 try {
169                         return fromNullable(identities.get(identityId));
170                 } finally {
171                         lock.readLock().unlock();
172                 }
173         }
174
175         @Override
176         public Function<String, Optional<Sone>> getSone() {
177                 return new Function<String, Optional<Sone>>() {
178                         @Override
179                         public Optional<Sone> apply(String soneId) {
180                                 return (soneId == null) ? Optional.<Sone>absent() : getSone(soneId);
181                         }
182                 };
183         }
184
185         @Override
186         public Optional<Sone> getSone(String soneId) {
187                 lock.readLock().lock();
188                 try {
189                         return fromNullable(sones.get(soneId));
190                 } finally {
191                         lock.readLock().unlock();
192                 }
193         }
194
195         @Override
196         public Collection<Sone> getSones() {
197                 lock.readLock().lock();
198                 try {
199                         return Collections.unmodifiableCollection(sones.values());
200                 } finally {
201                         lock.readLock().unlock();
202                 }
203         }
204
205         @Override
206         public Collection<Sone> getLocalSones() {
207                 lock.readLock().lock();
208                 try {
209                         return from(getSones()).filter(LOCAL_SONE_FILTER).toSet();
210                 } finally {
211                         lock.readLock().unlock();
212                 }
213         }
214
215         @Override
216         public Collection<Sone> getRemoteSones() {
217                 lock.readLock().lock();
218                 try {
219                         return from(getSones()).filter(not(LOCAL_SONE_FILTER)).toSet();
220                 } finally {
221                         lock.readLock().unlock();
222                 }
223         }
224
225         @Override
226         public SoneBuilder newSoneBuilder() {
227                 return new DefaultSoneBuilder(this) {
228                         @Override
229                         public Sone build(Optional<SoneCreated> soneCreated) throws IllegalStateException {
230                                 Sone sone = super.build(soneCreated);
231                                 lock.writeLock().lock();
232                                 try {
233                                         sones.put(sone.getId(), sone);
234                                 } finally {
235                                         lock.writeLock().unlock();
236                                 }
237                                 return sone;
238                         }
239                 };
240         }
241
242         //
243         // POSTPROVIDER METHODS
244         //
245
246         @Override
247         public Function<String, Optional<Post>> getPost() {
248                 return new Function<String, Optional<Post>>() {
249                         @Override
250                         public Optional<Post> apply(String postId) {
251                                 return (postId == null) ? Optional.<Post>absent() : getPost(postId);
252                         }
253                 };
254         }
255
256         @Override
257         public Optional<Post> getPost(String postId) {
258                 lock.readLock().lock();
259                 try {
260                         return fromNullable(allPosts.get(postId));
261                 } finally {
262                         lock.readLock().unlock();
263                 }
264         }
265
266         @Override
267         public Collection<Post> getPosts(String soneId) {
268                 lock.readLock().lock();
269                 try {
270                         return new HashSet<Post>(sonePosts.get(soneId));
271                 } finally {
272                         lock.readLock().unlock();
273                 }
274         }
275
276         @Override
277         public Collection<Post> getDirectedPosts(String recipientId) {
278                 lock.readLock().lock();
279                 try {
280                         Collection<Post> posts = recipientPosts.get(recipientId);
281                         return (posts == null) ? Collections.<Post>emptySet() : new HashSet<Post>(posts);
282                 } finally {
283                         lock.readLock().unlock();
284                 }
285         }
286
287         //
288         // POSTSTORE METHODS
289         //
290
291         @Override
292         public void storePost(Post post) {
293                 checkNotNull(post, "post must not be null");
294                 lock.writeLock().lock();
295                 try {
296                         allPosts.put(post.getId(), post);
297                         sonePosts.put(post.getSone().getId(), post);
298                         if (post.getRecipientId().isPresent()) {
299                                 recipientPosts.put(post.getRecipientId().get(), post);
300                         }
301                 } finally {
302                         lock.writeLock().unlock();
303                 }
304         }
305
306         @Override
307         public void removePost(Post post) {
308                 checkNotNull(post, "post must not be null");
309                 lock.writeLock().lock();
310                 try {
311                         allPosts.remove(post.getId());
312                         sonePosts.remove(post.getSone().getId(), post);
313                         if (post.getRecipientId().isPresent()) {
314                                 recipientPosts.remove(post.getRecipientId().get(), post);
315                         }
316                         post.getSone().removePost(post);
317                 } finally {
318                         lock.writeLock().unlock();
319                 }
320         }
321
322         @Override
323         public void storePosts(Sone sone, Collection<Post> posts) throws IllegalArgumentException {
324                 checkNotNull(sone, "sone must not be null");
325                 /* verify that all posts are from the same Sone. */
326                 for (Post post : posts) {
327                         if (!sone.equals(post.getSone())) {
328                                 throw new IllegalArgumentException(String.format("Post from different Sone found: %s", post));
329                         }
330                 }
331
332                 lock.writeLock().lock();
333                 try {
334                         /* remove all posts by the Sone. */
335                         sonePosts.removeAll(sone.getId());
336                         for (Post post : posts) {
337                                 allPosts.remove(post.getId());
338                                 if (post.getRecipientId().isPresent()) {
339                                         recipientPosts.remove(post.getRecipientId().get(), post);
340                                 }
341                         }
342
343                         /* add new posts. */
344                         sonePosts.putAll(sone.getId(), posts);
345                         for (Post post : posts) {
346                                 allPosts.put(post.getId(), post);
347                                 if (post.getRecipientId().isPresent()) {
348                                         recipientPosts.put(post.getRecipientId().get(), post);
349                                 }
350                         }
351                 } finally {
352                         lock.writeLock().unlock();
353                 }
354         }
355
356         @Override
357         public void removePosts(Sone sone) {
358                 checkNotNull(sone, "sone must not be null");
359                 lock.writeLock().lock();
360                 try {
361                         /* remove all posts by the Sone. */
362                         sonePosts.removeAll(sone.getId());
363                         for (Post post : sone.getPosts()) {
364                                 allPosts.remove(post.getId());
365                                 if (post.getRecipientId().isPresent()) {
366                                         recipientPosts.remove(post.getRecipientId().get(), post);
367                                 }
368                         }
369                 } finally {
370                         lock.writeLock().unlock();
371                 }
372         }
373
374         //
375         // POSTREPLYPROVIDER METHODS
376         //
377
378         @Override
379         public Optional<PostReply> getPostReply(String id) {
380                 lock.readLock().lock();
381                 try {
382                         return fromNullable(allPostReplies.get(id));
383                 } finally {
384                         lock.readLock().unlock();
385                 }
386         }
387
388         @Override
389         public List<PostReply> getReplies(String postId) {
390                 lock.readLock().lock();
391                 try {
392                         if (!postReplies.containsKey(postId)) {
393                                 return emptyList();
394                         }
395                         return new ArrayList<PostReply>(postReplies.get(postId));
396                 } finally {
397                         lock.readLock().unlock();
398                 }
399         }
400
401         //
402         // POSTREPLYSTORE METHODS
403         //
404
405         /**
406          * Returns whether the given post reply is known.
407          *
408          * @param postReply
409          *              The post reply
410          * @return {@code true} if the given post reply is known, {@code false}
411          *         otherwise
412          */
413         public boolean isPostReplyKnown(PostReply postReply) {
414                 lock.readLock().lock();
415                 try {
416                         return knownPostReplies.contains(postReply.getId());
417                 } finally {
418                         lock.readLock().unlock();
419                 }
420         }
421
422         @Override
423         public void setPostReplyKnown(PostReply postReply) {
424                 lock.writeLock().lock();
425                 try {
426                         knownPostReplies.add(postReply.getId());
427                 } finally {
428                         lock.writeLock().unlock();
429                 }
430         }
431
432         @Override
433         public void storePostReply(PostReply postReply) {
434                 lock.writeLock().lock();
435                 try {
436                         allPostReplies.put(postReply.getId(), postReply);
437                         postReplies.put(postReply.getPostId(), postReply);
438                 } finally {
439                         lock.writeLock().unlock();
440                 }
441         }
442
443         @Override
444         public void storePostReplies(Sone sone, Collection<PostReply> postReplies) {
445                 checkNotNull(sone, "sone must not be null");
446                 /* verify that all posts are from the same Sone. */
447                 for (PostReply postReply : postReplies) {
448                         if (!sone.equals(postReply.getSone())) {
449                                 throw new IllegalArgumentException(String.format("PostReply from different Sone found: %s", postReply));
450                         }
451                 }
452
453                 lock.writeLock().lock();
454                 try {
455                         /* remove all post replies of the Sone. */
456                         for (PostReply postReply : getRepliesFrom(sone.getId())) {
457                                 removePostReply(postReply);
458                         }
459                         for (PostReply postReply : postReplies) {
460                                 allPostReplies.put(postReply.getId(), postReply);
461                                 sonePostReplies.put(postReply.getSone().getId(), postReply);
462                                 this.postReplies.put(postReply.getPostId(), postReply);
463                         }
464                 } finally {
465                         lock.writeLock().unlock();
466                 }
467         }
468
469         @Override
470         public void removePostReply(PostReply postReply) {
471                 lock.writeLock().lock();
472                 try {
473                         allPostReplies.remove(postReply.getId());
474                         postReplies.remove(postReply.getPostId(), postReply);
475                 } finally {
476                         lock.writeLock().unlock();
477                 }
478         }
479
480         @Override
481         public void removePostReplies(Sone sone) {
482                 checkNotNull(sone, "sone must not be null");
483
484                 lock.writeLock().lock();
485                 try {
486                         for (PostReply postReply : sone.getReplies()) {
487                                 removePostReply(postReply);
488                         }
489                 } finally {
490                         lock.writeLock().unlock();
491                 }
492         }
493
494         //
495         // ALBUMPROVDER METHODS
496         //
497
498         @Override
499         public Optional<Album> getAlbum(String albumId) {
500                 lock.readLock().lock();
501                 try {
502                         return fromNullable(allAlbums.get(albumId));
503                 } finally {
504                         lock.readLock().unlock();
505                 }
506         }
507
508         @Override
509         public List<Album> getAlbums(Album parent) {
510                 lock.readLock().lock();
511                 try {
512                         return from(albumChildren.get(parent.getId())).transformAndConcat(getAlbum()).toList();
513                 } finally {
514                         lock.readLock().unlock();
515                 }
516         }
517
518         @Override
519         public void moveUp(Album album) {
520                 lock.writeLock().lock();
521                 try {
522                         List<String> albums = albumChildren.get(album.getParent().getId());
523                         int currentIndex = albums.indexOf(album.getId());
524                         if (currentIndex == 0) {
525                                 return;
526                         }
527                         albums.remove(album.getId());
528                         albums.add(currentIndex - 1, album.getId());
529                 } finally {
530                         lock.writeLock().unlock();
531                 }
532         }
533
534         @Override
535         public void moveDown(Album album) {
536                 lock.writeLock().lock();
537                 try {
538                         List<String> albums = albumChildren.get(album.getParent().getId());
539                         int currentIndex = albums.indexOf(album.getId());
540                         if (currentIndex == (albums.size() - 1)) {
541                                 return;
542                         }
543                         albums.remove(album.getId());
544                         albums.add(currentIndex + 1, album.getId());
545                 } finally {
546                         lock.writeLock().unlock();
547                 }
548         }
549
550         //
551         // ALBUMSTORE METHODS
552         //
553
554         @Override
555         public void storeAlbum(Album album) {
556                 lock.writeLock().lock();
557                 try {
558                         allAlbums.put(album.getId(), album);
559                         if (!album.isRoot()) {
560                                 albumChildren.put(album.getParent().getId(), album.getId());
561                         }
562                 } finally {
563                         lock.writeLock().unlock();
564                 }
565         }
566
567         @Override
568         public void removeAlbum(Album album) {
569                 lock.writeLock().lock();
570                 try {
571                         allAlbums.remove(album.getId());
572                         albumChildren.remove(album.getParent().getId(), album.getId());
573                 } finally {
574                         lock.writeLock().unlock();
575                 }
576         }
577
578         //
579         // IMAGEPROVIDER METHODS
580         //
581
582         @Override
583         public Optional<Image> getImage(String imageId) {
584                 lock.readLock().lock();
585                 try {
586                         return fromNullable(allImages.get(imageId));
587                 } finally {
588                         lock.readLock().unlock();
589                 }
590         }
591
592         @Override
593         public List<Image> getImages(Album parent) {
594                 lock.readLock().lock();
595                 try {
596                         return from(albumImages.get(parent.getId())).transformAndConcat(getImage()).toList();
597                 } finally {
598                         lock.readLock().unlock();
599                 }
600         }
601
602         @Override
603         public void moveUp(Image image) {
604                 lock.writeLock().lock();
605                 try {
606                         List<String> images = albumImages.get(image.getAlbum().getId());
607                         int currentIndex = images.indexOf(image.getId());
608                         if (currentIndex == 0) {
609                                 return;
610                         }
611                         images.remove(image.getId());
612                         images.add(currentIndex - 1, image.getId());
613                 } finally {
614                         lock.writeLock().unlock();
615                 }
616         }
617
618         @Override
619         public void moveDown(Image image) {
620                 lock.writeLock().lock();
621                 try {
622                         List<String> images = albumChildren.get(image.getAlbum().getId());
623                         int currentIndex = images.indexOf(image.getId());
624                         if (currentIndex == (images.size() - 1)) {
625                                 return;
626                         }
627                         images.remove(image.getId());
628                         images.add(currentIndex + 1, image.getId());
629                 } finally {
630                         lock.writeLock().unlock();
631                 }
632         }
633
634         //
635         // IMAGESTORE METHODS
636         //
637
638         @Override
639         public void storeImage(Image image) {
640                 lock.writeLock().lock();
641                 try {
642                         allImages.put(image.getId(), image);
643                         albumImages.put(image.getAlbum().getId(), image.getId());
644                 } finally {
645                         lock.writeLock().unlock();
646                 }
647         }
648
649         @Override
650         public void removeImage(Image image) {
651                 lock.writeLock().lock();
652                 try {
653                         allImages.remove(image.getId());
654                         albumImages.remove(image.getAlbum().getId(), image.getId());
655                 } finally {
656                         lock.writeLock().unlock();
657                 }
658         }
659
660         //
661         // PACKAGE-PRIVATE METHODS
662         //
663
664         /**
665          * Returns whether the given post is known.
666          *
667          * @param post
668          *              The post
669          * @return {@code true} if the post is known, {@code false} otherwise
670          */
671         boolean isPostKnown(Post post) {
672                 lock.readLock().lock();
673                 try {
674                         return knownPosts.contains(post.getId());
675                 } finally {
676                         lock.readLock().unlock();
677                 }
678         }
679
680         /**
681          * Sets whether the given post is known.
682          *
683          * @param post
684          *              The post
685          * @param known
686          *              {@code true} if the post is known, {@code false} otherwise
687          */
688         void setPostKnown(Post post, boolean known) {
689                 lock.writeLock().lock();
690                 try {
691                         if (known) {
692                                 knownPosts.add(post.getId());
693                         } else {
694                                 knownPosts.remove(post.getId());
695                         }
696                 } finally {
697                         lock.writeLock().unlock();
698                 }
699         }
700
701         //
702         // PRIVATE METHODS
703         //
704
705         /** Loads the known posts. */
706         private void loadKnownPosts() {
707                 lock.writeLock().lock();
708                 try {
709                         int postCounter = 0;
710                         while (true) {
711                                 String knownPostId = configuration.getStringValue("KnownPosts/" + postCounter++ + "/ID").getValue(null);
712                                 if (knownPostId == null) {
713                                         break;
714                                 }
715                                 knownPosts.add(knownPostId);
716                         }
717                 } finally {
718                         lock.writeLock().unlock();
719                 }
720         }
721
722         /**
723          * Saves the known posts to the configuration.
724          *
725          * @throws DatabaseException
726          *              if a configuration error occurs
727          */
728         private void saveKnownPosts() throws DatabaseException {
729                 lock.readLock().lock();
730                 try {
731                         int postCounter = 0;
732                         for (String knownPostId : knownPosts) {
733                                 configuration.getStringValue("KnownPosts/" + postCounter++ + "/ID").setValue(knownPostId);
734                         }
735                         configuration.getStringValue("KnownPosts/" + postCounter + "/ID").setValue(null);
736                 } catch (ConfigurationException ce1) {
737                         throw new DatabaseException("Could not save database.", ce1);
738                 } finally {
739                         lock.readLock().unlock();
740                 }
741         }
742
743         /**
744          * Returns all replies by the given Sone.
745          *
746          * @param id
747          *              The ID of the Sone
748          * @return The post replies of the Sone, sorted by time (newest first)
749          */
750         private Collection<PostReply> getRepliesFrom(String id) {
751                 lock.readLock().lock();
752                 try {
753                         if (sonePostReplies.containsKey(id)) {
754                                 return Collections.unmodifiableCollection(sonePostReplies.get(id));
755                         }
756                         return Collections.emptySet();
757                 } finally {
758                         lock.readLock().unlock();
759                 }
760         }
761
762         /** Loads the known post replies. */
763         private void loadKnownPostReplies() {
764                 lock.writeLock().lock();
765                 try {
766                         int replyCounter = 0;
767                         while (true) {
768                                 String knownReplyId = configuration.getStringValue("KnownReplies/" + replyCounter++ + "/ID").getValue(null);
769                                 if (knownReplyId == null) {
770                                         break;
771                                 }
772                                 knownPostReplies.add(knownReplyId);
773                         }
774                 } finally {
775                         lock.writeLock().unlock();
776                 }
777         }
778
779         /**
780          * Saves the known post replies to the configuration.
781          *
782          * @throws DatabaseException
783          *              if a configuration error occurs
784          */
785         private void saveKnownPostReplies() throws DatabaseException {
786                 lock.readLock().lock();
787                 try {
788                         int replyCounter = 0;
789                         for (String knownReplyId : knownPostReplies) {
790                                 configuration.getStringValue("KnownReplies/" + replyCounter++ + "/ID").setValue(knownReplyId);
791                         }
792                         configuration.getStringValue("KnownReplies/" + replyCounter + "/ID").setValue(null);
793                 } catch (ConfigurationException ce1) {
794                         throw new DatabaseException("Could not save database.", ce1);
795                 } finally {
796                         lock.readLock().unlock();
797                 }
798         }
799
800         private Function<String, Iterable<Album>> getAlbum() {
801                 return new Function<String, Iterable<Album>>() {
802                         @Override
803                         public Iterable<Album> apply(String input) {
804                                 return (input == null) ? Collections.<Album>emptyList() : getAlbum(input).asSet();
805                         }
806                 };
807         }
808
809         private Function<String, Iterable<Image>> getImage() {
810                 return new Function<String, Iterable<Image>>() {
811                         @Override
812                         public Iterable<Image> apply(String input) {
813                                 return (input == null) ? Collections.<Image>emptyList() : getImage(input).asSet();
814                         }
815                 };
816         }
817
818 }