package net.wotonomy.foundation; import java.io.Serializable; import java.util.Objects; /** * Represents an error code. * * @author bjculkin * */ public class NSError implements Serializable { private static final long serialVersionUID = 532874201592029465L; public static final String NSWotonomyDomain = "wotonomy"; public static final String NSJavaDomain = "java"; public final String domain; public final int error; public final NSDictionary userInfo; private String description; private NSArray underlyingErrors = new NSMutableArray<>(); @SuppressWarnings("unchecked") public NSError(String domain, int error) { this(domain, error, (NSDictionary) NSDictionary.EmptyDictionary); } public NSError(String domain, int error, NSDictionary userInfo) { this.domain = domain; this.error = error; this.userInfo = userInfo; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public NSArray getUnderlyingErrors() { return underlyingErrors; } public void addUnderlyingError(NSError underlying) { underlyingErrors.add(underlying); } @Override public int hashCode() { return Objects.hash(domain, error, userInfo, description); } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; NSError other = (NSError) obj; return Objects.equals(domain, other.domain) && error == other.error && Objects.equals(userInfo, other.userInfo) && Objects.equals(description, other.description); } }