/*
Copyright (c) 2013, Colorado State University
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

This software is provided by the copyright holders and contributors "as is" and
any express or implied warranties, including, but not limited to, the implied
warranties of merchantability and fitness for a particular purpose are
disclaimed. In no event shall the copyright holder or contributors be liable for
any direct, indirect, incidental, special, exemplary, or consequential damages
(including, but not limited to, procurement of substitute goods or services;
loss of use, data, or profits; or business interruption) however caused and on
any theory of liability, whether in contract, strict liability, or tort
(including negligence or otherwise) arising in any way out of the use of this
software, even if advised of the possibility of such damage.
*/

package galileo.dataset.feature;

import galileo.serialization.ByteSerializable;
import galileo.serialization.SerializationInputStream;
import galileo.serialization.SerializationOutputStream;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Maps array names (Strings) to their respective FeatureArrays.
 *
 * @author malensek
 */
public class FeatureArraySet
implements ByteSerializable, Iterable<FeatureArray> {

    private Map<String, FeatureArray> arrays = new HashMap<>();

    public FeatureArraySet() { }

    public void put(FeatureArray array) {
        arrays.put(array.getName(), array);
    }

    public FeatureArray get(String name) {
        return arrays.get(name);
    }

    @Override
    public Iterator<FeatureArray> iterator() {
        return arrays.values().iterator();
    }

    @Deserialize
    public FeatureArraySet(SerializationInputStream in)
    throws IOException {
        int numArrays = in.readInt();
        for (int i = 0; i < numArrays; ++i) {
            FeatureArray array = new FeatureArray(in);
            put(array);
        }
    }

    @Override
    public void serialize(SerializationOutputStream out)
    throws IOException {
        out.writeInt(arrays.size());
        for (FeatureArray array : arrays.values()) {
            out.writeSerializable(array);
        }
    }
}

@@ -1365,38 +1365,126 @@
 leo.
-serialization.ByteSerializable
+dataset.SimpleMap;%0Aimport galileo.serialization.ByteSerializable;%0A%0Aimport galileo.serialization.SerializationException
 ;%0Aim
@@ -1617,24 +1617,53 @@
 OException;%0A
+import java.util.Collection;%0A
 import java.
@@ -1902,16 +1902,57 @@
 reArray%3E
+,%0A        SimpleMap%3CString, FeatureArray%3E
  %7B%0A%0A    
@@ -2042,24 +2042,38 @@
 ySet() %7B %7D%0A%0A
+    @Override%0A
     public v
@@ -2149,24 +2149,38 @@
 ay);%0A    %7D%0A%0A
+    @Override%0A
     public F
@@ -2370,18 +2370,15 @@
    @
-Deserializ
+Overrid
 e%0A  
@@ -2378,32 +2378,43 @@
 ride%0A    public 
+Collection%3C
 FeatureArraySet(
@@ -2413,108 +2413,57 @@
 rray
-Set(SerializationInputStream in)%0A    throws IOException %7B%0A        int numArrays = in.readInt
+%3E values() %7B%0A        return arrays.values
 ();%0A    
     
@@ -2462,138 +2462,259 @@
     
+%7D%0A%0A
     
-for (int i = 0; i %3C numArrays; ++i) %7B%0A            FeatureArray array = new FeatureArray(
+@Override%0A    public int size() %7B%0A        return arrays.size();%0A    %7D%0A%0A    @Deserialize%0A    public FeatureArraySet(SerializationInputStream 
 in)
-;
 %0A    
-        put(array);%0A        %7D
+throws IOException, SerializationException %7B%0A        in.readSimpleMap(FeatureArray.class, this);
 %0A   
@@ -2834,132 +2834,24 @@
 rite
-Int(arrays.size());%0A        for (FeatureArray array : arrays.values()) %7B%0A            out.writeSerializable(array);%0A        %7D
+SimpleMap(this);
 %0A   

Implement SimpleMap