提交 094d4bb3 编写于 作者: J João Moreno

cleanup INavigator

上级 c9609bd2
......@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { INavigator, ArrayNavigator } from 'vs/base/common/iterator';
import { INavigator, ArrayNavigator } from 'vs/base/common/navigator';
export class HistoryNavigator<T> implements INavigator<T> {
......@@ -45,10 +45,6 @@ export class HistoryNavigator<T> implements INavigator<T> {
return this._navigator.current();
}
public parent(): null {
return null;
}
public first(): T | null {
return this._navigator.first();
}
......
......@@ -75,102 +75,3 @@ export namespace Iterable {
return [consumed, { [Symbol.iterator]() { return iterator; } }];
}
}
export interface INextIterator<T> {
next(): T | null;
}
export class ArrayIterator<T> implements INextIterator<T> {
private readonly items: readonly T[];
protected start: number;
protected end: number;
protected index: number;
constructor(items: readonly T[], start: number = 0, end: number = items.length, index = start - 1) {
this.items = items;
this.start = start;
this.end = end;
this.index = index;
}
public first(): T | null {
this.index = this.start;
return this.current();
}
public next(): T | null {
this.index = Math.min(this.index + 1, this.end);
return this.current();
}
protected current(): T | null {
if (this.index === this.start - 1 || this.index === this.end) {
return null;
}
return this.items[this.index];
}
}
export class ArrayNavigator<T> extends ArrayIterator<T> implements INavigator<T> {
constructor(items: readonly T[], start: number = 0, end: number = items.length, index = start - 1) {
super(items, start, end, index);
}
public current(): T | null {
return super.current();
}
public previous(): T | null {
this.index = Math.max(this.index - 1, this.start - 1);
return this.current();
}
public first(): T | null {
this.index = this.start;
return this.current();
}
public last(): T | null {
this.index = this.end - 1;
return this.current();
}
public parent(): T | null {
return null;
}
}
export class MappedIterator<T, R> implements INextIterator<R> {
constructor(protected iterator: INextIterator<T>, protected fn: (item: T | null) => R) {
// noop
}
next() { return this.fn(this.iterator.next()); }
}
export interface INavigator<T> extends INextIterator<T> {
current(): T | null;
previous(): T | null;
parent(): T | null;
first(): T | null;
last(): T | null;
next(): T | null;
}
export class MappedNavigator<T, R> extends MappedIterator<T, R> implements INavigator<R> {
constructor(protected navigator: INavigator<T>, fn: (item: T | null) => R) {
super(navigator, fn);
}
current() { return this.fn(this.navigator.current()); }
previous() { return this.fn(this.navigator.previous()); }
parent() { return this.fn(this.navigator.parent()); }
first() { return this.fn(this.navigator.first()); }
last() { return this.fn(this.navigator.last()); }
next() { return this.fn(this.navigator.next()); }
}
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export interface INavigator<T> {
current(): T | null;
previous(): T | null;
first(): T | null;
last(): T | null;
next(): T | null;
}
export class ArrayNavigator<T> implements INavigator<T> {
constructor(
private readonly items: readonly T[],
protected start: number = 0,
protected end: number = items.length,
protected index = start - 1
) { }
current(): T | null {
if (this.index === this.start - 1 || this.index === this.end) {
return null;
}
return this.items[this.index];
}
next(): T | null {
this.index = Math.min(this.index + 1, this.end);
return this.current();
}
previous(): T | null {
this.index = Math.max(this.index - 1, this.start - 1);
return this.current();
}
first(): T | null {
this.index = this.start;
return this.current();
}
last(): T | null {
this.index = this.end - 1;
return this.current();
}
}
......@@ -12,7 +12,7 @@ import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cance
import { IStringDictionary } from 'vs/base/common/collections';
import { getErrorMessage, isPromiseCanceledError, onUnexpectedError } from 'vs/base/common/errors';
import { Emitter, Event } from 'vs/base/common/event';
import { ArrayNavigator } from 'vs/base/common/iterator';
import { ArrayNavigator } from 'vs/base/common/navigator';
import { Disposable, dispose, IDisposable } from 'vs/base/common/lifecycle';
import * as strings from 'vs/base/common/strings';
import { URI } from 'vs/base/common/uri';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册