<commit_before>/*
 * Copyright 2016 - 2017 <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 de.mrapp.android.tabswitcher.model;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;

import de.mrapp.android.tabswitcher.R;
import de.mrapp.android.tabswitcher.Tab;
import de.mrapp.android.tabswitcher.TabSwitcher;
import de.mrapp.android.tabswitcher.view.TabViewHolder;
import de.mrapp.android.util.view.AttachedViewRecycler;

import static de.mrapp.android.util.Condition.ensureAtLeast;
import static de.mrapp.android.util.Condition.ensureNotNull;

/**
 * An item, which contains information about a tab of a {@link TabSwitcher}.
 *
 * @author <NAME>
 * @since 1.0.0
 */
public class TabItem {

    /**
     * A comparator, which allows to compare two instances of the class {@link TabItem}.
     */
    public static class Comparator implements java.util.Comparator<TabItem> {

        /**
         * The tab switcher, the tab items, which are compared by the comparator, belong to.
         */
        private final TabSwitcher tabSwitcher;

        /**
         * Creates a new comparator, which allows to compare two instances of the class {@link
         * TabItem}.
         *
         * @param tabSwitcher
         *         The tab switcher, the tab items, which should be compared by the comparator,
         *         belong to, as a instance of the class {@link TabSwitcher}. The tab switcher may
         *         not be null
         */
        public Comparator(@NonNull final TabSwitcher tabSwitcher) {
            ensureNotNull(tabSwitcher, "The tab switcher may not be null");
            this.tabSwitcher = tabSwitcher;
        }

        @Override
        public int compare(final TabItem o1, final TabItem o2) {
            Tab tab1 = o1.getTab();
            Tab tab2 = o2.getTab();
            int index1 = tabSwitcher.indexOf(tab1);
            int index2 = tabSwitcher.indexOf(tab2);

            if (index1 == -1) {
                throw new RuntimeException("Tab not contained by tab switcher");
            } else if (index2 == -1) {
                return -1;
            }

            return index1 <= index2 ? -1 : 1;
        }

    }

    /**
     * The index of the tab.
     */
    private final int index;

    /**
     * The tab.<commit_msg>Revised comparator to compare two TabItems.<commit_after>/*
 * Copyright 2016 - 2017 <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 de.mrapp.android.tabswitcher.model;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;

import de.mrapp.android.tabswitcher.R;
import de.mrapp.android.tabswitcher.Tab;
import de.mrapp.android.tabswitcher.TabSwitcher;
import de.mrapp.android.tabswitcher.view.TabViewHolder;
import de.mrapp.android.util.view.AttachedViewRecycler;

import static de.mrapp.android.util.Condition.ensureAtLeast;
import static de.mrapp.android.util.Condition.ensureNotNull;

/**
 * An item, which contains information about a tab of a {@link TabSwitcher}.
 *
 * @author <NAME>
 * @since 1.0.0
 */
public class TabItem {

    /**
     * A comparator, which allows to compare two instances of the class {@link TabItem}.
     */
    public static class Comparator implements java.util.Comparator<TabItem> {

        /**
         * The tab switcher, the tab items, which are compared by the comparator, belong to.
         */
        private final TabSwitcher tabSwitcher;

        /**
         * Creates a new comparator, which allows to compare two instances of the class {@link
         * TabItem}.
         *
         * @param tabSwitcher
         *         The tab switcher, the tab items, which should be compared by the comparator,
         *         belong to, as a instance of the class {@link TabSwitcher}. The tab switcher may
         *         not be null
         */
        public Comparator(@NonNull final TabSwitcher tabSwitcher) {
            ensureNotNull(tabSwitcher, "The tab switcher may not be null");
            this.tabSwitcher = tabSwitcher;
        }

        @Override
        public int compare(final TabItem o1, final TabItem o2) {
            Tab tab1 = o1.getTab();
            Tab tab2 = o2.getTab();
            int index1 = tabSwitcher.indexOf(tab1);
            int index2 = tabSwitcher.indexOf(tab2);

            if (index2 == -1) {
                index2 = o2.getIndex();
            }

            if (index1 == -1 || index2 == -1) {
                throw new RuntimeException("Tab not contained by tab switcher");
            }

            return index1 < index2 ? -1 : 1;
        }

    }

    /**
     * The index of the tab.
     */
    private final int index;

    /**
     * The tab.
{'fraction_non_alphanumeric': 0.0896814404432133, 'fraction_numerical': 0.01229224376731302, 'mean_word_length': 2.400235432607416, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '1116824', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1606, 'n_words': 563}