import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.data.Profile;
+import net.pterodactylus.sone.data.Profile.DuplicateField;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.database.PostBuilder;
import net.pterodactylus.sone.database.PostReplyBuilder;
}
try {
profile.addField(fieldName.trim()).setValue(fieldValue);
- } catch (IllegalArgumentException iae1) {
- logger.log(Level.WARNING, String.format("Duplicate field: %s", fieldName), iae1);
+ } catch (DuplicateField df1) {
+ logger.log(Level.WARNING, String.format("Duplicate field: %s", fieldName), df1);
return null;
}
}
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 (getFieldByName(fieldName) != null) {
+ throw new DuplicateField();
+ }
@SuppressWarnings("synthetic-access")
Field field = new Field().setName(fieldName);
fields.add(field);
}
+ /**
+ * Exception that signals the addition of a field that already exists.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+ public static class DuplicateField extends IllegalArgumentException { }
+
}
import java.util.List;
import net.pterodactylus.sone.data.Profile;
+import net.pterodactylus.sone.data.Profile.DuplicateField;
import net.pterodactylus.sone.data.Profile.Field;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.FreenetRequest;
fields = profile.getFields();
webInterface.getCore().touchConfiguration();
throw new RedirectException("editProfile.html#profile-fields");
- } catch (IllegalArgumentException iae1) {
+ } catch (DuplicateField df1) {
templateContext.set("fieldName", fieldName);
templateContext.set("duplicateFieldName", true);
}