static { Map<Class<?>, PropertyType> map = new HashMap<Class<?>, PropertyType>(); for (PropertyType type : PropertyType.values()) { map.put(type.getRepresentation(), type); } // special rule map.put(PropertyType.DATETIME.getRepresentation(), PropertyType.DATETIME); TYPES = Collections.unmodifiableMap(map); }
/** * Returns property type kind corresponded to the property name and type. * * @param name property name * @param type property type * @return property type kind, or {@code null} without suitable correponded kind * @throws IllegalArgumentException if some parameters were {@code null} */ public static PropertyType getType(PropertyName name, Class<?> type) { if (name == null) { throw new IllegalArgumentException("name must not be null"); // $NON-NLS-1$ } if (type == null) { throw new IllegalArgumentException("type must not be null"); // $NON-NLS-1$ } PropertyType kind = TYPES.get(type); if (kind == null) { return null; } if (kind.getRepresentation() == Calendar.class) { List<String> words = name.getWords(); if (words.contains(PropertyType.DATE.name().toLowerCase())) { return PropertyType.DATE; } else if (words.contains(PropertyType.TIME.name().toLowerCase())) { return PropertyType.TIME; } else if (words.contains(PropertyType.DATETIME.name().toLowerCase())) { return PropertyType.DATETIME; } } return kind; }