From 9c681f38b742b26b841eb42bc19879cb90ac03de Mon Sep 17 00:00:00 2001 From: Benjamin Culkin Date: Mon, 8 Jul 2024 17:30:58 -0400 Subject: Add XML property lists Implement support for the XML property lists that are the newer version of the ASCII ones. There are a few things that still need to be done, but all of the basics are there Next things - Allow collapsing a property list into a series of objects - Serialize both the property list and flattened objects to XML --- .../main/java/net/wotonomy/foundation/NSError.java | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSError.java (limited to 'projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSError.java') diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSError.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSError.java new file mode 100644 index 0000000..9e46b5e --- /dev/null +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSError.java @@ -0,0 +1,71 @@ +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); + } +} -- cgit v1.2.3