X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FProfile.java;h=4970cf9ffefd723ea22684d224571098b8caae18;hb=b15a7ce43a2fdad4fda640895892ff288486264a;hp=4bf26cc7b5d99abc88b849e957f01b4ddc786055;hpb=c07b7c86e363cddee344527e7e19472e3744b0c1;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/data/Profile.java b/src/main/java/net/pterodactylus/sone/data/Profile.java
index 4bf26cc..4970cf9 100644
--- a/src/main/java/net/pterodactylus/sone/data/Profile.java
+++ b/src/main/java/net/pterodactylus/sone/data/Profile.java
@@ -325,10 +325,14 @@ public class Profile implements Fingerprintable {
*/
public Field addField(String fieldName) throws IllegalArgumentException {
checkNotNull(fieldName, "fieldName must not be null");
- checkArgument(fieldName.length() > 0, "fieldName must not be empty");
- checkArgument(getFieldByName(fieldName) == null, "fieldName must be unique");
+ if (fieldName.length() == 0) {
+ throw new EmptyFieldName();
+ }
+ if (getFieldByName(fieldName) != null) {
+ throw new DuplicateField();
+ }
@SuppressWarnings("synthetic-access")
- Field field = new Field().setName(fieldName);
+ Field field = new Field().setName(fieldName).setValue("");
fields.add(field);
return field;
}
@@ -553,4 +557,18 @@ public class Profile implements Fingerprintable {
}
+ /**
+ * Exception that signals the addition of a field with an empty name.
+ *
+ * @author David âBombeâ Roden
+ */
+ public static class EmptyFieldName extends IllegalArgumentException { }
+
+ /**
+ * Exception that signals the addition of a field that already exists.
+ *
+ * @author David âBombeâ Roden
+ */
+ public static class DuplicateField extends IllegalArgumentException { }
+
}