-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Showing
8 changed files
with
111 additions
and
4 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
18 changes: 18 additions & 0 deletions
18
src/commonMain/kotlin/com/github/doyaaaaaken/kotlincsv/event/skip/CsvSkipEvent.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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.github.doyaaaaaken.kotlincsv.event.skip | ||
|
||
|
||
fun interface SkipNotify { | ||
fun onSkipped(row: SkippedRow) | ||
} | ||
|
||
/** | ||
* interface function that will be triggered when skipping either insufficient or excess number of fields | ||
*/ | ||
fun interface INotifySkippedEvent { | ||
fun notify(skippedRow: SkippedRow) | ||
} | ||
|
||
|
||
fun skipNotification(block: NotifySkipEvent.() -> Unit): INotifySkippedEvent { | ||
return NotifySkipEvent().apply(block) | ||
} |
8 changes: 8 additions & 0 deletions
8
src/commonMain/kotlin/com/github/doyaaaaaken/kotlincsv/event/skip/NotifySkipEvent.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.github.doyaaaaaken.kotlincsv.event.skip | ||
|
||
class NotifySkipEvent: INotifySkippedEvent { | ||
val listeners = mutableMapOf<String, SkipNotify>() | ||
override fun notify(skippedRow: SkippedRow) { | ||
listeners.forEach { (_, value) -> value.onSkipped(skippedRow) } | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/commonMain/kotlin/com/github/doyaaaaaken/kotlincsv/event/skip/SkipType.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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.github.doyaaaaaken.kotlincsv.event.skip | ||
enum class SkipType { | ||
InsufficientFieldsRowBehaviour, | ||
ExcessFieldsRowBehaviour | ||
} |
24 changes: 24 additions & 0 deletions
24
src/commonMain/kotlin/com/github/doyaaaaaken/kotlincsv/event/skip/SkippedRow.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.github.doyaaaaaken.kotlincsv.event.skip | ||
|
||
/** | ||
* data class containing relevant information | ||
*/ | ||
data class SkippedRow( | ||
/** | ||
* row index in the csv file | ||
*/ | ||
val idx: Int, | ||
/** | ||
* row values | ||
*/ | ||
val row: List<String>, | ||
/** | ||
* reason for skipping | ||
*/ | ||
val message: String, | ||
/** | ||
* type of skip | ||
*/ | ||
val skipType: SkipType | ||
|
||
) |
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