Explorar el Código

Merge pull request #608 from csmith/tidying2

Minor tidying around displayable events.
pull/610/head
Shane Mc Cormack hace 8 años
padre
commit
cd30623b4b

+ 14
- 0
src/com/dmdirc/events/DisplayableEvent.java Ver fichero

@@ -63,6 +63,20 @@ public interface DisplayableEvent {
63 63
      */
64 64
     <T> Optional<T> getDisplayProperty(DisplayProperty<T> property);
65 65
 
66
+    /**
67
+     * Determines whether this event has a display property.
68
+     *
69
+     * <p>Only use this method if the value of the property does not matter; otherwise use
70
+     * {@link #getDisplayProperty(DisplayProperty)} and use the appropriate {@link Optional}
71
+     * accessors.
72
+     *
73
+     * @param property The property to be checked.
74
+     * @return True if the property is present, false otherwise.
75
+     */
76
+    default boolean hasDisplayProperty(final DisplayProperty<?> property) {
77
+        return getDisplayProperty(property).isPresent();
78
+    }
79
+
66 80
     /**
67 81
      * Gets the map of all display properties.
68 82
      *

+ 6
- 8
src/com/dmdirc/ui/messages/BackBuffer.java Ver fichero

@@ -28,6 +28,8 @@ import com.dmdirc.events.DisplayableEvent;
28 28
 import com.dmdirc.interfaces.WindowModel;
29 29
 import com.dmdirc.util.EventUtils;
30 30
 
31
+import java.util.Arrays;
32
+
31 33
 import net.engio.mbassy.listener.Handler;
32 34
 
33 35
 /**
@@ -77,13 +79,9 @@ public class BackBuffer {
77 79
     @Handler(priority = EventUtils.PRIORITY_DISPLAYABLE_EVENT_HANDLER)
78 80
     private void handleDisplayableEvent(final DisplayableEvent event) {
79 81
         if (shouldDisplay(event)) {
80
-            formatter.format(event).map(s -> s.split("\n")).ifPresent(
81
-                    t -> {
82
-                        for (String line : t) {
83
-                            document.addText(event.getTimestamp(), event
84
-                                    .getDisplayProperties(), line);
85
-                        }
86
-                    });
82
+            formatter.format(event).map(s -> s.split("\n")).map(Arrays::stream).ifPresent(
83
+                    t -> t.forEach(line -> document.addText(
84
+                            event.getTimestamp(), event.getDisplayProperties(), line)));
87 85
         }
88 86
     }
89 87
 
@@ -95,7 +93,7 @@ public class BackBuffer {
95 93
      */
96 94
     private boolean shouldDisplay(final DisplayableEvent event) {
97 95
         return event.getSource().equals(owner)
98
-                && !event.getDisplayProperty(DisplayProperty.DO_NOT_DISPLAY).isPresent();
96
+                && !event.hasDisplayProperty(DisplayProperty.DO_NOT_DISPLAY);
99 97
     }
100 98
 
101 99
     public IRCDocument getDocument() {

+ 1
- 1
src/com/dmdirc/ui/messages/EventFormatter.java Ver fichero

@@ -60,7 +60,7 @@ public class EventFormatter {
60 60
     public Optional<String> format(final DisplayableEvent event) {
61 61
         final Optional<EventFormat> format = formatProvider.getFormat(event.getClass());
62 62
 
63
-        if (!event.getDisplayProperty(DisplayProperty.FOREGROUND_COLOUR).isPresent()) {
63
+        if (!event.hasDisplayProperty(DisplayProperty.FOREGROUND_COLOUR)) {
64 64
             format.flatMap(EventFormat::getDefaultForegroundColour)
65 65
                     .ifPresent(c -> event.setDisplayProperty(DisplayProperty.FOREGROUND_COLOUR, c));
66 66
         }

Loading…
Cancelar
Guardar