-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da1786a
commit 03b182a
Showing
15 changed files
with
267 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,44 @@ | ||
package dev.silenium.libs.flows.api | ||
|
||
data class FlowItem<T, P>(val pad: UInt, val metadata: P, val value: T) : ReferenceCounted<FlowItem<T, P>> { | ||
/** | ||
* Wraps the actual data of a flow item and contains its metadata and pad id. | ||
* | ||
* @param T The type of the data. | ||
* @param P The type of the metadata. | ||
* @property pad The pad id of the flow item. | ||
* @property metadata The metadata of the flow item. | ||
* @property value The actual data of the flow item. | ||
* @see Reference | ||
* @see AutoCloseable | ||
*/ | ||
data class FlowItem<T, P>(val pad: UInt, val metadata: P, val value: T) : Reference<FlowItem<T, P>> { | ||
/** | ||
* Clones the flow item. | ||
* If value and/or metadata are [Reference], they are cloned as well. | ||
*/ | ||
@Suppress("UNCHECKED_CAST") | ||
override fun clone(): Result<FlowItem<T, P>> { | ||
return when (value) { | ||
is ReferenceCounted<*> -> value.clone().map { FlowItem(pad, metadata, it as T) } | ||
else -> Result.success(this) | ||
val clonedValue = when (value) { | ||
is Reference<*> -> value.clone() as T | ||
else -> value | ||
} | ||
val clonedMetadata = when (metadata) { | ||
is Reference<*> -> metadata.clone() as P | ||
else -> metadata | ||
} | ||
return Result.success(FlowItem(pad, clonedMetadata, clonedValue)) | ||
} | ||
|
||
/** | ||
* Closes the flow item. | ||
* If value and/or metadata are [AutoCloseable], they are closed as well. | ||
*/ | ||
override fun close() { | ||
if (value is AutoCloseable) { | ||
(value as AutoCloseable).close() | ||
} | ||
if (metadata is AutoCloseable) { | ||
(metadata as AutoCloseable).close() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package dev.silenium.libs.flows.api | ||
|
||
/** | ||
* A reference to a resource. | ||
* The resource is closed when the reference count reaches zero and it implements [AutoCloseable]. | ||
* | ||
* @param T The type of the underlying resource. | ||
* @see AutoCloseable | ||
*/ | ||
interface Reference<T : Reference<T>> : AutoCloseable { | ||
/** | ||
* Creates a new reference to the underlying resource. | ||
*/ | ||
fun clone(): Result<T> | ||
|
||
/** | ||
* Destroys the reference to the underlying resource. | ||
* If the reference count reaches zero, the resource is closed. | ||
*/ | ||
override fun close() | ||
} |
5 changes: 0 additions & 5 deletions
5
src/main/kotlin/dev/silenium/libs/flows/api/ReferenceCounted.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/dev/silenium/libs/flows/api/Transformer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
package dev.silenium.libs.flows.api | ||
|
||
/** | ||
* A [Transformer] is a flow element that transforms flow items. | ||
* It is simply both a [Sink] and a [Source]. | ||
* | ||
* @param IT The type of the input data. | ||
* @param IP The type of the input metadata. | ||
* @param OT The type of the output data. | ||
* @param OP The type of the output metadata. | ||
* @see Sink | ||
* @see Source | ||
*/ | ||
interface Transformer<IT, IP, OT, OP> : Sink<IT, IP>, Source<OT, OP> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.