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.

MutableAutoCommand.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Copyright (c) 2006-2014 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.ui.core.autocommands;
  23. import com.dmdirc.commandparser.auto.AutoCommand;
  24. import com.dmdirc.commandparser.auto.AutoCommandType;
  25. import com.google.common.base.MoreObjects;
  26. import java.util.Objects;
  27. import java.util.Optional;
  28. import javax.annotation.Nonnull;
  29. /**
  30. * Mutable version of an {@link AutoCommand}.
  31. */
  32. public class MutableAutoCommand {
  33. private Optional<String> server;
  34. private Optional<String> network;
  35. private Optional<String> profile;
  36. private String response;
  37. private AutoCommandType type;
  38. public MutableAutoCommand(@Nonnull final AutoCommand command) {
  39. this(command.getServer(),
  40. command.getNetwork(),
  41. command.getProfile(),
  42. command.getResponse(),
  43. command.getType());
  44. }
  45. public MutableAutoCommand(
  46. final Optional<String> server,
  47. final Optional<String> network,
  48. final Optional<String> profile,
  49. @Nonnull final String response,
  50. final AutoCommandType type) {
  51. this.server = server;
  52. this.network = network;
  53. this.profile = profile;
  54. this.response = response;
  55. this.type = type;
  56. }
  57. public Optional<String> getServer() {
  58. return server;
  59. }
  60. public void setServer(final Optional<String> server) {
  61. this.server = server;
  62. }
  63. public Optional<String> getNetwork() {
  64. return network;
  65. }
  66. public void setNetwork(final Optional<String> network) {
  67. this.network = network;
  68. }
  69. public Optional<String> getProfile() {
  70. return profile;
  71. }
  72. public void setProfile(final Optional<String> profile) {
  73. this.profile = profile;
  74. }
  75. @Nonnull
  76. public String getResponse() {
  77. return response;
  78. }
  79. public void setResponse(@Nonnull final String response) {
  80. this.response = response;
  81. }
  82. public AutoCommandType getType() {
  83. return type;
  84. }
  85. public void setType(final AutoCommandType type) {
  86. this.type = type;
  87. }
  88. public AutoCommand getAutoCommand() {
  89. return AutoCommand.create(server, network, profile, response);
  90. }
  91. @Override
  92. public boolean equals(final Object object) {
  93. if (object == null) {
  94. return false;
  95. }
  96. if (getClass() != object.getClass()) {
  97. return false;
  98. }
  99. final MutableAutoCommand command = (MutableAutoCommand) object;
  100. return Objects.equals(server, command.getServer()) &&
  101. Objects.equals(network, command.getNetwork()) &&
  102. Objects.equals(profile, command.getProfile()) &&
  103. Objects.equals(response, command.getResponse());
  104. }
  105. public boolean equalsAutoCommand(final AutoCommand command) {
  106. return command != null && Objects.equals(server, command.getServer()) &&
  107. Objects.equals(network, command.getNetwork()) &&
  108. Objects.equals(profile, command.getProfile()) &&
  109. Objects.equals(response, command.getResponse());
  110. }
  111. @Override
  112. public int hashCode() {
  113. return Objects.hash(server, network, profile, response);
  114. }
  115. @Override
  116. public String toString() {
  117. return MoreObjects.toStringHelper(this)
  118. .add("Connection", server)
  119. .add("Network", network)
  120. .add("Profile", profile)
  121. .add("Response", response)
  122. .toString();
  123. }
  124. }