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 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright (c) 2006-2012 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 = 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. /**
  74. * Sets the hostname of this user.
  75. *
  76. * @param host The new hostname
  77. */
  78. protected void setHostname(final String host) {
  79. this.host = host;
  80. }
  81. /**
  82. * Sets the nickname of this user.
  83. *
  84. * @param nick The new nickname
  85. */
  86. protected void setLocalNickname(final String nick) {
  87. this.nick = nick;
  88. }
  89. /**
  90. * Sets the realname of this user.
  91. *
  92. * @param realname The new realname
  93. */
  94. protected void setRealname(final String realname) {
  95. this.realname = realname;
  96. }
  97. /**
  98. * Sets the username of this user.
  99. *
  100. * @param user The new username
  101. */
  102. protected void setUsername(final String user) {
  103. this.user = user;
  104. }
  105. /** {@inheritDoc} */
  106. @Override
  107. public Map<Object, Object> getMap() {
  108. return map;
  109. }
  110. /** {@inheritDoc} */
  111. @Override
  112. public Parser getParser() {
  113. return parser;
  114. }
  115. /** {@inheritDoc} */
  116. @Override
  117. public String toString() {
  118. return getNickname();
  119. }
  120. }