/** * @return the {@code FieldType} associated to the provided binding, or {@link FieldType#UNKNOWN} * if no {@code FieldType} relates to the argument attribute type. */ public static FieldType forBinding(@Nullable Class<?> binding) { if (binding == null || Void.class.equals(binding)) { return NULL; } // try a hash lookup first FieldType fieldType = BINDING_MAPPING.get(binding); if (fieldType != null) { return fieldType; } // not in the map, lets check one by one anyways // beware for this to work properly FieldTypes for super classes must be defined _after_ // any subclass (i.e. Point before Geometry) for (FieldType t : values()) { if (t.getBinding() != null && t.getBinding().isAssignableFrom(binding)) { return t; } } return UNKNOWN; }
static { for (FieldType t : FieldType.values()) { BINDING_MAPPING.put(t.getBinding(), t); } }