<commit_before>package fr.openwide.core.hibernate.more.business.generic.util;

import java.util.Comparator;

import fr.openwide.core.hibernate.business.generic.model.GenericEntity;
import fr.openwide.core.hibernate.more.business.generic.model.GenericListItem;

public class GenericListItemComparator<E extends GenericListItem<E>> implements Comparator<E> {

	@Override
	public int compare(E o1, E o2) {
		// on trie en priorité sur la position, puis sur le libellé et enfin par l'identifiant
		int order = 0;
		if (o1.getPosition() != null) {
			order = o1.getPosition().compareTo(o2.getPosition());
		}
		if (order == 0 && o1.getLabel() != null) {
			order = GenericEntity.DEFAULT_STRING_COLLATOR.compare(o1.getLabel(), o2.getLabel());
		}
		if (order == 0) {
			order = o1.compareTo(o2);
		}
		return order;
	}

}<commit_msg>on évite de faire un comparator générique<commit_after>package fr.openwide.core.hibernate.more.business.generic.util;

import java.util.Comparator;

import fr.openwide.core.hibernate.business.generic.model.GenericEntity;
import fr.openwide.core.hibernate.more.business.generic.model.GenericListItem;

public class GenericListItemComparator implements Comparator<GenericListItem<?>> {
	
	public static final Comparator<GenericListItem<?>> INSTANCE = new GenericListItemComparator();
	
	@Override
	public int compare(GenericListItem<?> o1, GenericListItem<?> o2) {
		if (!o1.getClass().equals(o2.getClass())) {
			throw new IllegalArgumentException("Compared objects must have the same type.");
		}
		
		// on trie en priorité sur la position, puis sur le libellé et enfin par l'identifiant
		int order = 0;
		if (o1.getPosition() != null) {
			order = o1.getPosition().compareTo(o2.getPosition());
		}
		if (order == 0 && o1.getLabel() != null) {
			order = GenericEntity.DEFAULT_STRING_COLLATOR.compare(o1.getLabel(), o2.getLabel());
		}
		if (order == 0) {
			order = o1.getId().compareTo(o2.getId());
		}
		return order;
	}

}
{'fraction_non_alphanumeric': 0.1319693094629156, 'fraction_numerical': 0.01432225063938619, 'mean_word_length': 4.6531791907514455, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6750142', 'n_tokens_mistral': 692, 'n_tokens_neox': 641, 'n_words': 142}