/
ImmutableCollection.ts
67 lines (58 loc) · 2.31 KB
/
ImmutableCollection.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* @license
* Copyright Larry Diamond 2018 All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/larrydiamond/typescriptcollectionsframework/blob/master/LICENSE
*/
import {Consumer} from "./Consumer";
import {JIterator} from "./JIterator";
/**
* The root interface in the collection hierarchy. A collection represents a group of objects, known as its elements.
*
* Some collections allow duplicate elements and others do not. Some are ordered and others unordered.
*
* This framework does not provide any direct implementations of this interface: it provides implementations of more specific subinterfaces like Set and List.
*
* This interface is typically used to pass collections around and query them where maximum generality is desired.
*
* Methods that modify collections are not defined in this class, they are instead defined in Collection or some subinterface.
*
* Some collection implementations have restrictions on the elements that they may contain. For example, some implementations prohibit null and / or undefined elements.
*
* This interface is the immutable version of java.lang.Collection.
*/
export interface ImmutableCollection<T> {
/**
* Returns the number of elements in this collection.
* @return {number} the number of elements in this collection
*/
size () : number;
/**
* Returns true if this collection contains no elements.
* @return {boolean} true if this collection contains no elements
*/
isEmpty () : boolean;
/**
* Returns a Java style iterator
* @return {JIterator<T>} the Java style iterator
*/
iterator():JIterator<T>;
/**
* Returns a TypeScript style iterator
* @return {Iterator<T>} the TypeScript style iterator
*/
[Symbol.iterator] ():Iterator<T>;
/**
* Returns true if this collection contains the specified element.
* @param {T} t element whose presence in this collection is to be tested
* @return {boolean} true if this collection contains the specified element
*/
contains (t:T) : boolean;
/**
* Performs the given action for each element until all elements have been processed or the action throws and exception.
*
* Exceptions thrown by the action are relayed to the caller
*/
forEach (action: Consumer<T>) : void;
}