Add method to rename a field.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 14 Jan 2011 11:04:58 +0000 (12:04 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 14 Jan 2011 11:04:58 +0000 (12:04 +0100)
src/main/java/net/pterodactylus/sone/data/Profile.java

index d0a659c..f6e2bed 100644 (file)
@@ -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.
         *