Просмотр исходного кода

Merge pull request #528 from csmith/master

Use an EvictingQueue instead of RollingList.
pull/529/head
Greg Holmes 9 лет назад
Родитель
Сommit
17ac3cdb96
1 измененных файлов: 9 добавлений и 6 удалений
  1. 9
    6
      src/com/dmdirc/Channel.java

+ 9
- 6
src/com/dmdirc/Channel.java Просмотреть файл

@@ -51,16 +51,18 @@ import com.dmdirc.ui.input.TabCompletionType;
51 51
 import com.dmdirc.ui.messages.BackBufferFactory;
52 52
 import com.dmdirc.ui.messages.Styliser;
53 53
 import com.dmdirc.ui.messages.sink.MessageSinkManager;
54
-import com.dmdirc.util.collections.RollingList;
55 54
 import com.dmdirc.util.colours.Colour;
56 55
 import com.dmdirc.util.colours.ColourUtils;
57 56
 
57
+import com.google.common.collect.EvictingQueue;
58
+
58 59
 import java.util.ArrayList;
59 60
 import java.util.Arrays;
60 61
 import java.util.Collection;
61 62
 import java.util.Collections;
62 63
 import java.util.List;
63 64
 import java.util.Optional;
65
+import java.util.Queue;
64 66
 import java.util.stream.Collectors;
65 67
 
66 68
 import javax.annotation.Nullable;
@@ -77,7 +79,7 @@ public class Channel extends FrameContainer implements GroupChat {
77 79
     /** The connection this channel is on. */
78 80
     private final Connection connection;
79 81
     /** A list of previous topics we've seen. */
80
-    private final RollingList<Topic> topics;
82
+    private final Queue<Topic> topics;
81 83
     /** Our event handler. */
82 84
     private final ChannelEventHandler eventHandler;
83 85
     /** The migrator to use to migrate our config provider. */
@@ -136,7 +138,8 @@ public class Channel extends FrameContainer implements GroupChat {
136 138
 
137 139
         getConfigManager().getBinder().bind(this, Channel.class);
138 140
 
139
-        topics = new RollingList<>(getConfigManager().getOptionInt("channel", "topichistorysize"));
141
+        topics = EvictingQueue.create(
142
+                getConfigManager().getOptionInt("channel", "topichistorysize"));
140 143
 
141 144
         eventHandler = new ChannelEventHandler(this, getEventBus(), groupChatUserManager);
142 145
 
@@ -470,17 +473,17 @@ public class Channel extends FrameContainer implements GroupChat {
470 473
     @Override
471 474
     public List<Topic> getTopics() {
472 475
         synchronized (topics) {
473
-            return new ArrayList<>(topics.getList());
476
+            return new ArrayList<>(topics);
474 477
         }
475 478
     }
476 479
 
477 480
     @Override
478 481
     public Optional<Topic> getCurrentTopic() {
479 482
         synchronized (topics) {
480
-            if (topics.getList().isEmpty()) {
483
+            if (topics.isEmpty()) {
481 484
                 return Optional.empty();
482 485
             } else {
483
-                return Optional.of(topics.get(topics.getList().size() - 1));
486
+                return Optional.of(getTopics().get(topics.size() - 1));
484 487
             }
485 488
         }
486 489
     }

Загрузка…
Отмена
Сохранить