From 671f7e20aab401e972ede3c7d8eb30d92f4dc547 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 14 Jan 2011 12:04:58 +0100 Subject: [PATCH] Add method to rename a field. --- src/main/java/net/pterodactylus/sone/data/Profile.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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. * -- 2.7.4