1+ /*
2+ * * Copyright (C) 2013-2019 Matt Baxter https://kitteh.org
3+ *
4+ * Permission is hereby granted, free of charge, to any person
5+ * obtaining a copy of this software and associated documentation
6+ * files (the "Software"), to deal in the Software without
7+ * restriction, including without limitation the rights to use, copy,
8+ * modify, merge, publish, distribute, sublicense, and/or sell copies
9+ * of the Software, and to permit persons to whom the Software is
10+ * furnished to do so, subject to the following conditions:
11+ *
12+ * The above copyright notice and this permission notice shall be
13+ * included in all copies or substantial portions of the Software.
14+ *
15+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ * SOFTWARE.
23+ */
24+ package org .kitteh .irc .client .library .defaults .element .mode ;
25+
26+ import org .checkerframework .checker .nullness .qual .NonNull ;
27+ import org .checkerframework .checker .nullness .qual .Nullable ;
28+ import org .kitteh .irc .client .library .Client ;
29+ import org .kitteh .irc .client .library .element .Channel ;
30+ import org .kitteh .irc .client .library .element .mode .ChannelMode ;
31+ import org .kitteh .irc .client .library .element .mode .ModeInfo ;
32+ import org .kitteh .irc .client .library .util .Mask ;
33+ import org .kitteh .irc .client .library .util .ToStringer ;
34+
35+ import java .time .Instant ;
36+ import java .util .Optional ;
37+
38+ /**
39+ * A default ModeInfo implementation.
40+ */
41+ public class DefaultModeInfo implements ModeInfo {
42+ private final Client client ;
43+ private final Instant creationTime ;
44+ private final String creator ;
45+ private final Channel channel ;
46+ private final Mask mask ;
47+ private final ChannelMode mode ;
48+
49+ /**
50+ * Constructs the mode info.
51+ *
52+ * @param client the client
53+ * @param channel channel
54+ * @param mode mode
55+ * @param mask mask
56+ * @param creator creator, if known
57+ * @param creationTime creation time, if known
58+ */
59+ public DefaultModeInfo (@ NonNull Client client , @ NonNull Channel channel , @ NonNull ChannelMode mode , @ NonNull String mask , @ Nullable String creator , @ Nullable Instant creationTime ) {
60+ this .client = client ;
61+ this .creator = creator ;
62+ this .channel = channel ;
63+ this .mask = Mask .fromString (mask );
64+ this .creationTime = creationTime ;
65+ this .mode = mode ;
66+ }
67+
68+ @ Override
69+ public @ NonNull Optional <String > getCreator () {
70+ return Optional .ofNullable (this .creator );
71+ }
72+
73+ @ Override
74+ public @ NonNull Channel getChannel () {
75+ return this .channel ;
76+ }
77+
78+ @ Override
79+ public @ NonNull Client getClient () {
80+ return this .client ;
81+ }
82+
83+ @ Override
84+ public @ NonNull Mask getMask () {
85+ return this .mask ;
86+ }
87+
88+ @ Override
89+ public @ NonNull ChannelMode getMode () {
90+ return this .mode ;
91+ }
92+
93+ @ Override
94+ public @ NonNull Optional <Instant > getCreationTime () {
95+ return Optional .ofNullable (this .creationTime );
96+ }
97+
98+ @ Override
99+ public @ NonNull
100+ String toString () {
101+ return new ToStringer (this ).add ("client" , this .client ).add ("channel" , this .channel ).add ("mode" , this .mode ).add ("mask" , this .mask ).add ("creator" , this .creator ).add ("creationTime" , this .creationTime ).toString ();
102+ }
103+ }
0 commit comments