Package io.keikai.doc.collab.types
Class YArray<T>
- Type Parameters:
T-
A shared Array implementation.
-
Field Summary
Fields inherited from class io.keikai.doc.collab.types.AbstractType
_doc, _length, _map, _searchMarker -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcallObserver(Transaction transaction, Set<String> parentSubs) Creates YArrayEvent and calls observers.clone()Makes a copy of this data type that can be included somewhere else.copy()voiddelete(int index) Deletes elements starting from an index.voiddelete(int index, int length) Deletes elements starting from an index.voidExecutes a provided function once on every element of this YArray.static <T> YArray<T>Construct a new YArray containing the specified items.get(int index) Returns the i-th element from a YArray.voidInserts new content at an index.voidInserts new content at an index.voidIntegrate this type into the Yjs instance.Iterator<?>iterator()Creates an iterator for this YArray.intlength()<M> List<M>map(TriFunction<T, Number, AbstractType, M> f) Returns a List with the result of calling a provided function on every element of this YArray.voidAppends content to this YArray.static YArray<?>readYArray(UpdateDecoder decoder) Reads a YArray from the decoder.List<?>slice(int start) Returns a portion of this YArray into a Java List selected from start to end (end not included).List<?>slice(int start, int end) Returns a portion of this YArray into a Java List selected from start to end (end not included).Object[]toArray()Transforms this YArray to a Java array.org.zkoss.json.JSONArraytoJSON()Transforms this Shared Type to a JSON object.List<?>toList()Transforms this YArray to a Java List.voidPrepends content to this YArray.voidwrite(UpdateEncoder encoder) Writes the type reference of this YArray to the encoder.Methods inherited from class io.keikai.doc.collab.types.AbstractType
callTypeObservers, createMapIterator, getDeepEventHandler, getDoc, getFirst, getItem, getMap, getParent, getSearchMarker, getStart, getTypeChildren, isParentOf, observe, observe, observeDeep, setLength, setMap, setStart, typeListCreateIterator, typeListDelete, typeListForEach, typeListForEachSnapshot, typeListGet, typeListInsertGenerics, typeListInsertGenericsAfter, typeListMap, typeListPushGenerics, typeListSlice, typeListToArray, typeListToArraySnapshot, typeMapDelete, typeMapGet, typeMapGetAll, typeMapGetAllSnapshot, typeMapGetSnapshot, typeMapHas, typeMapSet, unobserve, unobserveDeep
-
Constructor Details
-
YArray
public YArray()
-
-
Method Details
-
from
Construct a new YArray containing the specified items.- Type Parameters:
T-- Parameters:
items-- Returns:
-
integrate
Integrate this type into the Yjs instance.- Overrides:
integratein classAbstractType<YArrayEvent>- Parameters:
y- The Yjs instanceitem-
-
copy
- Overrides:
copyin classAbstractType<YArrayEvent>- Returns:
-
clone
Makes a copy of this data type that can be included somewhere else.- Overrides:
clonein classAbstractType<YArrayEvent>- Returns:
-
length
public int length()- Overrides:
lengthin classAbstractType<YArrayEvent>
-
callObserver
Creates YArrayEvent and calls observers.- Overrides:
callObserverin classAbstractType<YArrayEvent>- Parameters:
transaction-parentSubs- Keys changed on this type. `null` if list was modified.
-
insert
Inserts new content at an index.- Parameters:
index- The index to insert content at.content- The array of content
-
insert
Inserts new content at an index.- Parameters:
index- The index to insert content at.content- The list of content
-
push
Appends content to this YArray.- Parameters:
content- Array of content to append.
-
unshift
Prepends content to this YArray.- Parameters:
content- Array of content to prepend.
-
delete
public void delete(int index) Deletes elements starting from an index.- Parameters:
index- Index at which to start deleting elements.
-
delete
public void delete(int index, int length) Deletes elements starting from an index.- Parameters:
index- Index at which to start deleting elements.length- The number of elements to remove. Defaults to 1.
-
get
Returns the i-th element from a YArray.- Parameters:
index- The index of the element to return from the YArray.- Returns:
- The element at the specified index.
-
toList
Transforms this YArray to a Java List.- Returns:
- A list containing all elements of this YArray.
-
toArray
Transforms this YArray to a Java array.- Returns:
- An Object array containing all elements of this YArray.
-
slice
Returns a portion of this YArray into a Java List selected from start to end (end not included).- Parameters:
start-- Returns:
- A list containing elements from the specified range.
-
slice
Returns a portion of this YArray into a Java List selected from start to end (end not included).- Parameters:
start-end-- Returns:
- A list containing elements from the specified range.
-
toJSON
public org.zkoss.json.JSONArray toJSON()Transforms this Shared Type to a JSON object.- Overrides:
toJSONin classAbstractType<YArrayEvent>- Returns:
- A list representing the JSON object.
-
map
Returns a List with the result of calling a provided function on every element of this YArray.- Type Parameters:
M- The type of the elements in the resulting list.- Parameters:
f- The function that produces an element of the new List.- Returns:
- A list with each element being the result of the callback function.
-
forEach
Executes a provided function once on every element of this YArray.- Parameters:
f- A function to execute on every element of this YArray.
-
iterator
Creates an iterator for this YArray.- Returns:
- An iterator over the elements in this YArray.
-
write
Writes the type reference of this YArray to the encoder.- Overrides:
writein classAbstractType<YArrayEvent>- Parameters:
encoder- The encoder to write to.
-
readYArray
Reads a YArray from the decoder.- Parameters:
decoder- The decoder to read from.- Returns:
- A new YArray instance.
-