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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (c) 2006-2013 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<Object, Object>();
  35. /** The user's details. */
  36. private String nick, user, host, realname, account = null;
  37. /**
  38. * Creates a new base client info for the specified parser with the
  39. * specified details.
  40. *
  41. * @param parser The parser that owns this client info object
  42. * @param nick The nickname of the user this object represents
  43. * @param user The username of the user this object represents
  44. * @param host The hostname of the user this object represents
  45. */
  46. public BaseClientInfo(final Parser parser, final String nick,
  47. final String user, final String host) {
  48. this.parser = parser;
  49. this.nick = nick;
  50. this.user = user;
  51. this.host = host;
  52. }
  53. /** {@inheritDoc} */
  54. @Override
  55. public String getNickname() {
  56. return nick;
  57. }
  58. /** {@inheritDoc} */
  59. @Override
  60. public String getUsername() {
  61. return user;
  62. }
  63. /** {@inheritDoc} */
  64. @Override
  65. public String getHostname() {
  66. return host;
  67. }
  68. /** {@inheritDoc} */
  69. @Override
  70. public String getRealname() {
  71. return realname;
  72. }
  73. /** {@inheritDoc} */
  74. @Override
  75. public String getAccountName() {
  76. return account;
  77. }
  78. /**
  79. * Sets the hostname of this user.
  80. *
  81. * @param host The new hostname
  82. */
  83. protected void setHostname(final String host) {
  84. this.host = host;
  85. }
  86. /**
  87. * Sets the nickname of this user.
  88. *
  89. * @param nick The new nickname
  90. */
  91. protected void setLocalNickname(final String nick) {
  92. this.nick = nick;
  93. }
  94. /**
  95. * Sets the realname of this user.
  96. *
  97. * @param realname The new realname
  98. */
  99. protected void setRealname(final String realname) {
  100. this.realname = realname;
  101. }
  102. /**
  103. * Sets the account of this user.
  104. *
  105. * @param account The new account
  106. */
  107. protected void setAccountName(final String account) {
  108. this.account = account;
  109. }
  110. /**
  111. * Sets the username of this user.
  112. *
  113. * @param user The new username
  114. */
  115. protected void setUsername(final String user) {
  116. this.user = user;
  117. }
  118. /** {@inheritDoc} */
  119. @Override
  120. public Map<Object, Object> getMap() {
  121. return map;
  122. }
  123. /** {@inheritDoc} */
  124. @Override
  125. public Parser getParser() {
  126. return parser;
  127. }
  128. /** {@inheritDoc} */
  129. @Override
  130. public String toString() {
  131. return getNickname();
  132. }
  133. /** {@inheritDoc} */
  134. @Override
  135. public String getAwayReason() {
  136. return "";
  137. }
  138. }