X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=inline;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FProfile.java;h=55faf180aa3c1468ab6214c0fcc04ad2b20a353f;hb=d9206828d23e4c0092499c46ffd75f6792c928bc;hp=5a4fde041052c8c4f0a7228196eb5fba9b3698fa;hpb=6e9a43ccd93ae125720547c0fe421dc81a54ba90;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 5a4fde0..55faf18 100644
--- a/src/main/java/net/pterodactylus/sone/data/Profile.java
+++ b/src/main/java/net/pterodactylus/sone/data/Profile.java
@@ -1,5 +1,5 @@
/*
- * Sone - Profile.java - Copyright © 2010â2013 David Roden
+ * Sone - Profile.java - Copyright © 2010â2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -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");
- checkState(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 { }
+
}