<commit_before>/*
 * Copyright 2003 - 2013 The eFaps Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Revision:        $Rev$
 * Last Changed:    $Date$
 * Last Changed By: $Author$
 */

package org.efaps.db;

import java.io.Serializable;
import java.util.UUID;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.efaps.admin.datamodel.Type;
import org.efaps.util.EFapsException;
import org.efaps.util.cache.CacheReloadException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * The class is used to store one object id of an instance (defined with type and id). The string representation is the
 * type id plus point plus id.
 *
 * @author The eFaps Team
 * @version $Id$
 */
public final class Instance
    implements Serializable
{
    /**
     * Logging instance used in this class.
     */
    private static final Logger LOG = LoggerFactory.getLogger(Instance.class);

    /**
     * Serial Version unique identifier.
     */
    private static final long serialVersionUID = -5587167060980613742L;

    /**
     * The instance variable stores the type definition for which this class is the instance.
     */
    private final UUID uuid;

    /**
     * The instance variable stores the database id of the instance in the database.
     *
     * @see #getId()
     */
    private final long id;

    /**
     * Key for this instance.
     */
    private final String key;

    /**
     * Is the information of GeneralId retrieved from the eFaps DataBase.
     */
    private boolean generalised;

    /**
     * The generalId of this Instance.
     */
    private long generalId = 0;

    /**
     * The ExhangeID of this Instance.
     */
    private long exchangeId = 0;

    /**
     * The ExchangeSystemID of this Instance.
     */
    private long exchangeSystemId = 0;

    /**
     * Constructor used if the type and the database id is known.
     *
     * @param _uuid uuid of the type of the instance
     * @param _id id in the database of the instance
     * @param _instanceKey key to this instance
     */
    private Instance(final UUID _uuid,
                     final long _id,
                     final String _instanceKey)
    {
        this.uuid = _uuid;
        this.id = _id;
        this.key = _instanceKey;
    }

    /**
     * @return id represented by this instance
     * @see #id
     */
    @Override
    public int hashCode()
    {
        return (int) this.id;
    }

    /**
     * @param _obj Object to compare
     * @return <i>true</i> if the given object in _obj is an instance and holds the same type and id
     * @see #id
     * @see #type
     */
    @Override
    public boolean equals(final Object _obj)
    {
        boolean ret = false;
        if (_obj instanceof Instance) {
            final Instance other = (Instance) _obj;
            if (other.uuid != null && this.uuid != null) {
                ret = (other.getId() == getId()) && (other.uuid.equals(this.uuid));
            } else {
                ret = super.equals(_obj);
            }
        }
        return ret;
    }

    /**
     * This is the getter method for the instance variable {@link #type}.
     *
     * @return value of instance variable {@link #type}
     * @see #type
     */
    public Type getType()
    {
        Type ret = null;
        try {
            ret = Type.get(this.uuid);
        } catch (final CacheReloadException e) {
            Instance.LOG.error("Could not load Type for UUID: {}", this.uuid);
        }
        return ret;
    }

    /**
     * Getter method for the instance variable {@link #uuid}.
     *
     * @return value of instance variable {@link #uuid}
     */
    public UUID getTypeUUID()
    {
        return this.uuid;
    }

    /**
     * This is the getter method for the instance variable {@link #id}.
     *
     * @return value of instance variable {@link #id}
     * @see #id
     */
    public long getId()
    {
        return this.id;
    }

    /**
     * The string representation which is defined by this instance is returned.
     *
     * @return string representation of the object id
     */
    public String getOid()
    {
        String ret = null;
        if ((getType() != null) && (getId() != 0)) {
            ret = getType().getId() + "." + getId();
        }
        return ret;
    }

    /**
     * Getter method for instance variable {@link #key}.
     *
     * @return value of instance variable {@link #key}
     */
    public String getKey()
    {<commit_msg>- kernel: adding missing validation<commit_after>/*
 * Copyright 2003 - 2013 The eFaps Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Revision:        $Rev$
 * Last Changed:    $Date$
 * Last Changed By: $Author$
 */

package org.efaps.db;

import java.io.Serializable;
import java.util.UUID;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.efaps.admin.datamodel.Type;
import org.efaps.util.EFapsException;
import org.efaps.util.cache.CacheReloadException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * The class is used to store one object id of an instance (defined with type and id). The string representation is the
 * type id plus point plus id.
 *
 * @author The eFaps Team
 * @version $Id$
 */
public final class Instance
    implements Serializable
{
    /**
     * Logging instance used in this class.
     */
    private static final Logger LOG = LoggerFactory.getLogger(Instance.class);

    /**
     * Serial Version unique identifier.
     */
    private static final long serialVersionUID = -5587167060980613742L;

    /**
     * The instance variable stores the type definition for which this class is the instance.
     */
    private final UUID uuid;

    /**
     * The instance variable stores the database id of the instance in the database.
     *
     * @see #getId()
     */
    private final long id;

    /**
     * Key for this instance.
     */
    private final String key;

    /**
     * Is the information of GeneralId retrieved from the eFaps DataBase.
     */
    private boolean generalised;

    /**
     * The generalId of this Instance.
     */
    private long generalId = 0;

    /**
     * The ExhangeID of this Instance.
     */
    private long exchangeId = 0;

    /**
     * The ExchangeSystemID of this Instance.
     */
    private long exchangeSystemId = 0;

    /**
     * Constructor used if the type and the database id is known.
     *
     * @param _uuid uuid of the type of the instance
     * @param _id id in the database of the instance
     * @param _instanceKey key to this instance
     */
    private Instance(final UUID _uuid,
                     final long _id,
                     final String _instanceKey)
    {
        this.uuid = _uuid;
        this.id = _id;
        this.key = _instanceKey;
    }

    /**
     * @return id represented by this instance
     * @see #id
     */
    @Override
    public int hashCode()
    {
        return (int) this.id;
    }

    /**
     * @param _obj Object to compare
     * @return <i>true</i> if the given object in _obj is an instance and holds the same type and id
     * @see #id
     * @see #type
     */
    @Override
    public boolean equals(final Object _obj)
    {
        boolean ret = false;
        if (_obj instanceof Instance) {
            final Instance other = (Instance) _obj;
            if (other.uuid != null && this.uuid != null) {
                ret = (other.getId() == getId()) && (other.uuid.equals(this.uuid));
            } else {
                ret = super.equals(_obj);
            }
        }
        return ret;
    }

    /**
     * This is the getter method for the instance variable {@link #type}.
     *
     * @return value of instance variable {@link #type}
     * @see #type
     */
    public Type getType()
    {
        Type ret = null;
        try {
            ret = Type.get(this.uuid);
        } catch (final CacheReloadException e) {
            Instance.LOG.error("Could not load Type for UUID: {}", this.uuid);
        }
        return ret;
    }

    /**
     * Getter method for the instance variable {@link #uuid}.
     *
     * @return value of instance variable {@link #uuid}
     */
    public UUID getTypeUUID()
    {
        return this.uuid;
    }

    /**
     * This is the getter method for the instance variable {@link #id}.
     *
     * @return value of instance variable {@link #id}
     * @see #id
     */
    public long getId()
    {
        return this.id;
    }

    /**
     * The string representation which is defined by this instance is returned.
     *
     * @return string representation of the object id
     */
    public String getOid()
    {
        String ret = null;
        if (isValid()) {
            ret = getType().getId() + "." + getId();
        }
        return ret;
    }

    /**
     * Getter method for instance variable {@link #key}.
     *
     * @return value of instance variable {@link #key}
     */
    public String getKey()
    {
{'fraction_non_alphanumeric': 0.09804313099041534, 'fraction_numerical': 0.007488019169329074, 'mean_word_length': 2.0354545454545456, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '919624', 'n_tokens_mistral': 2865, 'n_tokens_neox': 2805, 'n_words': 1045}