+ };
+
+ public static final Function<Sone, String> TO_NICE_NAME = new Function<Sone, String>() {
+ @Override
+ public String apply(Sone sone) {
+ return (sone == null) ? null : getNiceName(sone);
+ }
+ };
+
+ /** Comparator that sorts Sones by last activity (least recent active first). */
+ public static final Comparator<Sone> LAST_ACTIVITY_COMPARATOR = new Comparator<Sone>() {
+
+ @Override
+ public int compare(Sone firstSone, Sone secondSone) {
+ return (int) Math.min(Integer.MAX_VALUE, Math.max(Integer.MIN_VALUE, secondSone.getTime() - firstSone.getTime()));
+ }
+ };
+
+ /** Comparator that sorts Sones by numbers of posts (descending). */
+ public static final Comparator<Sone> POST_COUNT_COMPARATOR = new Comparator<Sone>() {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int compare(Sone leftSone, Sone rightSone) {
+ return (leftSone.getPosts().size() != rightSone.getPosts().size()) ? (rightSone.getPosts().size() - leftSone.getPosts().size()) : (rightSone.getReplies().size() - leftSone.getReplies().size());
+ }
+ };
+
+ /** Comparator that sorts Sones by number of images (descending). */
+ public static final Comparator<Sone> IMAGE_COUNT_COMPARATOR = new Comparator<Sone>() {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int compare(Sone leftSone, Sone rightSone) {
+ int rightSoneImageCount = from(asList(rightSone.getRootAlbum())).transformAndConcat(FLATTENER).transformAndConcat(IMAGES).size();
+ int leftSoneImageCount = from(asList(leftSone.getRootAlbum())).transformAndConcat(FLATTENER).transformAndConcat(IMAGES).size();
+ /* sort descending. */
+ return Ints.compare(rightSoneImageCount, leftSoneImageCount);
+ }
+ };
+
+ /** Filter to remove Sones that have not been downloaded. */
+ public static final Predicate<Sone> EMPTY_SONE_FILTER = new Predicate<Sone>() {
+
+ @Override
+ public boolean apply(Sone sone) {
+ return (sone == null) ? false : sone.getTime() != 0;
+ }
+ };
+
+ /** Filter that matches all {@link Sone#isLocal() local Sones}. */
+ public static final Predicate<Sone> LOCAL_SONE_FILTER = new Predicate<Sone>() {
+
+ @Override
+ public boolean apply(Sone sone) {
+ return (sone == null) ? false : sone.isLocal();
+ }
+
+ };
+
+ /** Filter that matches Sones that have at least one album. */
+ public static final Predicate<Sone> HAS_ALBUM_FILTER = new Predicate<Sone>() {
+
+ @Override
+ public boolean apply(Sone sone) {
+ return (sone == null) ? false : !sone.getRootAlbum().getAlbums().isEmpty();
+ }
+ };
+
+ public static final Function<Sone, FreenetURI> TO_FREENET_URI = new Function<Sone, FreenetURI>() {
+ @Override
+ public FreenetURI apply(Sone sone) {
+ return (sone == null) ? null : create(sone.getIdentity().getRequestUri());
+ }
+ };
+
+ public static final Function<Sone, FreenetURI> TO_INSERT_URI = new Function<Sone, FreenetURI>() {
+ @Override
+ public FreenetURI apply(@Nullable Sone sone) {
+ return ((sone == null) || !sone.isLocal()) ? null : create(((OwnIdentity) sone.getIdentity()).getInsertUri());
+ }
+ };
+
+ public static final Function<Sone, List<Post>> TO_POSTS = new Function<Sone, List<Post>>() {
+ @Override
+ public List<Post> apply(Sone sone) {
+ return (sone == null) ? Collections.<Post>emptyList() : sone.getPosts();
+ }
+ };