/*-------------------------------------------------------------------------------------------------------------------*\
|  Copyright (C) 2015 PayPal                                                                                          |
|                                                                                                                     |
|  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance     |
|  with the License.                                                                                                  |
|                                                                                                                     |
|  You may obtain a copy of the License at                                                                            |
|                                                                                                                     |
|       http://www.apache.org/licenses/LICENSE-2.0                                                                    |
|                                                                                                                     |
|  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed   |
|  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for  |
|  the specific language governing permissions and limitations under the License.                                     |
\*-------------------------------------------------------------------------------------------------------------------*/

package com.paypal.selion.platform.dataprovider.pojos;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * Mappable class for a collection of KeyValuePair
 */
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class KeyValueMap {


    private Map<String, KeyValuePair> map;

    public Map<String, KeyValuePair> getMap() {
        if (map == null) {
            map = new LinkedHashMap<String, KeyValuePair>();
        }
        return map;
    }

    @XmlElement(name = "item")
    private List<KeyValuePair> getItems() {
        return new ArrayList<KeyValuePair>(getMap().values());
    }

    public List<Map.Entry<String, String>> getEntries() {
        List<Map.Entry<String, String>> returned = new ArrayList<Map.Entry<String, String>>(getMap().values().size());
        for (KeyValuePair item : getMap().values()) {
            returned.add(new AbstractMap.SimpleImmutableEntry<String, String>(item.getKey(), item.getValue()));
        }
        return returned;
    }

    @SuppressWarnings("unused")
    private void setItems(final List<KeyValuePair> items) {
        getMap().clear();
        for (KeyValuePair item : items) {
            getMap().put(item.getKey(), item);
        }
    }

}
@@ -1734,144 +1734,8 @@
 s;%0A%0A
-import java.util.AbstractMap;%0Aimport java.util.ArrayList;%0Aimport java.util.LinkedHashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0A
 impo
@@ -1921,16 +1921,93 @@
 Element;
+%0Aimport java.util.LinkedHashMap;%0Aimport java.util.List;%0Aimport java.util.Map;
 %0A%0A/**%0A *
@@ -2140,17 +2140,16 @@
 eMap %7B%0A%0A
-%0A
     priv
@@ -2152,28 +2152,21 @@
 private 
-Map%3CString, 
+List%3C
 KeyValue
@@ -2175,159 +2175,89 @@
 ir%3E 
-map
+items
 ;%0A%0A    
-public Map%3CString, KeyValuePair%3E getMap() %7B%0A        if (map == null) %7B%0A            map = new LinkedHashMap%3CString, KeyValuePair%3E();%0A        %7D
+@XmlElement(name = %22item%22)%0A    public List%3CKeyValuePair%3E getItems() %7B
 %0A   
@@ -2272,11 +2272,13 @@
 urn 
-map
+items
 ;%0A  
@@ -2290,47 +2290,29 @@
     
-@XmlElement(name = %22item%22)%0A    private 
+public void setItems(
 List
@@ -2322,33 +2322,29 @@
 yValuePair%3E 
-getI
+i
 tems
-(
 ) %7B%0A        
@@ -2347,244 +2347,148 @@
     
-return new ArrayList%3CKeyValuePair%3E(getMap().values());%0A    %7D%0A%0A    public List%3CMap.Entry%3CString, String%3E%3E getEntries() %7B%0A        List%3CMap.Entry%3CString, String%3E%3E returned = new ArrayList%3CMap.Entry%3CString, String%3E%3E(getMap().values().size()
+this.items = items;%0A    %7D%0A%0A    public Map%3CString, KeyValuePair%3E getMap() %7B%0A        Map%3CString, KeyValuePair%3E returned = new LinkedHashMap%3C%3E(
 );%0A 
@@ -2526,19 +2526,12 @@
  get
-Map().value
+Item
 s())
@@ -2558,64 +2558,11 @@
 ned.
-add(new AbstractMap.SimpleImmutableEntry%3CString, String%3E
+put
 (ite
@@ -2581,20 +2581,8 @@
 item
-.getValue())
 );%0A 
@@ -2626,229 +2626,5 @@
  %7D%0A%0A
-    @SuppressWarnings(%22unused%22)%0A    private void setItems(final List%3CKeyValuePair%3E items) %7B%0A        getMap().clear();%0A        for (KeyValuePair item : items) %7B%0A            getMap().put(item.getKey(), item);%0A        %7D%0A    %7D%0A%0A
 %7D

Fix for #192