Selaa lähdekoodia

Merge pull request #746 from csmith/master

Add base interface for objects with display properties.
pull/747/head
Chris Smith 7 vuotta sitten
vanhempi
commit
da4b1df3ea

+ 2
- 41
api/src/main/java/com/dmdirc/events/DisplayableEvent.java Näytä tiedosto

@@ -22,52 +22,13 @@
22 22
 
23 23
 package com.dmdirc.events;
24 24
 
25
+import com.dmdirc.interfaces.Displayable;
25 26
 import java.time.LocalDateTime;
26
-import java.util.Optional;
27 27
 
28 28
 /**
29 29
  * Describes an event which is rendered in the client to the user.
30 30
  */
31
-public interface DisplayableEvent extends SourcedEvent {
32
-
33
-    /**
34
-     * Sets a property relating to how this event should be displayed.
35
-     *
36
-     * @param property The property to be set
37
-     * @param value The value of the property
38
-     * @param <T> The type of value that the property takes.
39
-     */
40
-    <T> void setDisplayProperty(DisplayProperty<T> property, T value);
41
-
42
-    /**
43
-     * Retrieves a property relating to how this event should be displayed.
44
-     *
45
-     * @param property The property to be retrieved.
46
-     * @param <T> The type of value that the property takes.
47
-     * @return An optional value for the property.
48
-     */
49
-    <T> Optional<T> getDisplayProperty(DisplayProperty<T> property);
50
-
51
-    /**
52
-     * Determines whether this event has a display property.
53
-     *
54
-     * <p>Only use this method if the value of the property does not matter; otherwise use
55
-     * {@link #getDisplayProperty(DisplayProperty)} and use the appropriate {@link Optional}
56
-     * accessors.
57
-     *
58
-     * @param property The property to be checked.
59
-     * @return True if the property is present, false otherwise.
60
-     */
61
-    default boolean hasDisplayProperty(final DisplayProperty<?> property) {
62
-        return getDisplayProperty(property).isPresent();
63
-    }
64
-
65
-    /**
66
-     * Gets the map of all display properties.
67
-     *
68
-     * @return The map of display properties.
69
-     */
70
-    DisplayPropertyMap getDisplayProperties();
31
+public interface DisplayableEvent extends SourcedEvent, Displayable {
71 32
 
72 33
     /**
73 34
      * Gets the times at which the event occurred.

+ 77
- 0
api/src/main/java/com/dmdirc/interfaces/Displayable.java Näytä tiedosto

@@ -0,0 +1,77 @@
1
+/*
2
+ * Copyright (c) 2006-2016 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7
+ * permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ *
9
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ * Software.
11
+ *
12
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
14
+ * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ */
17
+
18
+package com.dmdirc.interfaces;
19
+
20
+import com.dmdirc.events.DisplayProperty;
21
+import com.dmdirc.events.DisplayPropertyMap;
22
+import java.util.Optional;
23
+
24
+/**
25
+ * Common interface for objects which may be displayed, and are affected by {@link DisplayProperty}s.
26
+ */
27
+public interface Displayable {
28
+
29
+    /**
30
+     * Retrieves a property relating to how this object should be displayed.
31
+     *
32
+     * @param property The property to be retrieved.
33
+     * @param <T> The type of value that the property takes.
34
+     * @return An optional value for the property.
35
+     */
36
+    <T> Optional<T> getDisplayProperty(DisplayProperty<T> property);
37
+
38
+    /**
39
+     * Sets a property relating to how this object should be displayed.
40
+     *
41
+     * @param property The property to be set
42
+     * @param value The value of the property
43
+     * @param <T> The type of value that the property takes.
44
+     */
45
+    <T> void setDisplayProperty(DisplayProperty<T> property, T value);
46
+
47
+    /**
48
+     * Determines whether this object has a display property.
49
+     *
50
+     * <p>Only use this method if the value of the property does not matter; otherwise use
51
+     * {@link #getDisplayProperty(DisplayProperty)} and use the appropriate {@link Optional}
52
+     * accessors.
53
+     *
54
+     * @param property The property to be checked.
55
+     * @return True if the property is present, false otherwise.
56
+     */
57
+    default boolean hasDisplayProperty(final DisplayProperty<?> property) {
58
+        return getDisplayProperty(property).isPresent();
59
+    }
60
+
61
+    /**
62
+     * Removes a property relating to how this object should be displayed.
63
+     *
64
+     * @param property The property to be removed
65
+     */
66
+    default <T> void removeDisplayProperty(final DisplayProperty<T> property) {
67
+        getDisplayProperties().remove(property);
68
+    }
69
+
70
+    /**
71
+     * Gets the map of all display properties.
72
+     *
73
+     * @return The map of display properties.
74
+     */
75
+    DisplayPropertyMap getDisplayProperties();
76
+
77
+}

+ 1
- 33
api/src/main/java/com/dmdirc/interfaces/GroupChatUser.java Näytä tiedosto

@@ -22,16 +22,13 @@
22 22
 
23 23
 package com.dmdirc.interfaces;
24 24
 
25
-import com.dmdirc.events.DisplayProperty;
26
-import com.dmdirc.events.DisplayPropertyMap;
27
-
28 25
 import java.util.Comparator;
29 26
 import java.util.Optional;
30 27
 
31 28
 /**
32 29
  * Describes a {@link User} that is present on a {@link GroupChat}.
33 30
  */
34
-public interface GroupChatUser {
31
+public interface GroupChatUser extends Displayable {
35 32
 
36 33
     /**
37 34
      * Retrieves the {@link User} object which this object corresponds
@@ -107,33 +104,4 @@ public interface GroupChatUser {
107 104
      */
108 105
     Comparator<String> getModeComparator();
109 106
 
110
-    /**
111
-     * Sets a property relating to how this {@link GroupChatUser} should be displayed.
112
-     *
113
-     * @param property The property to be set
114
-     * @param value The value of the property
115
-     * @param <T> The type of value that the property takes.
116
-     */
117
-    <T> void setDisplayProperty(final DisplayProperty<T> property, final T value);
118
-
119
-    /**
120
-     * Retrieves a property relating to how this {@link GroupChatUser} should be displayed.
121
-     *
122
-     * @param property The property to be retrieved.
123
-     * @param <T> The type of value that the property takes.
124
-     * @return An optional value for the property.
125
-     */
126
-    <T> Optional<T> getDisplayProperty(final DisplayProperty<T> property);
127
-
128
-    /**
129
-     * Removes a property relating to how this {@link GroupChatUser} should be displayed.
130
-     */
131
-    <T> void removeDisplayProperty(final DisplayProperty<T> property);
132
-
133
-    /**
134
-     * Gets the map of all display properties for this {@link GroupChatUser}.
135
-     *
136
-     * @return The map of display properties.
137
-     */
138
-    DisplayPropertyMap getDisplayProperties();
139 107
 }

Loading…
Peruuta
Tallenna