You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BaseClientInfo.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.parser.common;
  23. import com.dmdirc.parser.interfaces.ClientInfo;
  24. import com.dmdirc.parser.interfaces.Parser;
  25. import java.util.HashMap;
  26. import java.util.Map;
  27. /**
  28. * Provides a basic implementation of the {@link ClientInfo} interface.
  29. */
  30. public abstract class BaseClientInfo implements ClientInfo {
  31. /** The parser that owns this client. */
  32. private final Parser parser;
  33. /** A map for random data associated with the client to be stored in. */
  34. private final Map<Object, Object> map = new HashMap<>();
  35. /** The user's details. */
  36. private String nick;
  37. private String user;
  38. private String host;
  39. private String realname;
  40. private String account;
  41. /**
  42. * Creates a new base client info for the specified parser with the
  43. * specified details.
  44. *
  45. * @param parser The parser that owns this client info object
  46. * @param nick The nickname of the user this object represents
  47. * @param user The username of the user this object represents
  48. * @param host The hostname of the user this object represents
  49. */
  50. public BaseClientInfo(final Parser parser, final String nick,
  51. final String user, final String host) {
  52. this.parser = parser;
  53. this.nick = nick;
  54. this.user = user;
  55. this.host = host;
  56. }
  57. @Override
  58. public String getNickname() {
  59. return nick;
  60. }
  61. @Override
  62. public String getUsername() {
  63. return user;
  64. }
  65. @Override
  66. public String getHostname() {
  67. return host;
  68. }
  69. @Override
  70. public String getRealname() {
  71. return realname;
  72. }
  73. @Override
  74. public String getAccountName() {
  75. return account;
  76. }
  77. /**
  78. * Sets the hostname of this user.
  79. *
  80. * @param host The new hostname
  81. */
  82. protected void setHostname(final String host) {
  83. this.host = host;
  84. }
  85. /**
  86. * Sets the nickname of this user.
  87. *
  88. * @param nick The new nickname
  89. */
  90. protected void setLocalNickname(final String nick) {
  91. this.nick = nick;
  92. }
  93. /**
  94. * Sets the realname of this user.
  95. *
  96. * @param realname The new realname
  97. */
  98. protected void setRealname(final String realname) {
  99. this.realname = realname;
  100. }
  101. /**
  102. * Sets the account of this user.
  103. *
  104. * @param account The new account
  105. */
  106. protected void setAccountName(final String account) {
  107. this.account = account;
  108. }
  109. /**
  110. * Sets the username of this user.
  111. *
  112. * @param user The new username
  113. */
  114. protected void setUsername(final String user) {
  115. this.user = user;
  116. }
  117. @Override
  118. @SuppressWarnings("ReturnOfCollectionOrArrayField")
  119. public Map<Object, Object> getMap() {
  120. return map;
  121. }
  122. @Override
  123. public Parser getParser() {
  124. return parser;
  125. }
  126. @Override
  127. public String toString() {
  128. return getNickname();
  129. }
  130. @Override
  131. public String getAwayReason() {
  132. return "";
  133. }
  134. }