package com.sourcefellows.patterns.adapter;

import jakarta.xml.bind.annotation.adapters.XmlAdapter;

import java.util.ArrayList;
import java.util.HashMap;

public class MyHashMapAdapter extends XmlAdapter<MyHashMapType, HashMap<Integer, String>> {

    @Override
    public HashMap unmarshal(
            MyHashMapType myHashMapType)
            throws Exception {
        return null;
    }

    @Override
    public MyHashMapType marshal(
            HashMap<Integer, String> hashMap)
            throws Exception {

        var myMap = new MyHashMapType();
        myMap.entry = new ArrayList<>();

        hashMap.forEach((key, value) -> {
            var et = new MyHashMapEntryType(key, value);
            myMap.entry.add(et);
        });

        return myMap;
    }
}
