Collections Language
An extension to the Base Language that adds support for collections.
Introduction
Collection language provides a set of abstractions that enable the use of a few most commonly used containers, as well as a set of powerful tools to construct queries. The fundamental type provided by the collections is sequence, which is an abstraction analogous to Iterable in Java, or IEnumerable in .NET . The containers include list (both array-based and linked list), set and map. The collections language also provides the means to build expressive queries using closures, in a way similar to what LINQ does.
Null handling
Collections language has a set of relaxed rules regarding null elements and null sequences.
Null sequence is still a sequence
Null is a perfectly accepted value that can be assigned to a sequence variable. This results simply in an empty sequence.
Null is returned instead of exception throwing
Whereas the standard collections framework would have to throw an exception as a result of calling a method that cannot successfully complete, the collection language's sequence and its subtypes would return null value. For example, invoking first operation on an empty sequence will yield a null value instead of throwing an exception.
Skip and stop statements
skip
Applicable within a selectMany or forEach closure. The effect of the skip statement is that the processing of the current input element stops, and the next element (if available) is immediately selected.
stop
Applicable within a selectMany closure or a sequence initializer closure. The stop statement causes the construction of the output sequence to end immediately, ignoring all the remaining elements in the input sequence (if any).
—
Collections Runtime
Collections language uses a runtime library as its back end, which is designed to be extensible. Prior to version 1.5, the collections runtime library was written in Java and used only standard Java APIs. The release 1.5 brings a change: now the runtime library is available as an MPS model and uses constructs from jetbrains.mps.baseLanguage.closures language to facilitate passing of function-type parameters around.
| Important change! In order to make the transition from Java interfaces to abstract function types possible, several of the former Java interfaces in the collections runtime library have been changed into abstract classes. While no existing code that uses collections runtime will be broken, unfortunately this breaks the so called binary compatibility, which means that a complete recompilation of all the generated code is required to avoid incompatibility with the changed classes in the runtime. |
The classes which constitute the collections runtime library can be found in the collections.runtime solution, which is available from the jetbrains.mps.baseLanguage.collections language.
Sequence
Sequence is an abstraction of the order defined on a collection of elements of some type. The only operation that is allowed on a sequence is iterating its elements from first to last. A sequence is immutable. All operations defined in the following subsections and declared to return a sequence, always return a new instance of a sequence or the original sequence.
Although it is possible to create a sequence that produces infinite number of elements, it is not recommended. Some operations may require one or two full traversals of the sequence in order to compute, and invoking such an operation on an infinite sequence would never yield result.
Sequence type
sequence<Type>
| Subtypes | Supertypes | Comparable types |
|---|---|---|
| list<Type> set<Type> |
none | java.lang.Iterable<Type> |
Creation
new sequence
| Parameter type | Result type |
|---|---|
| { => sequence<Type> } | sequence<Type> |
Sequence can be created with initializer.
closure invocation
| Result type |
|---|
| sequence<Type> |
A sequence may be returned from a closure (see Closures).
array as a sequence
| Operand type | Parameter type | Result type |
|---|---|---|
| Type[] | none | sequence<Type> |
An array can be used as a sequence.
A list, a set and a map are sequences, too. All operations defined on a sequence are also available on an instance of any of these types.
Sequence type is assignable to a variable of type java.lang.Iterable. The opposite is also true.
Operations on sequence
Iteration and querying
foreach statement
Loop statement
is equivalent to
forEach
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | { Type => void } | void |
The code passed as a parameter (as a closure literal or by reference) is executed once for each element.
size
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | none | int |
Gives number of elements in a sequence.
isEmpty
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | none | boolean |
Test whether a sequence is empty, that is its size is 0.
isNotEmpty
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | none | boolean |
Test whether a sequence contains any elements.
indexOf
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | Type | int |
Gives the index of a first occurrence in a sequence of an element that is passed to it as a parameter.
contains
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | Type | boolean |
Produces boolean value, indicating whether or not a sequence contains the specified element.
any / all
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | { Type => boolean } | boolean |
Produces boolean value that indicates whether any (in case of any operation) or all (in case of all) of the elements in the input sequence match the condition specified by the closure.
iterator
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | none | iterator<Type> |
Produces an iterator.
enumerator
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | none | enumerator<Type> |
Produces an enumerator.
Selection and filtering
first
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | none | Type |
Yields the first element.
last
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | none | Type |
Yields the last element.
take
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | int | sequence<Type> |
Produces a sequence that is sub-sequence of the original one, starting from first element and of size count.
skip
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | int | sequence<Type> |
Produces a sequence that is sub-sequence of the original one, containing all elements starting with the element at index count.
cut
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | int | sequence<Type> |
Produces a sequence that is a sub-sequence of the original one, containing all elements starting with first and up to (but not including) the element at index size minus count. In other words, this operation returns a sequence with all elements from the original one except the last count elements.
tail
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | int | sequence<Type> |
Produces a sequence that is a sub-sequence of the original one, containing all elements starting with the element at index size minus count. In other words, this operations returns a sequence with count elements from the end of the original sequence, in the original order.
page
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | int int |
sequence<Type> |
Results in a sequence that is a sub-sequence of the original one, containing all elements starting with the element at index start and up to (but not including) the element at index end.
This is equivalent to
Where skip = start, count = end - start .
where
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | { Type => boolean } | sequence<Type> |
Produces a sequence that is a sub-sequence of the original one, with all elements for which the code passed as a parameter returns true.
findFirst
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | { Type => boolean } | Type |
Results in the first element that matches the parameter closure.
findLast
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | { Type => boolean } | Type |
Results in the last element that matches the parameter closure.
Transformation and sorting
select
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | { Type => Type2 } | sequence<Type2> |
Results in a sequence consisting of elements, each of which is the result of applying the parameter function to each element of the original sequence in turn.
selectMany
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | { Type => sequence<Type2> } | sequence<Type2> |
Produces a sequence that is a concatenation of all sequences, which are all the results of applying the parameter closure to each element of the original sequence in turn. The statements skip and stop are available within the parameter closure.
distinct
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | none | sequence<Type> |
Produces a sequence, which contains all elements from the original sequence in the original order, with all the elements having cardinality exactly 1. Of all occurrences of an element in the original sequence only the first occurrence is included in the resulting sequence.
sortBy
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | { Type => Type2 } boolean |
sequence<Type> |
Produces a sequence with all elements from the original one in the order, which corresponds to an order induced by an imaginary sequence produced by applying the selector function to each element in the original sequence in turn. The selector function can be thought of as returning a key, which is used to sort elements in a sequence. The ascending parameter controls the sort order.
alsoSortBy
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | { Type => Type2 } boolean |
sequence<Type> |
Equivalent to sortBy, unless used as a chain operation immediately following sortBy or another alsoSortBy. The result is a sequence sorted with a compound key, with the first component taken from previous sortBy or alsoSortBy (which is also a compound key), and the last component taken from this operation.
sort
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | { Type, Type => int } boolean sequence<Type> |
Produces a sequence containing all elements from the original one in the order produced by applying the comparator function (passed as a closure literal or by reference) to a list with elements from the original sequence. The ascending parameter controls the sort order (order is reversed if the value is false).
Binary operations
intersect
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | sequence<Type> | sequence<Type> |
Produces a sequence containing elements contained both by the original sequence and the parameter sequence.
except
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | sequence<Type> | sequence<Type> |
Produces a sequence containing all elements from the original sequence that are not also members of the parameter sequence.
union
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | sequence<Type> | sequence<Type> |
Produces a sequence containing elements both from the original sequence and the one passed as a parameter.
disjunction
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | sequence<Type> | sequence<Type> |
Produces exclusive disjunction (symmetric difference) of the original sequence and the one passed as a parameter.
concat
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | sequence<Type> } | sequence<Type> |
Produces a sequence, which is a concatenation of the original one with the sequence passed as a parameter
Conversion
reduceLeft / reduceRight
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | { Type, Type => Type } | Type |
Operation reduceLeft/reduceRight applies the combinator function passed as a parameter to all elements of the sequence in turn. One of the function parameters is a sequence element, and another is the result of previous application of the function. Operation reduceLeft takes first two sequence elements and applies the function to them, then takes the result of the first application and the third sequence element, etc. Operation reduceRight does the same, but moving from the sequence's tail backwards.
- reduceLeft
- reduceRight
foldLeft / foldRight
| Operand type | Parameter type | Result type | Applicable for |
|---|---|---|---|
| seed sequence<Type> |
{ Z, Type => Z } | Z | foldLeft |
| seed sequence<Type> |
{ Type, Z => Z } | Z | foldRight |
Operation foldLeft/foldRight behaves similarly to reduceLeft/reduceRight, with the difference that it also accepts a seed value. Also the combinator function is asymmetric (it takes a Type and a Z parameters and returns a Z value). The result of the operation is of type Z.
- foldLeft
- foldRight
join
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence< ? extends string > | string (optional) | string |
This operation is only available on a sequence of strings. The result is a string that is produced by concatenating all elements with the optional separator. The default separator is " " (single space).
toList
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | none | list<Type> |
Returns new list containing all the elements from the original sequence.
toArray
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | none | Type*[]* |
Returns new array containing all the elements from the original sequence.
List
A basic list container backed by either array list or linked list.
List type
list<Type>
| Subtypes | Supertypes | Comparable types |
|---|---|---|
| none | sequence<Type> | java.util.List<Type> |
List creation
new arraylist
new linkedlist
| Parameter type | Result type |
|---|---|
| Type... {*}sequence<? extends *Type> |
list<Type> |
Creates an empty list. Optionally, initial values may be specified right in the new list creation expression.
Alternatively, a sequence may be specified that is used to copy elements from.
Operations on list
iterator
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | none | modifying_iterator<Type> |
This operation is redefined for list to return a modifying_iterator.
get
| Operand type | Parameter type | Result type |
|---|---|---|
| list<Type> | int | Type |
Yields the element at index position.
- indexed access
set
Operand type Parameter type Result type list<Type> int
TypeType Sets the element at index position to the specified value. Yields the new value.
- indexed access
add
Operand type Parameter type Result type list<Type> Type Type Adds an element to the list.
addFirst
Operand type Parameter type Result type list<Type> Type Type Adds an element to the list as the first element.
addLast
Operand type Parameter type Result type list<Type> Type Type Adds an element to the list as the last element.
insert
Operand type Parameter type Result type list<Type> int
TypeType Inserts an element into the list at the position index.
remove
Operand type Parameter type Result type list<Type> Type Type Removes an element from the list.
removeFirst
Operand type Parameter type Result type list<Type> none Type Removes the first element from the list.
removeLast
Operand type Parameter type Result type list<Type> none Type Removes the last element from the list.
removeAt
Operand type Parameter type Result type list<Type> int Type Removes an element from the list located at the position index.
addAll
Operand type Parameter type Result type list<Type> sequence<Type> list<Type> Adds all elements in the parameter sequence to the list.
removeAll
Operand type Parameter type Result type list<Type> sequence<Type> list<Type> Removes all elements in the parameter sequence from the list.
clear
Operand type Parameter type Result type list<Type> none void Clears all elements from the list.
reverse
| Operand type | Parameter type | Result type |
|---|---|---|
| list<Type> | none | list<Type> |
Produces a list with all elements from the original list in the reversed order.
| Important The reverse operation does not modify the original list, but rather produces another list. |
Set
A basic set container backed by either hash set or linked hash set.
Set type
set<Type>
| Subtypes | Supertypes | Comparable types |
|---|---|---|
| sorted_set<Type> | sequence<Type> | java.util.Set<Type> |
Set creation
new hashset
new linked_hashset
| Parameter type | Result type |
|---|---|
| Type... sequence<? extends Type> |
set<Type> |
Creates an empty set. Optionally, initial values may be specified right in the new set creation expression.
Alternatively, a sequence may be specified that is used to copy elements from.
Operations on set
iterator
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | none | modifying_iterator<Type> |
This operation is redefined for set to return a modifying_iterator.
add
| Operand type | Parameter type | Result type |
|---|---|---|
| set<Type> | Type | Type |
Adds an element to the set.
addAll
| Operand type | Parameter type | Result type |
|---|---|---|
| set<Type> | sequence<Type> | set<Type> |
Adds all elements in the parameter sequence to the set.
remove
| Operand type | Parameter type | Result type |
|---|---|---|
| set<Type> | Type | Type |
Removes an element from the set.
removeAll
| Operand type | Parameter type | Result type |
|---|---|---|
| set<Type> | sequence<Type> | set<Type> |
Removes all elements in the parameter sequence from the set.
clear
| Operand type | Parameter type | Result type |
|---|---|---|
| set<Type> | none | void |
Clears all elements from the set.
Sorted Set
A subtype of set that provides iteration over its elements in the natural sorting order, backed by a tree set.
Sorted Set type
set<Type>
| Subtypes | Supertypes | Comparable types |
|---|---|---|
| none | set<Type> | java.util.SortedSet<Type> |
Sorted set creation
new treeset
| Parameter type | Result type |
|---|---|
| Type... sequence<? extends Type> |
set<Type> |
Creates an empty set. Optionally, initial values may be specified right in the new set creation expression.
Alternatively, a sequence may be specified that is used to copy elements from.
Operations on sorted set
headSet
| Operand type | Parameter type | Result type |
|---|---|---|
| sorted_set<Type> | Type | sorted_set<Type> |
Results in a sorted_set that is a subset of all elements from the original set in the original sorting order, starting with the first element and up to but not including the specified element.
tailSet
| Operand type | Parameter type | Result type |
|---|---|---|
| sorted_set<Type> | Type | sorted_set<Type> |
Results in a sorted_set that is a subset of all elements from the original set in the original sorting order, starting with the specified element.
subSet
| Operand type | Parameter type | Result type |
|---|---|---|
| sorted_set<Type> | Type, Type | sorted_set<Type> |
Results in a sorted_set that is a subset of all elements from the original set in the original sorting order, starting with the first specified element and up to but not including the second specified element.
Map
A map container backed by either a hash map or a linked hash map.
Map type
map<KeyType, ValueType>
| Subtypes | Supertypes | Comparable types |
|---|---|---|
| sorted_map<KeyType, ValueType> | sequence< mapping<KeyType, ValueType> > | java.util.Map<KeyType, ValueType> |
The map type is retrofitted to be a subtype of sequence.
Map creation
new hashmap
new linked_hashmap
| Parameter type | Result type |
|---|---|
| (KeyType => ValueType)... | map<KeyType, ValueType> |
Creates an empty map. Optionally, initial values may be specified right in the new map creation expression.
Operations on map
get value by key
| Operand type | Parameter type | Result type |
|---|---|---|
| map<KeyType, ValueType> | KeyType | ValueType |
keys
| Operand type | Parameter type | Result type |
|---|---|---|
| map<KeyType, ValueType> | none | sequence<KeyType> |
Results in a sequence containing all the keys in the map.
containsKey
| Operand type | Parameter type | Result type |
|---|---|---|
| map<KeyType, ValueType> | KeyType | boolean |
Returns true if the map contains a mapping for the specified key, false otherwise.
values
| Operand type | Parameter type | Result type |
|---|---|---|
| map<KeyType, ValueType> | none | sequence<ValueType> |
Results in a sequence containing all the values in the map.
containsValue
| Operand type | Parameter type | Result type |
|---|---|---|
| map<KeyType, ValueType> | ValueType | boolean |
Returns true if the map contains a mapping with the specified value, false otherwise.
mappings
| Operand type | Parameter type | Result type |
|---|---|---|
| map<KeyType, ValueType> | none | set< mapping<KeyType, ValueType> > |
Results in a set of mappings contained by this map. The mappings can be removed from the set, but not added.
assign value to a key
| Operand type | Parameter type | Result type |
|---|---|---|
| map<KeyType, ValueType> | KeyType | ValueType |
remove
| Operand type | Parameter type | Result type |
|---|---|---|
| map<KeyType, ValueType> | KeyType | void |
Removes the specified key and the associated value from the map.
clear
| Operand type | Parameter type | Result type |
|---|---|---|
| map<KeyType, ValueType> | none | void |
Clears all key-value pairs from the map.
putAll
| Operand type | Parameter type | Result type |
|---|---|---|
| map<KeyType, ValueType> | map<KeyType, ValueType> | void |
Puts all mappings from the map specified as a parameter into this map, replacing existing mappings.
—
Sorted Map
A subtype of map that provides iteration over keys conforming to the natural sorting order, backed by a tree map.
Sorted map type
map<KeyType, ValueType>
| Subtypes | Supertypes | Comparable types |
|---|---|---|
| none | map<KeyType, ValueType> | java.util.SortedMap<KeyType, ValueType> |
Sorted map creation
new treemap
| Parameter type | Result type |
|---|---|
| (KeyType => ValueType)... | map<KeyType, ValueType> |
Creates an empty tree map. Optionally, initial values may be specified right in the new map creation expression.
Operations on sorted map
headMap
| Operand type | Parameter type | Result type |
|---|---|---|
| sorted_map<KeyType, ValueType> | KeyType | sorted_map<KeyType, ValueType> |
Results in a sorted_map that is a submap of the original map, containing all the mappings in the original sorting order, starting with the first key and up to but not including the specified key.
tailMap
| Operand type | Parameter type | Result type |
|---|---|---|
| sorted_map<KeyType, ValueType> | KeyType | sorted_map<KeyType, ValueType> |
Results in a sorted_map that is a submap of the original map, containing all the mappings in the original sorting order, starting with the specified key.
subMap
| Operand type | Parameter type | Result type |
|---|---|---|
| sorted_map<KeyType, ValueType> | KeyType, KeyType | sorted_map<KeyType, ValueType> |
Results in a sorted_map that is a submap of the original map, containing all the mappings in the original sorting order, starting with the first specified key and up to but not including the second specified key.
—
Stack
A simple stack abstraction, backed by linked list.
Stack type
stack<Type>
| Subtypes | Supertypes | Comparable types |
|---|---|---|
| deque<Type> | sequence<Type> | java.util.Deque<Type> |
Stack creation
new linkedlist
| Parameter type | Result type |
|---|---|
| Type... sequence<? extends Type> |
stack<Type> |
Creates an empty stack. Optionally, initial values may be specified right in the new linked list creation expression.
Alternatively, a sequence may be specified that is used to copy elements from.
Operations on stack
iterator
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | none | modifying_iterator<Type> |
This operation is redefined for stack to return a modifying_iterator.
addFirst / push
| Operand type | Parameter type | Result type |
|---|---|---|
| stack<Type> | Type | Type |
Appends an element to the head of the stack.
removeFirst / pop
| Operand type | Parameter type | Result type |
|---|---|---|
| stack<Type> | Type |
Removes an element from the head of the stack.
first / peek
| Operand type | Parameter type | Result type |
|---|---|---|
| stack<Type> | Type |
Retrieves the first element at the head of the stack without removing it.
—
Queue
A simple queue abstraction, backed by linked list or priority queue.
Queue type
queue<Type>
| Subtypes | Supertypes | Comparable types |
|---|---|---|
| deque<Type> | sequence<Type> | java.util.Deque<Type> |
Queue creation
new linkedlist
new priority_queue
| Parameter type | Result type |
|---|---|
| Type... sequence<? extends Type> |
queue<Type> |
Creates an empty queue. Optionally, initial values may be specified right in the new linked list creation expression.
Alternatively, a sequence may be specified that is used to copy elements from.
Operations on queue
iterator
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | none | modifying_iterator<Type> |
This operation is redefined for queue to return a modifying_iterator.
addLast
| Operand type | Parameter type | Result type |
|---|---|---|
| queue<Type> | Type | Type |
Appends an element to the tail of the queue.
removeFirst
| Operand type | Parameter type | Result type |
|---|---|---|
| queue<Type> | Type |
Removes an element from the head of the queue.
first
| Operand type | Parameter type | Result type |
|---|---|---|
| queue<Type> | Type |
Retrieves the first element at the head of the queue without removing it.
last
| Operand type | Parameter type | Result type |
|---|---|---|
| queue<Type> | Type |
Retrieves the first element at the tail of the queue without removing it.
—
Deque
A simple double-linked queue abstraction, backed by linked list.
Deque type
queue<Type>
| Subtypes | Supertypes | Comparable types |
|---|---|---|
| sequence<Type> queue<Type> stack<Type> |
java.util.Deque<Type> |
Deque creation
new linkedlist
| Parameter type | Result type |
|---|---|
| Type... sequence<? extends Type> |
deque<Type> |
Creates an empty deque. Optionally, initial values may be specified right in the new linked list creation expression.
Alternatively, a sequence may be specified that is used to copy elements from.
Operations on deque
iterator
| Operand type | Parameter type | Result type |
|---|---|---|
| sequence<Type> | none | modifying_iterator<Type> |
This operation is redefined for deque to return a modifying_iterator.
addFirst / push
| Operand type | Parameter type | Result type |
|---|---|---|
| deque<Type> | Type | Type |
Appends an element to the head of the deque.
addLast
| Operand type | Parameter type | Result type |
|---|---|---|
| deque<Type> | Type | Type |
Appends an element to the tail of the deque.
removeFirst / pop
| Operand type | Parameter type | Result type |
|---|---|---|
| deque<Type> | Type |
Removes an element from the head of the deque.
first
| Operand type | Parameter type | Result type |
|---|---|---|
| queue<Type> | Type |
Retrieves the first element at the head of the deque without removing it.
last
| Operand type | Parameter type | Result type |
|---|---|---|
| queue<Type> | Type |
Retrieves the first element at the tail of the deque without removing it.
—
Iterator
A helper type that is analogous to java.util.Iterator. An instance of the iterator can be obtained with the iterator operation on a sequence.
Iterator type
iterator<Type>
| Subtypes | Supertypes | Comparable types |
|---|---|---|
| modifying_iterator<Type> | none | java.util.Iterator<Type> |
Operations on iterator
hasNext
| Operand type | Parameter type | Result type |
|---|---|---|
| iterator<Type> | none | boolean |
Tests if there is an element available.
next
| Operand type | Parameter type | Result type |
|---|---|---|
| iterator<Type> | none | Type |
Returns the next element.
Modifying Iterator
A subtype of iterator that supports remove operation.
Modifying Iterator type
modifying_iterator<Type>
| Subtypes | Supertypes | Comparable types |
|---|---|---|
| none | iterator<Type> | java.util.Iterator<Type> |
Operations on modifying iterator
remove
| Operand type | Parameter type | Result type |
|---|---|---|
| modifying_iterator<Type> | none | none |
Removes the element this iterator is currently positioned at.
Enumerator
An alternative to the iterator, a helper type that works similar to .NET's IEnumerator. An instance of the enumerator can be obtained with the enumerator operation on a sequence.
Enumerator type
enumerator<Type>
| Subtypes | Supertypes | Comparable types |
|---|---|---|
| none | none | none |
Operations on enumerator
moveNext
| Operand type | Parameter type | Result type |
|---|---|---|
| enumerator<Type> | none | boolean |
Moves to the next element. Returns true if there is an element available.
current
| Operand type | Parameter type | Result type |
|---|---|---|
| enumerator<Type> | none | Type |
Returns the element this enumerator is currently positioned at.
Mapping
A helper type used by map and sorted_map.
Mapping type
mapping<KeyType, ValueType>
| Subtypes | Supertypes | Comparable types |
|---|---|---|
| none | none | none |
Operations on mapping
get value
| Operand type | Parameter type | Result type |
|---|---|---|
| mapping<KeyType, ValueType> | none | ValueType |
set value
| Operand type | Parameter type | Result type |
|---|---|---|
| mapping<KeyType, ValueType> | ValueType | ValueType |
get key
| Operand type | Parameter type | Result type |
|---|---|---|
| map<KeyType, ValueType> | none | KeyType |
Custom Containers
Custom containers is a simple way to provide own implementation of standard container types, thus allowing for easy extensibility of the collections language.
Example: weakHashMap
Provided the following declaration is reachable from the model currently being edited...
... one can use the weak version of hashmap thusly:
Custom Containers Declaration
A root node of concept CustomContainers may have one or more declarations.
| declaration part | allowed contents |
|---|---|
| containerName | any valid identifier |
| container_type | one of the existing container types of the collections language |
| runtime type | Java classifier which represent implementation of the container |
| factory | (optional) container creation expression; the classifier's default constructor used if undefined |
Primitive Containers
Collections framework include a set of custom containers designed to work with primitive data types. Using primitive types helps optimize speed and/or size of the containers. These containers are available with a separate language jetbrains.mps.baseLanguage.collections.trove.
Primitive list containers
list<?,?>
| byteArrayList | list<byte> |
| doubleArrayList | list<double> |
| floatArrayList | list<float> |
| intArrayList | list<int> |
| longArrayList | list<long> |
| shortArrayList | list<short> |
Primitive set containers
set<?,?>
| byteHashSet | set<byte> |
| doubleHashSet | set<double> |
| floatHashSet | set<float> |
| intHashSet | set<int> |
| longHashSet | set<long> |
| shortHashSet | set<short> |
Primitive maps
map<byte,?>
| byteByteHashMap | map<byte, byte> |
| byteDoubleHashMap | map<byte, double> |
| byteFloatHashMap | map<byte, float> |
| byteIntHashMap | map<byte, int> |
| byteLongHashMap | map<byte, long> |
| byteShortHashMap | map<byte, short> |
map<double,?>
| doubleByteHashMap | map<double, byte> |
| doubleDoubleHashMap | map<double, double> |
| doubleFloatHashMap | map<double, float> |
| doubleIntHashMap | map<double, int> |
| doubleLongHashMap | map<double, long> |
| doubleShortHashMap | map<double, short> |
map<float,?>
| floatByteHashMap | map<float, byte> |
| floatDoubleHashMap | map<float, double> |
| floatFloatHashMap | map<float, float> |
| floatIntHashMap | map<float, int> |
| floatLongHashMap | map<float, long> |
| floatShortHashMap | map<float, short> |
map<int,?>
| intByteHashMap | map<int, byte> |
| intDoubleHashMap | map<int, double> |
| intFloatHashMap | map<int, float> |
| intIntHashMap | map<int, int> |
| intLongHashMap | map<int, long> |
| intShortHashMap | map<int, short> |
map<long,?>
| longByteHashMap | map<long, byte> |
| longDoubleHashMap | map<long, double> |
| longFloatHashMap | map<long, float> |
| longIntHashMap | map<long, int> |
| longLongHashMap | map<long, long> |
| longShortHashMap | map<long, short> |
map<short,?>
| shortByteHashMap | map<short, byte> |
| shortDoubleHashMap | map<short, double> |
| shortFloatHashMap | map<short, float> |
| shortIntHashMap | map<short, int> |
| shortLongHashMap | map<short, long> |
| shortShortHashMap | map<short, short> |
<K> map<K,?>
| ObjectByteHashMap<K> | map<K, byte> |
| ObjectDoubleHashMap<K> | map<K, double> |
| ObjectFloatHashMap<K> | map<K, float> |
| ObjectIntHashMap<K> | map<K, int> |
| ObjectLongHashMap<K> | map<K, long> |
| ObjectShortHashMap<K> | map<K, short> |