Browse Source

Minor tidying around displayable events.

pull/608/head
Chris Smith 8 years ago
parent
commit
07c5f9449e

+ 14
- 0
src/com/dmdirc/events/DisplayableEvent.java View File

63
      */
63
      */
64
     <T> Optional<T> getDisplayProperty(DisplayProperty<T> property);
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
      * Gets the map of all display properties.
81
      * Gets the map of all display properties.
68
      *
82
      *

+ 6
- 8
src/com/dmdirc/ui/messages/BackBuffer.java View File

28
 import com.dmdirc.interfaces.WindowModel;
28
 import com.dmdirc.interfaces.WindowModel;
29
 import com.dmdirc.util.EventUtils;
29
 import com.dmdirc.util.EventUtils;
30
 
30
 
31
+import java.util.Arrays;
32
+
31
 import net.engio.mbassy.listener.Handler;
33
 import net.engio.mbassy.listener.Handler;
32
 
34
 
33
 /**
35
 /**
77
     @Handler(priority = EventUtils.PRIORITY_DISPLAYABLE_EVENT_HANDLER)
79
     @Handler(priority = EventUtils.PRIORITY_DISPLAYABLE_EVENT_HANDLER)
78
     private void handleDisplayableEvent(final DisplayableEvent event) {
80
     private void handleDisplayableEvent(final DisplayableEvent event) {
79
         if (shouldDisplay(event)) {
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
      */
93
      */
96
     private boolean shouldDisplay(final DisplayableEvent event) {
94
     private boolean shouldDisplay(final DisplayableEvent event) {
97
         return event.getSource().equals(owner)
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
     public IRCDocument getDocument() {
99
     public IRCDocument getDocument() {

+ 1
- 1
src/com/dmdirc/ui/messages/EventFormatter.java View File

60
     public Optional<String> format(final DisplayableEvent event) {
60
     public Optional<String> format(final DisplayableEvent event) {
61
         final Optional<EventFormat> format = formatProvider.getFormat(event.getClass());
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
             format.flatMap(EventFormat::getDefaultForegroundColour)
64
             format.flatMap(EventFormat::getDefaultForegroundColour)
65
                     .ifPresent(c -> event.setDisplayProperty(DisplayProperty.FOREGROUND_COLOUR, c));
65
                     .ifPresent(c -> event.setDisplayProperty(DisplayProperty.FOREGROUND_COLOUR, c));
66
         }
66
         }

Loading…
Cancel
Save