Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

UserInfoResponseEvent.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2006-2015 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.events;
  23. import com.dmdirc.interfaces.Connection;
  24. import com.dmdirc.interfaces.User;
  25. import com.dmdirc.parser.events.UserInfoEvent;
  26. import java.util.Collection;
  27. import java.util.EnumMap;
  28. import java.util.Map;
  29. import java.util.Optional;
  30. /**
  31. * Event raised when detailed user info has been received for a user.
  32. */
  33. public class UserInfoResponseEvent extends ServerDisplayableEvent {
  34. private final User user;
  35. private final Map<UserInfoEvent.UserInfoType, UserInfoProperty> info;
  36. public UserInfoResponseEvent(final Connection connection, final long date,
  37. final User user, final Map<UserInfoEvent.UserInfoType, String> info) {
  38. super(date, connection);
  39. this.user = user;
  40. this.info = new EnumMap<>(UserInfoEvent.UserInfoType.class);
  41. info.forEach((key, value) -> this.info.put(key, new UserInfoProperty(key, value)));
  42. }
  43. /**
  44. * Gets the client that the event is for.
  45. *
  46. * @return The user this event is for.
  47. */
  48. public User getUser() {
  49. return user;
  50. }
  51. /**
  52. * Gets a specific piece of information about the user.
  53. *
  54. * @param type The type of information to return.
  55. *
  56. * @return An optional containing the information, if it was provided.
  57. */
  58. public Optional<String> getInfo(final UserInfoEvent.UserInfoType type) {
  59. return Optional.ofNullable(info.get(type)).map(UserInfoProperty::getRawValue);
  60. }
  61. /**
  62. * Gets a collection of all info properties in the response.
  63. *
  64. * @return A collection of all user info properties.
  65. */
  66. public Collection<UserInfoProperty> getProperties() {
  67. return info.values();
  68. }
  69. public static class UserInfoProperty {
  70. private final UserInfoEvent.UserInfoType type;
  71. private final String rawValue;
  72. public UserInfoProperty(final UserInfoEvent.UserInfoType type, final String rawValue) {
  73. this.type = type;
  74. this.rawValue = rawValue;
  75. }
  76. public UserInfoEvent.UserInfoType getType() {
  77. return type;
  78. }
  79. public String getRawValue() {
  80. return rawValue;
  81. }
  82. public String getFriendlyName() {
  83. return type.name().charAt(0) + type.name().substring(1).toLowerCase().replace('_', ' ');
  84. }
  85. }
  86. }