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