Package io.keikai.doc.collab.types
Class YArray<T>
- java.lang.Object
-
- io.keikai.doc.collab.types.AbstractType<YArrayEvent>
-
- io.keikai.doc.collab.types.YArray<T>
-
- Type Parameters:
T-
public class YArray<T> extends AbstractType<YArrayEvent>
A shared Array implementation.
-
-
Field Summary
-
Fields inherited from class io.keikai.doc.collab.types.AbstractType
_doc, _length, _map, _searchMarker
-
-
Constructor Summary
Constructors Constructor Description YArray()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcallObserver(Transaction transaction, java.util.Set<java.lang.String> parentSubs)Creates YArrayEvent and calls observers.YArray<T>clone()Makes a copy of this data type that can be included somewhere else.YArray<T>copy()voiddelete(int index)Deletes elements starting from an index.voiddelete(int index, int length)Deletes elements starting from an index.voidforEach(TriConsumer<java.lang.Object,java.lang.Integer,YArray> f)Executes a provided function once on every element of this YArray.static <T> YArray<T>from(java.util.List<T> items)Construct a new YArray containing the specified items.Tget(int index)Returns the i-th element from a YArray.voidinsert(int index, java.lang.Object[] content)Inserts new content at an index.voidinsert(int index, java.util.List<T> content)Inserts new content at an index.voidintegrate(Doc y, Item item)Integrate this type into the Yjs instance.java.util.Iterator<?>iterator()Creates an iterator for this YArray.intlength()<M> java.util.List<M>map(TriFunction<T,java.lang.Number,AbstractType,M> f)Returns a List with the result of calling a provided function on every element of this YArray.voidpush(java.util.List<T> content)Appends content to this YArray.static YArray<?>readYArray(UpdateDecoder decoder)Reads a YArray from the decoder.java.util.List<?>slice(int start)Returns a portion of this YArray into a Java List selected from start to end (end not included).java.util.List<?>slice(int start, int end)Returns a portion of this YArray into a Java List selected from start to end (end not included).java.lang.Object[]toArray()Transforms this YArray to a Java array.org.zkoss.json.JSONArraytoJSON()Transforms this Shared Type to a JSON object.java.util.List<?>toList()Transforms this YArray to a Java List.voidunshift(java.util.List<T> content)Prepends 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
-
-
-
-
Method Detail
-
from
public static <T> YArray<T> from(java.util.List<T> items)
Construct a new YArray containing the specified items.- Type Parameters:
T-- Parameters:
items-- Returns:
-
integrate
public void integrate(Doc y, Item item)
Integrate this type into the Yjs instance.- Overrides:
integratein classAbstractType<YArrayEvent>- Parameters:
y- The Yjs instanceitem-
-
copy
public YArray<T> copy()
- Overrides:
copyin classAbstractType<YArrayEvent>- Returns:
-
clone
public YArray<T> 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
public void callObserver(Transaction transaction, java.util.Set<java.lang.String> parentSubs)
Creates YArrayEvent and calls observers.- Overrides:
callObserverin classAbstractType<YArrayEvent>- Parameters:
transaction-parentSubs- Keys changed on this type. `null` if list was modified.
-
insert
public void insert(int index, java.lang.Object[] content)Inserts new content at an index.- Parameters:
index- The index to insert content at.content- The array of content
-
insert
public void insert(int index, java.util.List<T> content)Inserts new content at an index.- Parameters:
index- The index to insert content at.content- The list of content
-
push
public void push(java.util.List<T> content)
Appends content to this YArray.- Parameters:
content- Array of content to append.
-
unshift
public void unshift(java.util.List<T> content)
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
public T get(int index)
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
public java.util.List<?> toList()
Transforms this YArray to a Java List.- Returns:
- A list containing all elements of this YArray.
-
toArray
public java.lang.Object[] toArray()
Transforms this YArray to a Java array.- Returns:
- An Object array containing all elements of this YArray.
-
slice
public java.util.List<?> slice(int start)
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
public java.util.List<?> slice(int start, int end)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
public <M> java.util.List<M> map(TriFunction<T,java.lang.Number,AbstractType,M> f)
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
public void forEach(TriConsumer<java.lang.Object,java.lang.Integer,YArray> f)
Executes a provided function once on every element of this YArray.- Parameters:
f- A function to execute on every element of this YArray.
-
iterator
public java.util.Iterator<?> iterator()
Creates an iterator for this YArray.- Returns:
- An iterator over the elements in this YArray.
-
write
public void write(UpdateEncoder encoder)
Writes the type reference of this YArray to the encoder.- Overrides:
writein classAbstractType<YArrayEvent>- Parameters:
encoder- The encoder to write to.
-
readYArray
public static YArray<?> readYArray(UpdateDecoder decoder)
Reads a YArray from the decoder.- Parameters:
decoder- The decoder to read from.- Returns:
- A new YArray instance.
-
-