Use better synchronization and the pre-defined post comparator.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 5 Nov 2010 22:42:04 +0000 (23:42 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 5 Nov 2010 22:42:04 +0000 (23:42 +0100)
src/main/java/net/pterodactylus/sone/data/Sone.java

index 3ff0d3b..fd69832 100644 (file)
@@ -362,15 +362,11 @@ public class Sone {
         * @return All posts of this Sone
         */
        public List<Post> getPosts() {
-               List<Post> sortedPosts = new ArrayList<Post>(posts);
-               Collections.sort(sortedPosts, new Comparator<Post>() {
-
-                       @Override
-                       public int compare(Post leftPost, Post rightPost) {
-                               return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, rightPost.getTime() - leftPost.getTime()));
-                       }
-
-               });
+               List<Post> sortedPosts;
+               synchronized (this) {
+                       sortedPosts = new ArrayList<Post>(posts);
+               }
+               Collections.sort(sortedPosts, Post.TIME_COMPARATOR);
                return sortedPosts;
        }