+ checkCollectionField(requiredClass, fieldName, list);
+ return (List<T>) list;
+ }
+
+ /**
+ * Utility method for checking whether the items of a target list are compatible with a particular identity class.
+ *
+ * @param requiredClass Required class
+ * @param fieldName name of the field being filled
+ * @param list List, which items should be checked
+ * @return Type-checked List
+ * @throws IllegalArgumentException if a list item is not a Class representing {@code requiredClass}
+ * @throws NullPointerException if {@code requiredClass} or {@code fieldName} is null
+ */
+ @SuppressWarnings("unchecked")
+ public static <T extends BaseIdentity> @Nullable List<Class<? extends T>> checkListFieldCastIdentity(
+ final @NonNull Class<T> requiredClass, final @NonNull String fieldName, final @Nullable List<?> list) {
+ checkCollectionFieldIdentity(requiredClass, fieldName, list);
+ return (List<Class<? extends T>>) list;
+ }
+
+ /**
+ * Utility method for checking whether the items of target set is compatible.
+ *
+ * @param requiredClass Required item class
+ * @param fieldName name of the field being filled
+ * @param set Set, which items should be checked
+ * @return Type-checked Set
+ * @throws IllegalArgumentException if a set item is not instance of {@code requiredItemClass}
+ * @throws NullPointerException if {@code requiredClass} or {@code fieldName} is null
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> @Nullable Set<T> checkSetFieldCast(final @NonNull Class<?> requiredClass,
+ final @NonNull String fieldName, final @Nullable Set<?> set) {
+ checkCollectionField(requiredClass, fieldName, set);
+ return (Set<T>) set;
+ }
+
+ /**
+ * Utility method for checking whether the items of a target set are compatible with a particular identity class.
+ *
+ * @param requiredClass Required class
+ * @param fieldName name of the field being filled
+ * @param set Set, which items should be checked
+ * @return Type-checked Set
+ * @throws IllegalArgumentException if a set item is not a Class representing {@code requiredClass}
+ * @throws NullPointerException if {@code requiredClass} or {@code fieldName} is null
+ */
+ @SuppressWarnings("unchecked")
+ public static <T extends BaseIdentity> @Nullable Set<Class<? extends T>> checkSetFieldCastIdentity(
+ final @NonNull Class<T> requiredClass, final @NonNull String fieldName, final @Nullable Set<?> set) {
+ checkCollectionFieldIdentity(requiredClass, fieldName, set);
+ return (Set<Class<? extends T>>) set;
+ }
+
+ @SuppressFBWarnings(value = "DCN_NULLPOINTER_EXCEPTION",
+ justification = "Internal NPE->IAE conversion")
+ private static void checkCollectionField(final @NonNull Class<?> requiredClass,
+ final @NonNull String fieldName, final @Nullable Collection<?> collection) {
+ if (collection != null) {