<commit_before>/*
 * $Id$
 * $Revision$
 * $Date$
 *
 * ====================================================================
 * 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.
 */
package wicket;

/**
 * This provide a base class to work with {@link wicket.IDetachableModel}.
 * It wraps the actual model objects of components and provides a call back mechanism for
 * reacting on the starting/ ending of a request. doAttach will be called at the first
 * access to this model within a request and - if the model was attached earlier, doDetach
 * will be called at the end of the request. In effect, attachement and detachement is
 * only done when it is actually needed. As the wrapped model object is transient, either
 * attachement should be used to ensure the model onject is again available (after a
 * possible serialization), or extending classes should hold their own instance data
 * representing the model.
 */
public abstract class DetachableModel implements IDetachableModel
{
    /**
     * The wrapped model object. Note that this object is transient to ensure we never
     * serialize it even if the user forgets to set the object to null in their detach()
     * method
     */
    private transient Object object;

    /**
     * Transient flag to prevent multiple detach/attach scenario. We need to maintain this
     * flag as we allow 'null' model values!
     */
    private transient boolean attached = false;

    /**
     * Construct the detachable model with the given model object.
     * @param object the model object
     */
    public DetachableModel(final Object object)
    {
        this.object = object;<commit_msg>added a default constructor; this makes debugging annonymous classes possible, and I found it a common case to use detachable models without giving an id via the constructor.<commit_after>/*
 * $Id$
 * $Revision$
 * $Date$
 *
 * ====================================================================
 * 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.
 */
package wicket;

/**
 * This provide a base class to work with {@link wicket.IDetachableModel}.
 * It wraps the actual model objects of components and provides a call back mechanism for
 * reacting on the starting/ ending of a request. doAttach will be called at the first
 * access to this model within a request and - if the model was attached earlier, doDetach
 * will be called at the end of the request. In effect, attachement and detachement is
 * only done when it is actually needed. As the wrapped model object is transient, either
 * attachement should be used to ensure the model onject is again available (after a
 * possible serialization), or extending classes should hold their own instance data
 * representing the model.
 */
public abstract class DetachableModel implements IDetachableModel
{
    /**
     * The wrapped model object. Note that this object is transient to ensure we never
     * serialize it even if the user forgets to set the object to null in their detach()
     * method
     */
    private transient Object object;

    /**
     * Transient flag to prevent multiple detach/attach scenario. We need to maintain this
     * flag as we allow 'null' model values!
     */
    private transient boolean attached = false;

    /**
     * Construct.
     */
    public DetachableModel()
    {
    }

    /**
     * Construct the detachable model with the given model object.
     * @param object the model object
     */
    public DetachableModel(final Object object)
    {
        this.object = object;
{'fraction_non_alphanumeric': 0.0889671878440872, 'fraction_numerical': 0.0017617264919621229, 'mean_word_length': 3.4225900681596886, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7048879', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1067, 'n_words': 593}