A Collection is a way to have a standard collection type across all languages supported by the SDK.
Constructor
Methods
concat(c:Collection<T>):Collection<T>
Returns a new Collection by appending the elements of c
to the elements of
this
Collection.
This operation does not modify this
Collection.
If c
is an empty collection, a copy of this
Collection is returned.
The length of the returned Collection is equal to the sum of this.length()
and c.length()
.
If c
is null
, the result is unspecified.
copy():Collection<T>
Returns a shallow copy of this
Collection.
The elements are not copied and retain their identity, so
c.get(i) == c.copy().get(i)
is true for any valid i
. However,
c == c.copy()
is always false.
indexOf(x:T, ?fromIndex:Int):Int
Returns position of the first occurrence of x
in this
Collection, searching front to back.
- If
x
is found by checking standard equality, the function returns its index. - If
x
is not found, the function returns -1. - If
fromIndex
is specified, it will be used as the starting index to search from, otherwise search starts with zero index. If it is negative, it will be taken as the offset from the end ofthis
Collection to compute the starting index. If given or computed starting index is less than 0, the whole collection will be searched, if it is greater than or equal to the length ofthis
Collection, the function returns -1.
insert(pos:Int, x:T):Void
Inserts the element x
at the position pos
.
This operation modifies this
Collection in place.
The offset is calculated like so:
- If pos
exceeds this.length()
, the offset is this.length()
.
- If pos
is negative, the offset is calculated from the end of this
Collection, i.e. this.length() + pos
. If this yields a negative value, the
offset is 0.
- Otherwise, the offset is pos
.
If the resulting offset does not exceed this.length()
, all elements from
and including that offset to the end of this
Collection are moved one index
ahead.
iterator():Iterator<T>
Returns an iterator of the Collection values. This can be used with for
loops when
using the SDK within Haxe, and in Java it returns a native iterator.
join(sep:String):String
Returns a string representation of this
Collection, with sep
separating
each element.
- If
this
is the empty Collection[]
, the result is the empty String""
. - If
this
has exactly one element, the result is equal to converting the element to string. - If
sep
is null, the result is unspecified.
lastIndexOf(x:T, ?fromIndex:Int):Int
Returns position of the last occurrence of x
in this
Collection, searching back to
front.
- If
x
is found by checking standard equality, the function returns its index. - If
x
is not found, the function returns -1. - If
fromIndex
is specified, it will be used as the starting index to search from, otherwise search starts with the last element index. If it is negative, it will be taken as the offset from the end ofthis
Collection to compute the starting index. If given or computed starting index is greater than or equal to the length ofthis
Collection, the whole array will be searched, if it is less than 0, the function returns -1.
pop():T
Removes the last element of this
Collection and returns it.
This operation modifies this
Collection in place.
- If
this
has at least one element,this.length()
will decrease by 1. - If
this
is the empty Collection, null is returned and the length remains 0.
push(x:T):Collection<T>
Adds the element x
at the end of this
Collection and returns the new
length of this
Collection.
This operation modifies this
Collection in place.
this.length()
increases by 1.
this
Collection is returned to allows for fluent programming (method chaining).
remove(x:T):Bool
Removes the first occurrence of x
in this
Collection.
This operation modifies this
Collection in place.
If x
is found by checking standard equality, it is removed from this
Collection and all following elements are reindexed accordingly. The function
then returns true.
If x
is not found, this
Collection is not changed and the function returns false.
reverse():Void
Reverse the order of elements of this
Collection.
This operation modifies this
Collection in place.
If this.length() < 2
, this
remains unchanged.
shift():T
Removes the first element of this
Collection and returns it.
This operation modifies this
Collection in place.
If this
has at least one element, this.length()
and the index of each
remaining element is decreased by 1.
If this
is the empty Collection, null
is returned and the length remains 0.
slice(pos:Int, ?end:Int):Collection<T>
Creates a shallow copy of the range of this
Collection, starting at and
including pos
, up to but not including end
.
This operation does not modify this
Collection.
The elements are not copied and retain their identity.
If end
is omitted or exceeds this.length()
, it defaults to the end of
this
Collection.
If pos
or end
are negative, their offsets are calculated from the
end of this
Collection by this.length() + pos
and this.length() + end
respectively. If this yields a negative value, 0 is used instead.
If pos
exceeds this.length()
or if end
is less than or equals
pos
, the result is an empty Collection.
splice(pos:Int, len:Int):Collection<T>
Removes len
elements from this
Collection, starting at and including pos
,
and returns them.
This operation modifies this
Collection in place.
If len
is < 0 or pos
exceeds this.length()
, an empty Collection is
returned and this
Collection is unchanged.
If pos
is negative, its value is calculated from the end of this
Collection by this.length() + pos
. If this yields a negative value, 0 is used instead.
If the sum of the resulting values for len
and pos
exceed
this.length()
, this operation will affect the elements from pos
to the
end of this
Collection.
The length of the returned Collection is equal to the new length of this
Collection subtracted from the original length of this
Collection. In other
words, each element of the original this
Collection either remains in
this
Collection or becomes an element of the returned Collection.
toArray():Array<T>
Returns a Haxe array with the same elements as the collection.
The array is a shallow copy of the original collection.
This can be used when using the SDK within Haxe, but it is likely useless on other target languages.
unshift(x:T):Collection<T>
Adds the element x
at the start of this
Collection.
This operation modifies this
Collection in place.
this.length()
and the index of each Collection element increases by 1.