<commit_before>/*
 * Copyright (c) 2014 - Tyl Consulting s.a.s.
 *
 *   Authors: <NAME>
 *   Contributors: <NAME>, <NAME>
 *
 * 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 org.tylproject.vaadin.addon.datanav;

import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.Validator;
import com.vaadin.event.ListenerMethod;
import org.tylproject.vaadin.addon.datanav.events.*;
import org.tylproject.vaadin.addon.fieldbinder.behavior.Behavior;
import org.tylproject.vaadin.addon.fieldbinder.behavior.BehaviorFactory;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 * Created by evacchi on 19/11/14.
 */
final public class BasicDataNavigation extends AbstractDataNavigation implements DataNavigation {

    private @Nonnull Container.Ordered container;
    private @Nullable Class<? extends Container.Ordered> restrictedContainerType = null;

    private Object currentItemId;
    private boolean navigationEnabled = true;
    private boolean crudEnabled = true;
    private boolean findEnabled = true;
    private boolean editingMode = false;
    private boolean clearToFindMode = false;
    private BehaviorFactory behaviorFactory;



    public BasicDataNavigation() {
//        disableNavigation();
//        disableCrud();
//        disableFind();
    }

    public BasicDataNavigation(@Nonnull final Container.Ordered container) {
        setContainer(container);
    }

    public void setBehaviorFactory(BehaviorFactory behaviorFactory) {
        this.behaviorFactory = behaviorFactory;
    }

    @Override
    public Container.Ordered getContainer() {
        return container;
    }

    public void restrictContainerType(Class<? extends Container.Ordered> restrictedContainerType) {
        if (container != null) {
            // container.getClass() must be a subtype of restrictedContainerType
            container.getClass().isAssignableFrom(restrictedContainerType);
            throw new IllegalStateException(
                    "Cannot restrict container type to "+restrictedContainerType.getCanonicalName() +":"+
                            " a container of type " + container.getClass().getCanonicalName() +
                            " is currently attached"
            );
        }
        this.restrictedContainerType = restrictedContainerType;
    }

    protected void assertAssignableContainer(@Nonnull Container.Ordered container) {
        if (! (container == null ||
                restrictedContainerType == null ||
                container.getClass().isAssignableFrom(restrictedContainerType) ) ) {
            throw new AssertionError(
                    "Allowed container type is "+restrictedContainerType +", "+
                            container.getClass() + " was given"
            );<commit_msg>fix bug with restrictContainerType()<commit_after>/*
 * Copyright (c) 2014 - Tyl Consulting s.a.s.
 *
 *   Authors: <NAME>
 *   Contributors: <NAME>, <NAME>
 *
 * 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 org.tylproject.vaadin.addon.datanav;

import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.Validator;
import com.vaadin.event.ListenerMethod;
import org.tylproject.vaadin.addon.datanav.events.*;
import org.tylproject.vaadin.addon.fieldbinder.behavior.Behavior;
import org.tylproject.vaadin.addon.fieldbinder.behavior.BehaviorFactory;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 * Created by evacchi on 19/11/14.
 */
final public class BasicDataNavigation extends AbstractDataNavigation implements DataNavigation {

    private @Nonnull Container.Ordered container;
    private @Nullable Class<? extends Container.Ordered> restrictedContainerType = null;

    private Object currentItemId;
    private boolean navigationEnabled = true;
    private boolean crudEnabled = true;
    private boolean findEnabled = true;
    private boolean editingMode = false;
    private boolean clearToFindMode = false;
    private BehaviorFactory behaviorFactory;



    public BasicDataNavigation() {
//        disableNavigation();
//        disableCrud();
//        disableFind();
    }

    public BasicDataNavigation(@Nonnull final Container.Ordered container) {
        setContainer(container);
    }

    public void setBehaviorFactory(BehaviorFactory behaviorFactory) {
        this.behaviorFactory = behaviorFactory;
    }

    @Override
    public Container.Ordered getContainer() {
        return container;
    }

    public void restrictContainerType(Class<? extends Container.Ordered> restrictedContainerType) {
        if (container != null) {
            // container.getClass() must be a subtype of restrictedContainerType
            if (!container.getClass().isAssignableFrom(restrictedContainerType)) {
                throw new IllegalStateException(
                        "Cannot restrict container type to " + restrictedContainerType.getCanonicalName() + ":" +
                                " a container of type " + container.getClass()
                                .getCanonicalName() +
                                " is currently attached"
                );
            }
        }
        this.restrictedContainerType = restrictedContainerType;
    }

    protected void assertAssignableContainer(@Nonnull Container.Ordered container) {
        if (! (container == null ||
                restrictedContainerType == null ||
                container.getClass().isAssignableFrom(restrictedContainerType) ) ) {
            throw new AssertionError(
                    "Allowed container type is "+restrictedContainerType +", "+
                            container.getClass() + " was given"
            );
{'fraction_non_alphanumeric': 0.08480880821306354, 'fraction_numerical': 0.0041660467192382086, 'mean_word_length': 2.917249417249417, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3145123', 'n_tokens_mistral': 1698, 'n_tokens_neox': 1614, 'n_words': 489}