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.

ConfigTarget.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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 uk.org.ownage.dmdirc.identities;
  23. /**
  24. * Represents the target of a particular config source.
  25. * @author chris
  26. */
  27. public final class ConfigTarget implements Comparable {
  28. /** Indicates that the target is a global config source. */
  29. public static final int TYPE_GLOBAL = 1;
  30. /** Indicates that the target targets an ircd. */
  31. public static final int TYPE_IRCD = 2;
  32. /** Indicates that the target targets a network. */
  33. public static final int TYPE_NETWORK = 3;
  34. /** Indicates that the target targets a server. */
  35. public static final int TYPE_SERVER = 4;
  36. /** Indicates that the target targets a channel. */
  37. public static final int TYPE_CHANNEL = 5;
  38. /** The type of this target. */
  39. private int type;
  40. /** The data of this target. */
  41. private String data;
  42. /** Creates a new instance of ConfigTarget. */
  43. public ConfigTarget() {
  44. //Do nothing.
  45. }
  46. /** Sets this target to be a global config source. */
  47. public void setGlobal() {
  48. type = TYPE_GLOBAL;
  49. }
  50. /**
  51. * Sets this target to target an ircd.
  52. * @param ircd The ircd to target
  53. */
  54. public void setIrcd(final String ircd) {
  55. type = TYPE_IRCD;
  56. data = ircd;
  57. }
  58. /**
  59. * Sets this target to target a network.
  60. * @param network The network to target
  61. */
  62. public void setNetwork(final String network) {
  63. type = TYPE_NETWORK;
  64. data = network;
  65. }
  66. /**
  67. * Sets this target to target a server.
  68. * @param server The server to target
  69. */
  70. public void setServer(final String server) {
  71. type = TYPE_SERVER;
  72. data = server;
  73. }
  74. /**
  75. * Sets this target to target a channel.
  76. * @param channel The channel to target, in the form of channel@network
  77. */
  78. public void setChannel(final String channel) {
  79. type = TYPE_CHANNEL;
  80. data = channel;
  81. }
  82. /**
  83. * Retrieves the type of this target.
  84. * @return This target's type
  85. */
  86. public int getType() {
  87. return type;
  88. }
  89. /**
  90. * Returns a string representation of the type of this target.
  91. * @return A string describing this target's type
  92. */
  93. public String getTypeName() {
  94. switch(type) {
  95. case TYPE_GLOBAL:
  96. return "global";
  97. case TYPE_IRCD:
  98. return "ircd";
  99. case TYPE_NETWORK:
  100. return "network";
  101. case TYPE_SERVER:
  102. return "server";
  103. case TYPE_CHANNEL:
  104. return "channel";
  105. default:
  106. return "Unknown";
  107. }
  108. }
  109. /**
  110. * Retrieves the data associated with this target.
  111. * @return This target's data
  112. */
  113. public String getData() {
  114. return data;
  115. }
  116. /**
  117. * Compares this target to another to determine which is more specific.
  118. * @param target The target to compare to
  119. * @return -1 if this config is less specific, 0 if they're equal, +1 if
  120. * this is more specific
  121. */
  122. public int compareTo(final Object target) {
  123. return type - ((ConfigTarget) target).getType();
  124. }
  125. /**
  126. * Returns a string representation of this object.
  127. * @return A string representation of this object
  128. */
  129. public String toString() {
  130. switch (type) {
  131. case TYPE_GLOBAL:
  132. return "Global config";
  133. case TYPE_IRCD:
  134. return "Ircd specific: " + data;
  135. case TYPE_NETWORK:
  136. return "Network specific: " + data;
  137. case TYPE_SERVER:
  138. return "Server specific: " + data;
  139. case TYPE_CHANNEL:
  140. return "Channel specific: " + data;
  141. default:
  142. return "Unknown";
  143. }
  144. }
  145. }