public static <T> List<T> add(List<T> list, T element) {
        final int size = list.size();
        if (size == 0) {
            return Collections.singletonList(element);
        } else if (isUnmodifiableType(list.getClass())) {
            if (size == 1) {
                final T val = list.get(0);
                list = new ArrayList<>();
                list.add(val);
            } else {
                list = new ArrayList<>(list);
            }
        }
        list.add(element);
        return list;
    }
Return an unmodifiable copy of a set, or the same set if its already an unmodifiable type.

@param set the set
@param <T> element type
@return unmodifiable copy of a set, or the same set if its already an unmodifiable type
querydsl-core/src/main/java/com/querydsl/core/util/CollectionUtils.java