package com.dailystudio.dataobject;

import java.lang.reflect.Array;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by nanye on 17/12/6.
 */

public class DatabaseObjectKeys {

    private Map<String, Object> mValues = new HashMap<>();

    public boolean hasValue(Column column) {
        if (column == null) {
            return false;
        }

        final String key = column.getName();
        if (!mValues.containsKey(key)) {
            return false;
        }

        final Object value = mValues.get(key);

        return value.getClass() == column.getValueClass();
    }

    public boolean hasArrayValue(Column column) {
        if (column == null) {
            return false;
        }

        final String key = column.getName();
        if (!mValues.containsKey(key)) {
            return false;
        }

        final Object value = mValues.get(key);
        if (value instanceof Object[]) {
            return false;
        }

        final Object[] array = (Object[]) value;
        if (array.length <= 0) {
            return false;
        }

        return array[0].getClass() == column.getValueClass();
    }

    public void putValue(Column column, Object value) {
        if (column == null
                || value == null) {
            return;
        }

        mValues.put(column.getName(), value);
    }

    public Object getValue(Column column) {
        if (column == null) {
            return null;
        }

        return mValues.get(column.getName());
    }

    @Override
    public String toString() {
        return String.format("%s(0x%08x): %s",
                getClass().getSimpleName(),
                hashCode(),
                mValues);
    }

}

@@ -280,36 +280,56 @@
 ue(Column column
+, boolean ignoreType
 ) %7B%0A
-
         if (colu
@@ -494,32 +494,94 @@
 lse;%0A        %7D%0A%0A
+        if (ignoreType) %7B%0A            return true;%0A        %7D%0A%0A
         final Ob
@@ -670,32 +670,124 @@
 Class();%0A    %7D%0A%0A
+    public boolean hasValue(Column column) %7B%0A        return hasValue(column, false);%0A    %7D%0A%0A
     public boole
@@ -808,32 +808,52 @@
 ue(Column column
+, boolean ignoreType
 ) %7B%0A        if (
@@ -1286,59 +1286,223 @@
     
-return array%5B0%5D.getClass() == column.getValueClass(
+if (ignoreType) %7B%0A            return true;%0A        %7D%0A%0A        return array%5B0%5D.getClass() == column.getValueClass();%0A    %7D%0A%0A    public boolean hasArrayValue(Column column) %7B%0A        return hasArrayValue(column, false
 );%0A 

support only check key existence without checking the value type of DatabaseObjectKeys;