123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- /*
- * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
- package com.dmdirc.logger;
-
- import java.io.Serializable;
- import java.util.Arrays;
- import java.util.Date;
-
- /**
- * Stores a program error.
- */
- public final class ProgramError implements Serializable {
-
- /**
- * A version number for this class. It should be changed whenever the class
- * structure is changed (or anything else that would prevent serialized
- * objects being unserialized with the new class).
- */
- private static final long serialVersionUID = 3;
-
- /** Error ID. */
- private final long id;
-
- /** Error icon. */
- private final ErrorLevel level;
-
- /** Error message. */
- private final String message;
-
- /** Error trace. */
- private final String[] trace;
-
- /** Date/time error occurred. */
- private final Date date;
-
- /** Error report Status. */
- private ErrorReportStatus reportStatus;
-
- /** Error fixed Status. */
- private ErrorFixedStatus fixedStatus;
-
- /**
- * Creates a new instance of ProgramError.
- *
- * @param id error id
- * @param level Error level
- * @param message Error message
- * @param trace Error trace
- * @param date Error time and date
- */
- public ProgramError(final long id, final ErrorLevel level,
- final String message, final String[] trace, final Date date) {
- if (id < 0) {
- throw new IllegalArgumentException("ID must be a positive integer: " + id);
- }
- if (level == null) {
- throw new IllegalArgumentException("Level cannot be null");
- }
- if (message == null || message.isEmpty()) {
- throw new IllegalArgumentException("Message cannot be null or an empty string");
- }
- if (trace == null) {
- throw new IllegalArgumentException("Trace cannot be null");
- }
- if (date == null) {
- throw new IllegalArgumentException("date cannot be null");
- }
- this.id = id;
- this.level = level;
- this.message = message;
- this.trace = Arrays.copyOf(trace, trace.length);
- this.date = (Date) date.clone();
- this.reportStatus = ErrorReportStatus.WAITING;
- this.fixedStatus = ErrorFixedStatus.UNKNOWN;
- }
-
- /**
- * Returns this errors level.
- *
- * @return Error level
- */
- public ErrorLevel getLevel() {
- return level;
- }
-
- /**
- * Returns this errors message.
- *
- * @return Error message
- */
- public String getMessage() {
- return message;
- }
-
- /**
- * Returns this errors trace.
- *
- * @return Error trace
- */
- public String[] getTrace() {
- return Arrays.copyOf(trace, trace.length);
- }
-
- /**
- * Returns this errors time.
- *
- * @return Error time
- */
- public Date getDate() {
- return (Date) date.clone();
- }
-
- /**
- * Returns the reportStatus of this error.
- *
- * @return Error reportStatus
- */
- public ErrorReportStatus getReportStatus() {
- return reportStatus;
- }
-
- /**
- * Returns the fixed status of this error.
- *
- * @return Error fixed status
- */
- public ErrorFixedStatus getFixedStatus() {
- return fixedStatus;
- }
-
- /**
- * Sets the report Status of this error.
- *
- * @param newStatus new ErrorReportStatus for the error
- */
- public void setReportStatus(final ErrorReportStatus newStatus) {
- if (newStatus != null && !reportStatus.equals(newStatus)) {
- reportStatus = newStatus;
- ErrorManager.getErrorManager().fireErrorStatusChanged(this);
- }
- }
-
- /**
- * Sets the fixed status of this error.
- *
- * @param newStatus new ErrorFixedStatus for the error
- */
- public void setFixedStatus(final ErrorFixedStatus newStatus) {
- if (newStatus != null && !fixedStatus.equals(newStatus)) {
- fixedStatus = newStatus;
- ErrorManager.getErrorManager().fireErrorStatusChanged(this);
- }
- }
-
- /**
- * Returns the ID of this error.
- *
- * @return Error ID
- */
- public long getID() {
- return id;
- }
-
- /** {@inheritDoc} */
- @Override
- public String toString() {
- return "ID" + id + " Level: " + getLevel() + " Status: " + getReportStatus()
- + " Message: '" + getMessage() + "'";
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean equals(final Object obj) {
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final ProgramError other = (ProgramError) obj;
- if (this.level != other.level) {
- return false;
- }
- if (this.message == null || !this.message.equals(other.message)) {
- return false;
- }
- if (this.trace == null || !Arrays.equals(this.trace, other.trace)) {
- return false;
- }
- return true;
- }
-
- /** {@inheritDoc} */
- @Override
- public int hashCode() {
- int hash = 7;
- hash = 67 * hash + (this.level == null ? 0 : this.level.hashCode());
- hash = 67 * hash + (this.message == null ? 0 : this.message.hashCode());
- hash = 67 * hash + (this.trace == null ? 0 : Arrays.hashCode(this.trace));
- return hash;
- }
-
-
-
- }
|