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.

AutoCommand.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.commandparser.auto;
  23. import com.google.common.base.Objects;
  24. import com.google.common.base.Optional;
  25. /**
  26. * Describes a command that is executed automatically in response to either the client opening, or a
  27. * server connecting.
  28. */
  29. public class AutoCommand {
  30. /** The name of the server for connection events. */
  31. private final Optional<String> server;
  32. /** The name of the network for connection events. */
  33. private final Optional<String> network;
  34. /** The name of the profile for connection events. */
  35. private final Optional<String> profile;
  36. /** The commands to execute. */
  37. private final String response;
  38. public AutoCommand(
  39. final Optional<String> server,
  40. final Optional<String> network,
  41. final Optional<String> profile,
  42. final String response) {
  43. this.server = server;
  44. this.network = network;
  45. this.profile = profile;
  46. this.response = response;
  47. }
  48. public Optional<String> getServer() {
  49. return server;
  50. }
  51. public Optional<String> getNetwork() {
  52. return network;
  53. }
  54. public Optional<String> getProfile() {
  55. return profile;
  56. }
  57. public String getResponse() {
  58. return response;
  59. }
  60. @Override
  61. public boolean equals(final Object object) {
  62. if (object == null) {
  63. return false;
  64. }
  65. if (getClass() != object.getClass()) {
  66. return false;
  67. }
  68. final AutoCommand command = (AutoCommand) object;
  69. return Objects.equal(server, command.getServer())
  70. && Objects.equal(network, command.getNetwork())
  71. && Objects.equal(profile, command.getProfile())
  72. && Objects.equal(response, command.getResponse());
  73. }
  74. @Override
  75. public int hashCode() {
  76. return Objects.hashCode(server, network, profile, response);
  77. }
  78. @Override
  79. public String toString() {
  80. return Objects.toStringHelper(this)
  81. .add("Connection", server)
  82. .add("Network", network)
  83. .add("Profile", profile)
  84. .add("Response", response)
  85. .toString();
  86. }
  87. }