<commit_before>package jpaoletti.jpm2.core.model;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import jpaoletti.jpm2.core.JPMContext;
import jpaoletti.jpm2.core.PMException;
import jpaoletti.jpm2.core.converter.Converter;
import jpaoletti.jpm2.core.exception.IgnoreConvertionException;
import jpaoletti.jpm2.core.exception.NotAuthorizedException;
import jpaoletti.jpm2.util.JPMUtils;

/**
 * Contains fields and fields values. It depends on operation.
 *
 * @author jpaoletti
 */
public class EntityInstance {

    private IdentifiedObject iobject;
    private EntityInstanceOwner owner;
    private List<Operation> operations; //Individual operations
    private List<Field> fields;
    private Map<String, Object> values;
    private String highlight;

    /**
     * Used for lists.
     *
     * @param iobject
     * @param fields
     * @param ctx
     * @throws jpaoletti.jpm2.core.PMException
     */
    public EntityInstance(IdentifiedObject iobject, List<Field> fields, JPMContext ctx) throws PMException {
        this.iobject = iobject;
        this.values = new LinkedHashMap<>();
        this.fields = fields;
        this.highlight = "";
        configureItemOperations(ctx.getEntity(), ctx.getEntityContext(), ctx.getOperation());
    }

    /**
     * Used for single instance operations.
     *
     * @param ctx
     * @throws jpaoletti.jpm2.core.PMException
     */
    public EntityInstance(JPMContext ctx) throws PMException {
        this(null, ctx);
    }

    /**
     * Used for single instance operations.
     *
     * @param iobject
     * @param ctx
     * @throws jpaoletti.jpm2.core.PMException
     */
    public EntityInstance(IdentifiedObject iobject, JPMContext ctx) throws PMException {
        this(ctx.getContextualEntity(), iobject, ctx);
    }

    /**
     * Used for single instance operations.
     *
     * @param contextualEntity
     *
     * @param entity
     * @param iobject
     * @param ctx
     * @throws jpaoletti.jpm2.core.PMException
     */
    public EntityInstance(ContextualEntity contextualEntity, IdentifiedObject iobject, JPMContext ctx) throws PMException {
        this.iobject = iobject;
        final Object object = (iobject != null) ? iobject.getObject() : null;
        final String id = (iobject != null) ? iobject.getId() : null;
        values = new LinkedHashMap<>();
        fields = new ArrayList<>();
        operations = new ArrayList<>();
        final Entity entity = contextualEntity.getEntity();
        for (Field field : entity.getOrderedFields()) {
            final Converter converter = field.getConverter(ctx.getOperation());
            if (converter != null) {
                try {
                    values.put(field.getId(), converter.visualize(
                            contextualEntity, field, object, id));
                    fields.add(field);
                } catch (IgnoreConvertionException ex) {<commit_msg>Added owner configuration in list<commit_after>package jpaoletti.jpm2.core.model;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import jpaoletti.jpm2.core.JPMContext;
import jpaoletti.jpm2.core.PMException;
import jpaoletti.jpm2.core.converter.Converter;
import jpaoletti.jpm2.core.exception.IgnoreConvertionException;
import jpaoletti.jpm2.core.exception.NotAuthorizedException;
import jpaoletti.jpm2.util.JPMUtils;

/**
 * Contains fields and fields values. It depends on operation.
 *
 * @author jpaoletti
 */
public class EntityInstance {

    private IdentifiedObject iobject;
    private EntityInstanceOwner owner;
    private List<Operation> operations; //Individual operations
    private List<Field> fields;
    private Map<String, Object> values;
    private String highlight;

    /**
     * Used for lists.
     *
     * @param iobject
     * @param fields
     * @param ctx
     * @throws jpaoletti.jpm2.core.PMException
     */
    public EntityInstance(IdentifiedObject iobject, List<Field> fields, JPMContext ctx) throws PMException {
        this.iobject = iobject;
        this.values = new LinkedHashMap<>();
        this.fields = fields;
        this.highlight = "";
        final Object object = (iobject != null) ? iobject.getObject() : null;
        final Entity entity = ctx.getEntity();
        if (object != null) {
            if (entity.isWeak(ctx.getEntityContext())) {
                final Object ownerobject = JPMUtils.get(object, entity.getOwner(ctx.getEntityContext()).getLocalProperty());
                configureOwner(entity, ctx.getEntityContext(), ownerobject);
            }
            configureItemOperations(entity, ctx.getEntityContext(), ctx.getOperation());
        }
        configureItemOperations(entity, ctx.getEntityContext(), ctx.getOperation());
    }

    /**
     * Used for single instance operations.
     *
     * @param ctx
     * @throws jpaoletti.jpm2.core.PMException
     */
    public EntityInstance(JPMContext ctx) throws PMException {
        this(null, ctx);
    }

    /**
     * Used for single instance operations.
     *
     * @param iobject
     * @param ctx
     * @throws jpaoletti.jpm2.core.PMException
     */
    public EntityInstance(IdentifiedObject iobject, JPMContext ctx) throws PMException {
        this(ctx.getContextualEntity(), iobject, ctx);
    }

    /**
     * Used for single instance operations.
     *
     * @param contextualEntity
     *
     * @param entity
     * @param iobject
     * @param ctx
     * @throws jpaoletti.jpm2.core.PMException
     */
    public EntityInstance(ContextualEntity contextualEntity, IdentifiedObject iobject, JPMContext ctx) throws PMException {
        this.iobject = iobject;
        final Object object = (iobject != null) ? iobject.getObject() : null;
        final String id = (iobject != null) ? iobject.getId() : null;
        values = new LinkedHashMap<>();
        fields = new ArrayList<>();
        operations = new ArrayList<>();
        final Entity entity = contextualEntity.getEntity();
        for (Field field : entity.getOrderedFields()) {
            if (field.shouldDisplay(ctx.getOperation().getId())) {
                final Converter converter = field.getConverter(ctx.getOperation());
                if (converter != null) {
                    try {
                        values.put(field.getId(), converter.visualize(
                                contextualEntity, field, object, id));
                        fields.add(field);
                    } catch (IgnoreConvertionException ex) {
                    }
{'fraction_non_alphanumeric': 0.10319261612952035, 'fraction_numerical': 0.0033287940686942048, 'mean_word_length': 2.600217864923747, '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': '4335684', 'n_tokens_mistral': 1840, 'n_tokens_neox': 1836, 'n_words': 433}