Package io.keikai.doc.collab.types
Class AbstractType<E extends YEvent>
- java.lang.Object
-
- io.keikai.doc.collab.types.AbstractType<E>
-
- Direct Known Subclasses:
YArray,YMap,YText,YXmlFragment
public class AbstractType<E extends YEvent> extends java.lang.ObjectAbstract Yjs Type class
-
-
Field Summary
Fields Modifier and Type Field Description protected Doc_docprotected int_lengthprotected java.util.Map<java.lang.String,Item>_mapprotected java.util.List<ArraySearchMarker>_searchMarker
-
Constructor Summary
Constructors Constructor Description AbstractType()
-
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 YEvent and calls all type observers.static <T extends YEvent>
voidcallTypeObservers(AbstractType type, Transaction transaction, T event)Calls event listeners with an event and propagates to all parents.AbstractTypeclone()Makes a copy of this data type that can be included somewhere else.AbstractTypecopy()static java.util.Iterator<java.util.Map.Entry<java.lang.String,Item>>createMapIterator(java.util.Map<java.lang.String,Item> map)Creates an iterator over a map, filtering out deleted items.EventHandler<java.util.List<E>>getDeepEventHandler()DocgetDoc()ItemgetFirst()ItemgetItem()java.util.Map<java.lang.String,Item>getMap()AbstractTypegetParent()java.util.List<ArraySearchMarker>getSearchMarker()ItemgetStart()static java.util.List<Item>getTypeChildren(AbstractType t)Retrieves all children of a type as a list.voidintegrate(Doc y, Item item)Integrate this type into the Yjs instance.static booleanisParentOf(AbstractType parent, Item child)Check if `parent` is a parent of `child`.intlength()voidobserve(java.util.function.BiConsumer<E,Transaction> f)Observe all events that are created on this type.voidobserve(java.util.function.Consumer<E> f)Observe all events that are created on this type.voidobserveDeep(java.util.function.BiConsumer<java.util.List<E>,Transaction> f)Observe all events that are created by this type and its children.voidsetLength(int length)voidsetMap(java.util.Map<java.lang.String,Item> map)voidsetStart(Item start)java.lang.ObjecttoJSON()Converts the type to a JSON object representation.static java.util.Iterator<?>typeListCreateIterator(AbstractType type)Creates an iterator for the elements in the type.static voidtypeListDelete(Transaction transaction, AbstractType parent, int index, int length)Deletes content from the type at the specified index and length.static <T extends AbstractType>
voidtypeListForEach(T type, TriConsumer<java.lang.Object,java.lang.Integer,T> f)Executes a provided function on every element of the type.static voidtypeListForEachSnapshot(AbstractType type, TriConsumer<java.lang.Object,java.lang.Integer,AbstractType> f, Snapshot snapshot)Executes a provided function on every element of the type, based on the provided snapshot.static java.lang.ObjecttypeListGet(AbstractType type, int index)Gets the element at the specified index in the type.static voidtypeListInsertGenerics(Transaction transaction, AbstractType parent, int index, java.util.List<?> content)Inserts generic content at a specified index in the type.static voidtypeListInsertGenericsAfter(Transaction transaction, AbstractType parent, Item referenceItem, java.util.List<?> content)Inserts generic content after a specified item in the type.static <C,R>
java.util.List<R>typeListMap(AbstractType type, TriFunction<C,java.lang.Number,AbstractType,R> f)Maps the elements in the type to a new list using the provided function.static voidtypeListPushGenerics(Transaction transaction, AbstractType parent, java.util.List<?> content)Pushes generic content to the end of the type.static java.util.List<java.lang.Object>typeListSlice(AbstractType type, int start, int end)Slices the list elements within the provided range.static java.util.List<java.lang.Object>typeListToArray(AbstractType type)Converts the list of elements in the type to an array.static java.util.List<java.lang.Object>typeListToArraySnapshot(AbstractType type, Snapshot snapshot)Converts the list of elements in the type to an array based on the provided snapshot.static voidtypeMapDelete(Transaction transaction, AbstractType parent, java.lang.String key)Deletes a key from the type's map.static java.lang.ObjecttypeMapGet(AbstractType parent, java.lang.String key)Gets a value from the type's map by key.static java.util.Map<java.lang.String,java.lang.Object>typeMapGetAll(AbstractType parent)Gets all key-value pairs from the type's map.static java.util.Map<java.lang.String,java.lang.Object>typeMapGetAllSnapshot(AbstractType parent, Snapshot snapshot)Gets all key-value pairs from the type's map for a specific snapshot.static java.lang.ObjecttypeMapGetSnapshot(AbstractType parent, java.lang.String key, Snapshot snapshot)Gets a value from the type's map by key for a specific snapshot.static booleantypeMapHas(AbstractType parent, java.lang.String key)Checks if the type's map contains a key.static voidtypeMapSet(Transaction transaction, AbstractType parent, java.lang.String key, java.lang.Object value)Sets a value in the type's map.voidunobserve(java.util.function.BiConsumer<E,Transaction> f)Unregister an observer function.voidunobserveDeep(java.util.function.BiConsumer<java.util.List<E>,Transaction> f)Unregister an observer function.voidwrite(UpdateEncoder encoder)Writes this type's state to the encoder.
-
-
-
Field Detail
-
_map
protected java.util.Map<java.lang.String,Item> _map
-
_doc
protected Doc _doc
-
_length
protected int _length
-
_searchMarker
protected java.util.List<ArraySearchMarker> _searchMarker
-
-
Method Detail
-
getItem
public Item getItem()
-
getMap
public java.util.Map<java.lang.String,Item> getMap()
-
setMap
public void setMap(java.util.Map<java.lang.String,Item> map)
-
getStart
public Item getStart()
-
setStart
public void setStart(Item start)
-
getDoc
public Doc getDoc()
-
length
public int length()
-
setLength
public void setLength(int length)
-
getDeepEventHandler
public EventHandler<java.util.List<E>> getDeepEventHandler()
-
getSearchMarker
public java.util.List<ArraySearchMarker> getSearchMarker()
-
getParent
public AbstractType getParent()
-
integrate
public void integrate(Doc y, Item item)
Integrate this type into the Yjs instance. Save this struct in the os This type is sent to other client Observer functions are fired- Parameters:
y- The Yjs instanceitem- The item to integrate
-
copy
public AbstractType copy()
-
clone
public AbstractType clone()
Makes a copy of this data type that can be included somewhere else. Note that the content is only readable _after_ it has been included somewhere in the Ydoc.- Overrides:
clonein classjava.lang.Object- Returns:
- A copy of this data type
-
write
public void write(UpdateEncoder encoder)
Writes this type's state to the encoder.- Parameters:
encoder- The encoder to write to
-
getFirst
public Item getFirst()
- Returns:
- The first non-deleted item
-
callObserver
public void callObserver(Transaction transaction, java.util.Set<java.lang.String> parentSubs)
Creates YEvent and calls all type observers. Must be implemented by each type.- Parameters:
transaction- The current transactionparentSubs- Keys changed on this type. `null` if list was modified.
-
observe
public void observe(java.util.function.Consumer<E> f)
Observe all events that are created on this type.- Parameters:
f- Observer function
-
observe
public void observe(java.util.function.BiConsumer<E,Transaction> f)
Observe all events that are created on this type.- Parameters:
f- Observer function
-
observeDeep
public void observeDeep(java.util.function.BiConsumer<java.util.List<E>,Transaction> f)
Observe all events that are created by this type and its children.- Parameters:
f- Observer function
-
unobserve
public void unobserve(java.util.function.BiConsumer<E,Transaction> f)
Unregister an observer function.- Parameters:
f- Observer function
-
unobserveDeep
public void unobserveDeep(java.util.function.BiConsumer<java.util.List<E>,Transaction> f)
Unregister an observer function.- Parameters:
f- Observer function
-
toJSON
public java.lang.Object toJSON()
Converts the type to a JSON object representation.- Returns:
- The JSON object representation
-
getTypeChildren
public static java.util.List<Item> getTypeChildren(AbstractType t)
Retrieves all children of a type as a list.- Parameters:
t- The type to get children from.- Returns:
- The list of children.
-
callTypeObservers
public static <T extends YEvent> void callTypeObservers(AbstractType type, Transaction transaction, T event)
Calls event listeners with an event and propagates to all parents.- Parameters:
type- The type to trigger the event for.transaction- The current transaction.event- The event to propagate.
-
typeListSlice
public static java.util.List<java.lang.Object> typeListSlice(AbstractType type, int start, int end)
Slices the list elements within the provided range.- Parameters:
type- The abstract type containing the elements.start- The starting index.end- The ending index.- Returns:
- The list of sliced elements.
-
typeListToArray
public static java.util.List<java.lang.Object> typeListToArray(AbstractType type)
Converts the list of elements in the type to an array.- Parameters:
type- The abstract type containing the elements.- Returns:
- The list of elements as an array.
-
typeListToArraySnapshot
public static java.util.List<java.lang.Object> typeListToArraySnapshot(AbstractType type, Snapshot snapshot)
Converts the list of elements in the type to an array based on the provided snapshot.- Parameters:
type- The abstract type containing the elements.snapshot- The snapshot of the document state.- Returns:
- The list of elements as an array.
-
typeListForEach
public static <T extends AbstractType> void typeListForEach(T type, TriConsumer<java.lang.Object,java.lang.Integer,T> f)
Executes a provided function on every element of the type.- Parameters:
type- The abstract type containing the elements.f- The function to execute on each element.
-
typeListMap
public static <C,R> java.util.List<R> typeListMap(AbstractType type, TriFunction<C,java.lang.Number,AbstractType,R> f)
Maps the elements in the type to a new list using the provided function.- Parameters:
type- The abstract type containing the elements.f- The function to apply to each element.- Returns:
- The list of mapped elements.
-
typeListCreateIterator
public static java.util.Iterator<?> typeListCreateIterator(AbstractType type)
Creates an iterator for the elements in the type.- Parameters:
type- The abstract type containing the elements.- Returns:
- An iterator for the elements.
-
typeListForEachSnapshot
public static void typeListForEachSnapshot(AbstractType type, TriConsumer<java.lang.Object,java.lang.Integer,AbstractType> f, Snapshot snapshot)
Executes a provided function on every element of the type, based on the provided snapshot.- Parameters:
type- The abstract type containing the elements.f- The function to execute on each element.snapshot- The snapshot of the document state.
-
typeListGet
public static java.lang.Object typeListGet(AbstractType type, int index)
Gets the element at the specified index in the type.- Parameters:
type- The abstract type containing the elements.index- The index of the element.- Returns:
- The element at the specified index.
-
typeListInsertGenericsAfter
public static void typeListInsertGenericsAfter(Transaction transaction, AbstractType parent, Item referenceItem, java.util.List<?> content)
Inserts generic content after a specified item in the type.- Parameters:
transaction- The current transaction.parent- The parent abstract type.referenceItem- The item after which to insert the content.content- The content to insert.
-
typeListInsertGenerics
public static void typeListInsertGenerics(Transaction transaction, AbstractType parent, int index, java.util.List<?> content)
Inserts generic content at a specified index in the type.- Parameters:
transaction- The current transaction.parent- The parent abstract type.index- The index at which to insert the content.content- The content to insert.
-
typeListPushGenerics
public static void typeListPushGenerics(Transaction transaction, AbstractType parent, java.util.List<?> content)
Pushes generic content to the end of the type.- Parameters:
transaction- The current transaction.parent- The parent abstract type.content- The content to push.
-
typeListDelete
public static void typeListDelete(Transaction transaction, AbstractType parent, int index, int length)
Deletes content from the type at the specified index and length.- Parameters:
transaction- The current transaction.parent- The parent abstract type.index- The starting index of the deletion.length- The length of the content to delete.
-
typeMapDelete
public static void typeMapDelete(Transaction transaction, AbstractType parent, java.lang.String key)
Deletes a key from the type's map.- Parameters:
transaction- The current transaction.parent- The parent abstract type.key- The key to delete.
-
typeMapSet
public static void typeMapSet(Transaction transaction, AbstractType parent, java.lang.String key, java.lang.Object value)
Sets a value in the type's map.- Parameters:
transaction- The current transaction.parent- The parent abstract type.key- The key to set.value- The value to set.
-
typeMapGet
public static java.lang.Object typeMapGet(AbstractType parent, java.lang.String key)
Gets a value from the type's map by key.- Parameters:
parent- The parent abstract type.key- The key to get.- Returns:
- The value associated with the key.
-
typeMapGetAll
public static java.util.Map<java.lang.String,java.lang.Object> typeMapGetAll(AbstractType parent)
Gets all key-value pairs from the type's map.- Parameters:
parent- The parent abstract type.- Returns:
- The map of all key-value pairs.
-
typeMapHas
public static boolean typeMapHas(AbstractType parent, java.lang.String key)
Checks if the type's map contains a key.- Parameters:
parent- The parent abstract type.key- The key to check.- Returns:
- True if the key exists, false otherwise.
-
typeMapGetSnapshot
public static java.lang.Object typeMapGetSnapshot(AbstractType parent, java.lang.String key, Snapshot snapshot)
Gets a value from the type's map by key for a specific snapshot.- Parameters:
parent- The parent abstract type.key- The key to get.snapshot- The snapshot of the document state.- Returns:
- The value associated with the key in the snapshot.
-
typeMapGetAllSnapshot
public static java.util.Map<java.lang.String,java.lang.Object> typeMapGetAllSnapshot(AbstractType parent, Snapshot snapshot)
Gets all key-value pairs from the type's map for a specific snapshot.- Parameters:
parent- The parent abstract type.snapshot- The snapshot of the document state.- Returns:
- The map of all key-value pairs in the snapshot.
-
createMapIterator
public static java.util.Iterator<java.util.Map.Entry<java.lang.String,Item>> createMapIterator(java.util.Map<java.lang.String,Item> map)
Creates an iterator over a map, filtering out deleted items.- Parameters:
map- The map to iterate over.- Returns:
- An iterator over the map entries.
-
isParentOf
public static boolean isParentOf(AbstractType parent, Item child)
Check if `parent` is a parent of `child`.- Parameters:
parent- The parent AbstractType.child- The child Item or null.- Returns:
- Whether `parent` is a parent of `child`.
-
-