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.

ProgramError.java 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Copyright (c) 2006-2008 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 com.dmdirc.logger;
  23. import java.io.Serializable;
  24. import java.util.Arrays;
  25. import java.util.Date;
  26. /**
  27. * Stores a program error.
  28. */
  29. public final class ProgramError implements Serializable {
  30. /**
  31. * A version number for this class. It should be changed whenever the class
  32. * structure is changed (or anything else that would prevent serialized
  33. * objects being unserialized with the new class).
  34. */
  35. private static final long serialVersionUID = 3;
  36. /** Error ID. */
  37. private final long id;
  38. /** Error icon. */
  39. private final ErrorLevel level;
  40. /** Error message. */
  41. private final String message;
  42. /** Error trace. */
  43. private final String[] trace;
  44. /** Date/time error occurred. */
  45. private final Date date;
  46. /** Error report Status. */
  47. private ErrorReportStatus reportStatus;
  48. /** Error fixed Status. */
  49. private ErrorFixedStatus fixedStatus;
  50. /**
  51. * Creates a new instance of ProgramError.
  52. *
  53. * @param id error id
  54. * @param level Error level
  55. * @param message Error message
  56. * @param trace Error trace
  57. * @param date Error time and date
  58. */
  59. public ProgramError(final long id, final ErrorLevel level,
  60. final String message, final String[] trace, final Date date) {
  61. if (id < 0) {
  62. throw new IllegalArgumentException("ID must be a positive integer: " + id);
  63. }
  64. if (level == null) {
  65. throw new IllegalArgumentException("Level cannot be null");
  66. }
  67. if (message == null || message.isEmpty()) {
  68. throw new IllegalArgumentException("Message cannot be null or an empty string");
  69. }
  70. if (trace == null) {
  71. throw new IllegalArgumentException("Trace cannot be null");
  72. }
  73. if (date == null) {
  74. throw new IllegalArgumentException("date cannot be null");
  75. }
  76. this.id = id;
  77. this.level = level;
  78. this.message = message;
  79. this.trace = Arrays.copyOf(trace, trace.length);
  80. this.date = (Date) date.clone();
  81. this.reportStatus = ErrorReportStatus.WAITING;
  82. this.fixedStatus = ErrorFixedStatus.UNKNOWN;
  83. }
  84. /**
  85. * Returns this errors level.
  86. *
  87. * @return Error level
  88. */
  89. public ErrorLevel getLevel() {
  90. return level;
  91. }
  92. /**
  93. * Returns this errors message.
  94. *
  95. * @return Error message
  96. */
  97. public String getMessage() {
  98. return message;
  99. }
  100. /**
  101. * Returns this errors trace.
  102. *
  103. * @return Error trace
  104. */
  105. public String[] getTrace() {
  106. return Arrays.copyOf(trace, trace.length);
  107. }
  108. /**
  109. * Returns this errors time.
  110. *
  111. * @return Error time
  112. */
  113. public Date getDate() {
  114. return (Date) date.clone();
  115. }
  116. /**
  117. * Returns the reportStatus of this error.
  118. *
  119. * @return Error reportStatus
  120. */
  121. public ErrorReportStatus getReportStatus() {
  122. return reportStatus;
  123. }
  124. /**
  125. * Returns the fixed status of this error.
  126. *
  127. * @return Error fixed status
  128. */
  129. public ErrorFixedStatus getFixedStatus() {
  130. return fixedStatus;
  131. }
  132. /**
  133. * Sets the report Status of this error.
  134. *
  135. * @param newStatus new ErrorReportStatus for the error
  136. */
  137. public void setReportStatus(final ErrorReportStatus newStatus) {
  138. if (newStatus != null && !reportStatus.equals(newStatus)) {
  139. reportStatus = newStatus;
  140. ErrorManager.getErrorManager().fireErrorStatusChanged(this);
  141. }
  142. }
  143. /**
  144. * Sets the fixed status of this error.
  145. *
  146. * @param newStatus new ErrorFixedStatus for the error
  147. */
  148. public void setFixedStatus(final ErrorFixedStatus newStatus) {
  149. if (newStatus != null && !fixedStatus.equals(newStatus)) {
  150. fixedStatus = newStatus;
  151. ErrorManager.getErrorManager().fireErrorStatusChanged(this);
  152. }
  153. }
  154. /**
  155. * Returns the ID of this error.
  156. *
  157. * @return Error ID
  158. */
  159. public long getID() {
  160. return id;
  161. }
  162. /** {@inheritDoc} */
  163. @Override
  164. public String toString() {
  165. return "ID" + id + " Level: " + getLevel() + " Status: " + getReportStatus()
  166. + " Message: '" + getMessage() + "'";
  167. }
  168. /** {@inheritDoc} */
  169. @Override
  170. public boolean equals(final Object obj) {
  171. if (obj == null) {
  172. return false;
  173. }
  174. if (getClass() != obj.getClass()) {
  175. return false;
  176. }
  177. final ProgramError other = (ProgramError) obj;
  178. if (this.level != other.level) {
  179. return false;
  180. }
  181. if (this.message == null || !this.message.equals(other.message)) {
  182. return false;
  183. }
  184. if (this.trace == null || !Arrays.equals(this.trace, other.trace)) {
  185. return false;
  186. }
  187. return true;
  188. }
  189. /** {@inheritDoc} */
  190. @Override
  191. public int hashCode() {
  192. int hash = 7;
  193. hash = 67 * hash + (this.level == null ? 0 : this.level.hashCode());
  194. hash = 67 * hash + (this.message == null ? 0 : this.message.hashCode());
  195. hash = 67 * hash + (this.trace == null ? 0 : Arrays.hashCode(this.trace));
  196. return hash;
  197. }
  198. }