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.

CapabilityState.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2006-2017 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.irc;
  23. /**
  24. * Capability states.
  25. * See: http://ircv3.atheme.org/specification/capability-negotiation-3.1
  26. */
  27. public enum CapabilityState {
  28. /** Capability is invalid*/
  29. INVALID("Invalid", (char)0),
  30. /** Capability is disabled */
  31. DISABLED("Disabled", '-'),
  32. /** Capability is pending enabling, (needs ACK) */
  33. NEED_ACK("Needs ack", '~'),
  34. /** Capability is enabled entirely */
  35. ENABLED("Enabled", '+');
  36. /** Description. */
  37. private final String description;
  38. /**
  39. * Modifier.
  40. * This should probably be called symbol, but the docs refer to the symbols
  41. * as "capability modifiers". We just use them to make parsing the messages
  42. * a bit easier.
  43. */
  44. private final Character modifier;
  45. /**
  46. * Create a CapabilityState.
  47. *
  48. * @param description Description of capability.
  49. */
  50. CapabilityState(final String description, final Character modifier) {
  51. this.description = description;
  52. this.modifier = modifier;
  53. }
  54. /**
  55. * Get the description for this capability state.
  56. *
  57. * @return Description for this capability state.
  58. */
  59. public String getDescription() {
  60. return description;
  61. }
  62. /**
  63. * Get the modifier for this capability state.
  64. *
  65. * @return modifier for this capability state.
  66. */
  67. public char getModifier() {
  68. return modifier;
  69. }
  70. /**
  71. * Get the capability state for the given modifier, or null.
  72. *
  73. * @param modifier Modifier to get the capability for
  74. *
  75. * @return state for the given modifier, or null.
  76. */
  77. public static CapabilityState fromModifier(final char modifier) {
  78. for (CapabilityState cs : CapabilityState.values()) {
  79. if (cs.getModifier() == modifier) {
  80. return cs;
  81. }
  82. }
  83. return CapabilityState.INVALID;
  84. }
  85. }