/*
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 java.util.HashMap;
import java.util.Map;

public enum FeatureType {
    NULL (0),
    INT (1),
    LONG (2),
    FLOAT (3),
    DOUBLE (4),
    INTERVAL_INT (5),
    INTERVAL_LONG (6),
    INTERVAL_FLOAT (7),
    INTERVAL_DOUBLE (8),
    STRING (9);

    private final int type;

    private FeatureType(int type) {
        this.type = type;
    }

    public int toInt() {
        return type;
    }

    static Map<Integer, FeatureType> typeMap = new HashMap<>();

    static {
        for (FeatureType t : FeatureType.values()) {
            typeMap.put(t.toInt(), t);
        }
    }

    /**
     * Determine the FeatureType associated with the given integer.
     *
     * @param i Integer representing a FeatureType element.
     *
     * @return the associated FeatureType for the integer, or null if no
     * FeatureType exists.
     */
    public static FeatureType fromInt(int i) {
        FeatureType t = typeMap.get(i);
        if (t == null) {
            return FeatureType.NULL;
        }

        return t;
    }

    static Map<Class<?>, FeatureType> primitiveMap = new HashMap<>();

    static {
        primitiveMap.put(Integer.class, INT);
        primitiveMap.put(Long.class, LONG);
        primitiveMap.put(Float.class, FLOAT);
        primitiveMap.put(Double.class, DOUBLE);
        primitiveMap.put(String.class, STRING);
    }

    /**
     * Basic Feature types based on Java classes (/primitives) can be
     * ascertained by inspecting their generic parameters.  Other FeatureTypes,
     * such as intervals, can't be discovered by this method.
     *
     * @param type The basic Java type to inspect
     *
     * @return Corresponding FeatureType for the Java type, or null if no
     * FeatureType exists.
     */
    public static <T> FeatureType fromPrimitiveType(T type) {
        return primitiveMap.get(type.getClass());
    }

    /**
     * Provides a mapping between FeatureType elements and their corresponding
     * FeatureData implementations.
     */
    public Class<? extends FeatureData<?>> toClass() {
        switch (this) {
            case NULL: return NullFeatureData.class;
            case INT: return IntegerFeatureData.class;
            case LONG: return LongFeatureData.class;
            case FLOAT: return FloatFeatureData.class;
            case DOUBLE: return DoubleFeatureData.class;
            case INTERVAL_INT: return IntegerIntervalFeatureData.class;
            case INTERVAL_LONG: return LongIntervalFeatureData.class;
            case INTERVAL_FLOAT: return FloatIntervalFeatureData.class;
            case INTERVAL_DOUBLE: return DoubleIntervalFeatureData.class;
            case STRING: return StringFeatureData.class;
            default: return null;
        }

    }
}

@@ -1601,16 +1601,33 @@
 RING (9)
+,%0A    BINARY (10)
 ;%0A%0A    p
@@ -2714,24 +2714,72 @@
 s, STRING);%0A
+        primitiveMap.put(Byte%5B%5D.class, BINARY);%0A
     %7D%0A%0A    /
@@ -4105,32 +4105,89 @@
 tureData.class;%0A
+            case BINARY: return BinaryFeatureData.class;%0A
             defa
@@ -4210,21 +4210,20 @@
 ;%0A        %7D%0A
-%0A
     %7D%0A%7D%0A

Update FeatureType for BinaryFeatureData