Copy field names, too.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Profile.java
index 8dec42a..d0a659c 100644 (file)
@@ -20,6 +20,7 @@ package net.pterodactylus.sone.data;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -80,6 +81,7 @@ public class Profile implements Fingerprintable {
                this.birthDay = profile.birthDay;
                this.birthMonth = profile.birthMonth;
                this.birthYear = profile.birthYear;
+               this.fields.addAll(profile.fields);
                this.fieldValues.putAll(profile.fieldValues);
        }
 
@@ -317,6 +319,19 @@ public class Profile implements Fingerprintable {
        /**
         * Sets the value of the field with the given name.
         *
+        * @param fieldIndex
+        *            The index of the field
+        * @param value
+        *            The value of the field
+        */
+       public void setField(int fieldIndex, String value) {
+               Validation.begin().isGreaterOrEqual("Field Index", fieldIndex, 0).isLess("Field Index", fieldIndex, fields.size()).check();
+               setField(fields.get(fieldIndex), value);
+       }
+
+       /**
+        * Sets the value of the field with the given name.
+        *
         * @param field
         *            The name of the field
         * @param value
@@ -332,10 +347,24 @@ public class Profile implements Fingerprintable {
         *
         * @return The fields of this profile
         */
-       public List<String> getFields() {
+       public List<String> getFieldNames() {
                return Collections.unmodifiableList(fields);
        }
 
+       /**
+        * Returns all field names and their values, ordered the same way
+        * {@link #getFieldNames()} returns the names of the fields.
+        *
+        * @return All field names and values
+        */
+       public Map<String, String> getFields() {
+               Map<String, String> fields = new LinkedHashMap<String, String>();
+               for (String field : getFieldNames()) {
+                       fields.put(field, getField(field));
+               }
+               return fields;
+       }
+
        //
        // PRIVATE METHODS
        //