class CoreTokenFieldTypes {

    public static void validateType(CoreTokenField field, Object value) throws CoreTokenException {
        if (value == null) {
            throw new CoreTokenException(MessageFormat.format(
                    "\n" +
                            CoreTokenConstants.DEBUG_HEADER +
                            "Value field cannot be null!" +
                            "Key: {0}:{1}",
                    CoreTokenField.class.getSimpleName(),
                    field.name()));
        }

        Class<?> expectedType;
        if (isString(field)) {
            expectedType = String.class;
        } else if (isInteger(field)) {
            expectedType = Integer.class;
        } else if (isCalendar(field)) {
            expectedType = Calendar.class;
        } else if (isByteArray(field)) {
            expectedType = byte[].class;
        } else {
            throw new IllegalStateException("Unknown field: " + field.name());
        }

        if (!expectedType.isAssignableFrom(value.getClass())) {
            throw new CoreTokenException(MessageFormat.format(
                    "\n" +
                    CoreTokenConstants.DEBUG_HEADER +
                    "Value was not the correct type:\n" +
                    "           Key: {0}:{1}\n" +
                    "Required Class: {2}" +
                    "  Actual Class: {3}",
                    CoreTokenField.class.getSimpleName(),
                    field.name(),
                    expectedType.getName(),
                    value.getClass().getName()));
        }
    }

}