class ValueObjectUtils {

    public static List<? extends SchemaElement> sortResourceGroupElement(List<? extends SchemaElement> list) {
        if(list == null || list.isEmpty()) {
            return list;
        }
        Comparator<SchemaElement> comparator = new Comparator<SchemaElement>() {
            public int compare(SchemaElement elem1, SchemaElement elem2) {
                if (elem1 != null && elem2 != null)
                    return ObjectUtils.compare(elem1.getName(), elem2.getName());
                else if (elem1 == null) return  1;
                else if(elem2 == null) return -1;
                else return 0;
            }
        };
        Collections.sort(list, comparator);

        if (list.get(0) instanceof AbstractResourceGroupElement || list.get(0) instanceof ConstantsResourceGroupElement) {
            for (SchemaElement element : list) {
                if (element instanceof AbstractResourceGroupElement) {
                    sortResourceGroupElement(((AbstractResourceGroupElement) element).getElements());
                } else if (element instanceof ConstantsResourceGroupElement) {
                    sortResourceGroupElement(((ConstantsResourceGroupElement) element).getElements());
                }
            }
        }
        return list;
    }

}