<commit_before>/**
 @license
 Copyright 2020 Google Inc. All Rights Reserved.

 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.
 */

import {MDCFoundation} from '@material/base/foundation';
import {cssClasses, numbers, strings} from '@material/list/constants';

import {MDCListAdapter} from './mwc-list-adapter';

export type MWCListIndex = number|Set<number>

    interface IndexDiff {
  added: number[];
  removed: number[];
}

const findIndexDiff = (oldSet: Set<number>, newSet: Set<number>): IndexDiff => {
  const oldArr = Array.from(oldSet);
  const newArr = Array.from(newSet);
  const diff: IndexDiff = {added: [], removed: []};
  const oldSorted = oldArr.sort();
  const newSorted = newArr.sort();

  let i = 0;
  let j = 0;
  while (i < oldSorted.length || j < newSorted.length) {
    const oldVal = oldSorted[i];
    const newVal = newSorted[j];

    if (oldVal === newVal) {
      i++;
      j++;
      continue;
    }

    if (oldVal !== undefined && (newVal === undefined || oldVal < newVal)) {
      diff.removed.push(oldVal);
      i++;
      continue;
    }

    if (newVal !== undefined && (oldVal === undefined || newVal < oldVal)) {
      diff.added.push(newVal);
      j++;
      continue;
    }
  }

  return diff;
};

const ELEMENTS_KEY_ALLOWED_IN = ['input', 'button', 'textarea', 'select'];

export function isNumberSet(selectedIndex: MWCListIndex):
    selectedIndex is Set<number> {
  return selectedIndex instanceof Set;
}

export const createSetFromIndex = (index: MWCListIndex) => {
  const entry = index === numbers.UNSET_INDEX ? new Set<number>() : index;
  return isNumberSet(entry) ? new Set(entry) : new Set([entry]);
};

export class MDCListFoundation extends MDCFoundation<MDCListAdapter> {
  static get strings() {
    return strings;
  }

  static get cssClasses() {
    return cssClasses;
  }

  static get numbers() {
    return numbers;
  }

  private get isSelectableList_() {
    return this.isSelectable_ || this.isMulti_;
  }


  static get defaultAdapter(): MDCListAdapter {
    return {
      focusItemAtIndex: () => undefined,
      getFocusedElementIndex: () => 0,
      getListItemCount: () => 0,
      isFocusInsideList: () => false,
      isRootFocused: () => false,
      notifyAction: () => undefined,
      getSelectedStateForElementIndex: () => false,
      setDisabledStateForElementIndex: () => undefined,
      getDisabledStateForElementIndex: () => false,
      setSelectedStateForElementIndex: () => undefined,
      setActivatedStateForElementIndex: () => undefined,
      setTabIndexForElementIndex: () => undefined,
      setAttributeForElementIndex: () => undefined,
      getAttributeForElementIndex: () => null,
    };
  }
<commit_msg>remove cssclasses from constants import<commit_after>/**
 @license
 Copyright 2020 Google Inc. All Rights Reserved.

 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.
 */

import {MDCFoundation} from '@material/base/foundation';
import {numbers, strings} from '@material/list/constants';

import {MDCListAdapter} from './mwc-list-adapter';

export type MWCListIndex = number|Set<number>

    interface IndexDiff {
  added: number[];
  removed: number[];
}

const findIndexDiff = (oldSet: Set<number>, newSet: Set<number>): IndexDiff => {
  const oldArr = Array.from(oldSet);
  const newArr = Array.from(newSet);
  const diff: IndexDiff = {added: [], removed: []};
  const oldSorted = oldArr.sort();
  const newSorted = newArr.sort();

  let i = 0;
  let j = 0;
  while (i < oldSorted.length || j < newSorted.length) {
    const oldVal = oldSorted[i];
    const newVal = newSorted[j];

    if (oldVal === newVal) {
      i++;
      j++;
      continue;
    }

    if (oldVal !== undefined && (newVal === undefined || oldVal < newVal)) {
      diff.removed.push(oldVal);
      i++;
      continue;
    }

    if (newVal !== undefined && (oldVal === undefined || newVal < oldVal)) {
      diff.added.push(newVal);
      j++;
      continue;
    }
  }

  return diff;
};

const ELEMENTS_KEY_ALLOWED_IN = ['input', 'button', 'textarea', 'select'];

export function isNumberSet(selectedIndex: MWCListIndex):
    selectedIndex is Set<number> {
  return selectedIndex instanceof Set;
}

export const createSetFromIndex = (index: MWCListIndex) => {
  const entry = index === numbers.UNSET_INDEX ? new Set<number>() : index;
  return isNumberSet(entry) ? new Set(entry) : new Set([entry]);
};

export class MDCListFoundation extends MDCFoundation<MDCListAdapter> {
  static get strings() {
    return strings;
  }

  static get numbers() {
    return numbers;
  }

  private get isSelectableList_() {
    return this.isSelectable_ || this.isMulti_;
  }


  static get defaultAdapter(): MDCListAdapter {
    return {
      focusItemAtIndex: () => undefined,
      getFocusedElementIndex: () => 0,
      getListItemCount: () => 0,
      isFocusInsideList: () => false,
      isRootFocused: () => false,
      notifyAction: () => undefined,
      getSelectedStateForElementIndex: () => false,
      setDisabledStateForElementIndex: () => undefined,
      getDisabledStateForElementIndex: () => false,
      setSelectedStateForElementIndex: () => undefined,
      setActivatedStateForElementIndex: () => undefined,
      setTabIndexForElementIndex: () => undefined,
      setAttributeForElementIndex: () => undefined,
      getAttributeForElementIndex: () => null,
    };
  }

{'fraction_non_alphanumeric': 0.12175838077166351, 'fraction_numerical': 0.003795066413662239, 'mean_word_length': 3.6033478893740902, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 47, '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': '810287', 'n_tokens_mistral': 1868, 'n_tokens_neox': 1829, 'n_words': 546}