From: David ‘Bombe’ Roden Date: Fri, 14 Jan 2011 11:04:58 +0000 (+0100) Subject: Add method to rename a field. X-Git-Tag: 0.4^2~9^2~29 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=671f7e20aab401e972ede3c7d8eb30d92f4dc547;p=Sone.git Add method to rename a field. --- diff --git a/src/main/java/net/pterodactylus/sone/data/Profile.java b/src/main/java/net/pterodactylus/sone/data/Profile.java index d0a659c..f6e2bed 100644 --- a/src/main/java/net/pterodactylus/sone/data/Profile.java +++ b/src/main/java/net/pterodactylus/sone/data/Profile.java @@ -352,6 +352,21 @@ public class Profile implements Fingerprintable { } /** + * Renames a fields. + * + * @param fieldIndex + * The index of the field to rename + * @param fieldName + * The new name of the field + */ + public void setFieldName(int fieldIndex, String fieldName) { + Validation.begin().isGreaterOrEqual("Field Index", fieldIndex, 0).isLess("Field Index", fieldIndex, fields.size()).isNotNull("Field Name", fieldName).isEqual("New Field Name Unique", !fields.contains(fieldName) || (getFieldIndex(fieldName) == fieldIndex), true).check(); + String value = fieldValues.remove(fields.get(fieldIndex)); + fields.set(fieldIndex, fieldName); + fieldValues.put(fieldName, value); + } + + /** * Returns all field names and their values, ordered the same way * {@link #getFieldNames()} returns the names of the fields. *