<commit_before>package com.oneandone.typedrest.vaadin;

import static com.oneandone.typedrest.BeanUtils.*;
import com.oneandone.typedrest.*;
import com.vaadin.data.Validator;
import com.vaadin.data.fieldgroup.*;
import com.vaadin.data.util.*;
import com.vaadin.data.validator.*;
import com.vaadin.ui.*;
import java.lang.annotation.Annotation;

/**
 * Common base class for entity component implementations.
 *
 * @param <TEntity> The type of entity the component operates on.
 */
public abstract class AbstractEntityForm<TEntity>
        extends CustomComponent implements EntityForm<TEntity> {

    protected final Class<TEntity> entityType;
    protected final BeanFieldGroup<TEntity> fieldGroup;

    /**
     * Creates a new entity editor.
     *
     * @param entityType The type of entity the component operates on.
     */
    protected AbstractEntityForm(Class<TEntity> entityType) {
        this.entityType = entityType;
        this.fieldGroup = new BeanFieldGroup<>(entityType);
    }

    @Override
    public TEntity getEntity() {
        try {
            fieldGroup.commit();
        } catch (FieldGroup.CommitException ex) {
            // replace exception for nicer message
            throw new Validator.InvalidValueException("Invalid input!");
        }
        return fieldGroup.getItemDataSource().getBean();
    }

    @Override
    public void setEntity(TEntity entity) {
        fieldGroup.setItemDataSource(new BeanItem<>(entity, entityType));
        applyAnnotations(Required.class, new NullValidator("Must be set!", false));
        applyAnnotations(NotEmpty.class, new StringLengthValidator("Must not be empty!", 1, -1, false));
    }

    private void applyAnnotations(Class<? extends Annotation> annotationType, Validator validator) {
        getPropertiesWithAnnotation(entityType, annotationType)
                .forEach(property -> {
                    Field<?> field = fieldGroup.getField(property.getName());
                    if (field != null) {<commit_msg>typedrest-vaadin: Fixed Width of AbstractEntityForm<commit_after>package com.oneandone.typedrest.vaadin;

import static com.oneandone.typedrest.BeanUtils.*;
import com.oneandone.typedrest.*;
import com.vaadin.data.Validator;
import com.vaadin.data.fieldgroup.*;
import com.vaadin.data.util.*;
import com.vaadin.data.validator.*;
import com.vaadin.ui.*;
import java.lang.annotation.Annotation;

/**
 * Common base class for entity component implementations.
 *
 * @param <TEntity> The type of entity the component operates on.
 */
public abstract class AbstractEntityForm<TEntity>
        extends CustomComponent implements EntityForm<TEntity> {

    protected final Class<TEntity> entityType;
    protected final BeanFieldGroup<TEntity> fieldGroup;

    /**
     * Creates a new entity editor.
     *
     * @param entityType The type of entity the component operates on.
     */
    protected AbstractEntityForm(Class<TEntity> entityType) {
        this.entityType = entityType;
        this.fieldGroup = new BeanFieldGroup<>(entityType);
        setSizeFull();
        setWidth(100, Unit.PERCENTAGE);
    }

    @Override
    public TEntity getEntity() {
        try {
            fieldGroup.commit();
        } catch (FieldGroup.CommitException ex) {
            // replace exception for nicer message
            throw new Validator.InvalidValueException("Invalid input!");
        }
        return fieldGroup.getItemDataSource().getBean();
    }

    @Override
    public void setEntity(TEntity entity) {
        fieldGroup.setItemDataSource(new BeanItem<>(entity, entityType));
        applyAnnotations(Required.class, new NullValidator("Must be set!", false));
        applyAnnotations(NotEmpty.class, new StringLengthValidator("Must not be empty!", 1, -1, false));
    }

    private void applyAnnotations(Class<? extends Annotation> annotationType, Validator validator) {
        getPropertiesWithAnnotation(entityType, annotationType)
                .forEach(property -> {
                    Field<?> field = fieldGroup.getField(property.getName());
                    if (field != null) {
{'fraction_non_alphanumeric': 0.1009017791859615, 'fraction_numerical': 0.0017060687301974165, 'mean_word_length': 3.1707317073170733, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, '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': '3144894', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1080, 'n_words': 277}