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
Abstract Yjs Type class
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcallObserver(Transaction transaction, Set<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.clone()Makes a copy of this data type that can be included somewhere else.copy()createMapIterator(Map<String, Item> map) Creates an iterator over a map, filtering out deleted items.getDoc()getFirst()getItem()getMap()getStart()Retrieves all children of a type as a list.voidIntegrate this type into the Yjs instance.static booleanisParentOf(AbstractType parent, Item child) Check if `parent` is a parent of `child`.intlength()voidObserve all events that are created on this type.voidObserve all events that are created on this type.voidObserve all events that are created by this type and its children.voidsetLength(int length) voidvoidtoJSON()Converts the type to a JSON object representation.static Iterator<?>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<Object, Integer, T> f) Executes a provided function on every element of the type.static voidtypeListForEachSnapshot(AbstractType type, TriConsumer<Object, Integer, AbstractType> f, Snapshot snapshot) Executes a provided function on every element of the type, based on the provided snapshot.static ObjecttypeListGet(AbstractType type, int index) Gets the element at the specified index in the type.static voidtypeListInsertGenerics(Transaction transaction, AbstractType parent, int index, List<?> content) Inserts generic content at a specified index in the type.static voidtypeListInsertGenericsAfter(Transaction transaction, AbstractType parent, Item referenceItem, List<?> content) Inserts generic content after a specified item in the type.static <C,R> List<R> typeListMap(AbstractType type, TriFunction<C, Number, AbstractType, R> f) Maps the elements in the type to a new list using the provided function.static voidtypeListPushGenerics(Transaction transaction, AbstractType parent, List<?> content) Pushes generic content to the end of the type.typeListSlice(AbstractType type, int start, int end) Slices the list elements within the provided range.typeListToArray(AbstractType type) Converts the list of elements in the type to an array.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, String key) Deletes a key from the type's map.static ObjecttypeMapGet(AbstractType parent, String key) Gets a value from the type's map by key.typeMapGetAll(AbstractType parent) Gets all key-value pairs from the type's map.typeMapGetAllSnapshot(AbstractType parent, Snapshot snapshot) Gets all key-value pairs from the type's map for a specific snapshot.static ObjecttypeMapGetSnapshot(AbstractType parent, String key, Snapshot snapshot) Gets a value from the type's map by key for a specific snapshot.static booleantypeMapHas(AbstractType parent, String key) Checks if the type's map contains a key.static voidtypeMapSet(Transaction transaction, AbstractType parent, String key, Object value) Sets a value in the type's map.voidUnregister an observer function.voidUnregister an observer function.voidwrite(UpdateEncoder encoder) Writes this type's state to the encoder.
-
Field Details
-
_map
-
_doc
-
_length
protected int _length -
_searchMarker
-
-
Constructor Details
-
AbstractType
public AbstractType()
-
-
Method Details
-
getItem
-
getMap
-
setMap
-
getStart
-
setStart
-
getDoc
-
length
public int length() -
setLength
public void setLength(int length) -
getDeepEventHandler
-
getSearchMarker
-
getParent
-
integrate
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
-
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. -
write
Writes this type's state to the encoder.- Parameters:
encoder- The encoder to write to
-
getFirst
- Returns:
- The first non-deleted item
-
callObserver
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
Observe all events that are created on this type.- Parameters:
f- Observer function
-
observe
Observe all events that are created on this type.- Parameters:
f- Observer function
-
observeDeep
Observe all events that are created by this type and its children.- Parameters:
f- Observer function
-
unobserve
Unregister an observer function.- Parameters:
f- Observer function
-
unobserveDeep
Unregister an observer function.- Parameters:
f- Observer function
-
toJSON
Converts the type to a JSON object representation.- Returns:
- The JSON object representation
-
getTypeChildren
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
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
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
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<Object, 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
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
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<Object, 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
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, 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, 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, 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
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, String key, 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
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
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
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
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
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
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
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`.
-