<commit_before>package fr.openwide.core.wicket.markup.html.model;

import org.apache.wicket.Component;
import org.apache.wicket.model.ComponentModel;
import org.apache.wicket.model.IModel;

/**
 * Give translation for a given enum. Reosurce key is built as in EnumLabel.
 * 
 * This model needs to be wrapped by component to be used.
 */
public class EnumLabelModel<E extends Enum<?>> extends ComponentModel<String> {

	private static final long serialVersionUID = -7290192562513833670L;

	private IModel<E> enumValueModel;

	private IModel<String> nullKeyModel;

	public EnumLabelModel(IModel<E> enumValueModel) {
		this(enumValueModel, null);
	}

	public EnumLabelModel(IModel<E> enumValueModel, IModel<String> nullKeyModel) {
		super();
		this.enumValueModel = enumValueModel;
		this.nullKeyModel = nullKeyModel;
	}
	
	protected String getObject(Component component) {
		if (enumValueModel != null && enumValueModel.getObject() != null) {
			return component.getString(enumValueModel.getObject().getClass().getSimpleName() + "." + enumValueModel.getObject().name());
		} else if (nullKeyModel != null && nullKeyModel.getObject() != null) {
			return component.getString(nullKeyModel.getObject());
		} else {
			return "";
		}
	}

}
<commit_msg>Il peut s'avérer parfois utile de travail directement avec l'enum ; ajout de constructeur pour ce cas<commit_after>package fr.openwide.core.wicket.markup.html.model;

import org.apache.wicket.Component;
import org.apache.wicket.model.ComponentModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

/**
 * Give translation for a given enum. Reosurce key is built as in EnumLabel.
 * 
 * This model needs to be wrapped by component to be used.
 */
public class EnumLabelModel<E extends Enum<?>> extends ComponentModel<String> {

	private static final long serialVersionUID = -7290192562513833670L;

	private IModel<E> enumValueModel;

	private IModel<String> nullKeyModel;

	public EnumLabelModel(E enumValue) {
		this(Model.of(enumValue), null);
	}

	public EnumLabelModel(E enumValue, String nullKeyValue) {
		this(Model.of(enumValue), Model.of(nullKeyValue));
	}

	public EnumLabelModel(IModel<E> enumValueModel) {
		this(enumValueModel, null);
	}

	public EnumLabelModel(IModel<E> enumValueModel, IModel<String> nullKeyModel) {
		super();
		this.enumValueModel = enumValueModel;
		this.nullKeyModel = nullKeyModel;
	}
	
	protected String getObject(Component component) {
		if (enumValueModel != null && enumValueModel.getObject() != null) {
			return component.getString(enumValueModel.getObject().getClass().getSimpleName() + "." + enumValueModel.getObject().name());
		} else if (nullKeyModel != null && nullKeyModel.getObject() != null) {
			return component.getString(nullKeyModel.getObject());
		} else {
			return "";
		}
	}

}

{'fraction_non_alphanumeric': 0.11660149306789903, 'fraction_numerical': 0.0135087095627444, 'mean_word_length': 5.090909090909091, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '426212', 'n_tokens_mistral': 937, 'n_tokens_neox': 866, 'n_words': 205}