Skip to content
This repository was archived by the owner on May 26, 2026. It is now read-only.

Commit f5e0f50

Browse files
authored
Consequently use the term "jtx object" (#404)
* Rename `JtxItemAndExceptions` to `JtxObjectAndExceptions` * Rename `JtxItemBuilder` to `JtxObjectBuilder` * Rename `JtxItemHandler` to `JtxObjectHandler` * Remove "item" from `JtxEntityBuilder` kdoc * Remove "item" from `JtxFieldHandler` kdoc * Remove "item" from `RecurrenceFieldsBuilder`
1 parent fc9a899 commit f5e0f50

8 files changed

Lines changed: 66 additions & 76 deletions

File tree

lib/src/main/kotlin/at/bitfire/synctools/mapping/jtx/JtxItemBuilder.kt renamed to lib/src/main/kotlin/at/bitfire/synctools/mapping/jtx/JtxObjectBuilder.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import at.bitfire.synctools.mapping.jtx.builder.RecurrenceFieldsBuilder
1616
import at.bitfire.synctools.mapping.jtx.builder.RemindersBuilder
1717
import at.bitfire.synctools.mapping.jtx.builder.SyncPropertiesBuilder
1818
import at.bitfire.synctools.mapping.jtx.builder.TimeFieldsBuilder
19-
import at.bitfire.synctools.storage.jtx.JtxItemAndExceptions
19+
import at.bitfire.synctools.storage.jtx.JtxObjectAndExceptions
2020
import net.fortuna.ical4j.model.component.CalendarComponent
2121
import net.fortuna.ical4j.model.component.VJournal
2222
import net.fortuna.ical4j.model.component.VToDo
2323

2424
/**
2525
* Mapper from an [AssociatedComponents] data object to jtx Board content provider data rows.
2626
*/
27-
class JtxItemBuilder(
27+
class JtxObjectBuilder(
2828
collectionId: Long,
2929
fileName: String?,
3030
eTag: String?,
@@ -42,11 +42,11 @@ class JtxItemBuilder(
4242
RemindersBuilder()
4343
)
4444

45-
fun build(component: AssociatedComponents<CalendarComponent>): JtxItemAndExceptions {
45+
fun build(component: AssociatedComponents<CalendarComponent>): JtxObjectAndExceptions {
4646
requireJtxComponents(component)
4747

48-
val main = component.main ?: error("Main item required")
49-
return JtxItemAndExceptions(
48+
val main = component.main ?: error("Main component required")
49+
return JtxObjectAndExceptions(
5050
main = buildComponent(from = main, main = main),
5151
exceptions = component.exceptions.map { exception ->
5252
buildComponent(from = exception, main = main)

lib/src/main/kotlin/at/bitfire/synctools/mapping/jtx/JtxItemHandler.kt renamed to lib/src/main/kotlin/at/bitfire/synctools/mapping/jtx/JtxObjectHandler.kt

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import android.content.Entity
1010
import at.bitfire.synctools.icalendar.AssociatedComponents
1111
import at.bitfire.synctools.mapping.jtx.handler.DescriptionHandler
1212
import at.bitfire.synctools.mapping.jtx.handler.JtxFieldHandler
13-
import at.bitfire.synctools.storage.jtx.JtxItemAndExceptions
13+
import at.bitfire.synctools.storage.jtx.JtxObjectAndExceptions
1414
import at.techbee.jtx.JtxContract
1515
import net.fortuna.ical4j.model.Property
1616
import net.fortuna.ical4j.model.component.CalendarComponent
@@ -20,56 +20,54 @@ import net.fortuna.ical4j.model.property.ProdId
2020
import net.fortuna.ical4j.model.property.RRule
2121
import java.util.UUID
2222

23-
typealias AssociatedItems = AssociatedComponents<CalendarComponent>
24-
2523
/**
26-
* Mapper from jtx Board item main + data rows to [VJournal] or [VToDo].
24+
* Mapper from jtx Board object main + data rows to [VJournal] or [VToDo].
2725
*
2826
* @param prodId the `PRODID` to use
2927
*/
30-
class JtxItemHandler(
28+
class JtxObjectHandler(
3129
private val prodId: ProdId
3230
) {
3331
private val fieldHandlers: Array<JtxFieldHandler> = arrayOf(
3432
DescriptionHandler()
3533
)
3634

3735
/**
38-
* Maps a jtx Board item with its exceptions to [VJournal] or [VToDo].
36+
* Maps a jtx Board object with its exceptions to [VJournal] or [VToDo].
3937
*
4038
* VJOURNAL and VTODO must have a valid `UID`. So this method generates an UID, if necessary.
4139
* If an `UID` was generated, it is noted in the result.
4240
*/
43-
fun mapToCalendarComponents(itemAndExceptions: JtxItemAndExceptions): MappingResult {
44-
// make sure that main item has a UID
41+
fun mapToCalendarComponents(jtxObjectAndExceptions: JtxObjectAndExceptions): MappingResult {
42+
// make sure that main jtx object has a UID
4543
var generatedUid = false
46-
val mainValues = itemAndExceptions.main.entityValues
44+
val mainValues = jtxObjectAndExceptions.main.entityValues
4745
val uid = mainValues.getAsString(JtxContract.JtxICalObject.UID) ?: run {
4846
generatedUid = true
4947
UUID.randomUUID().toString()
5048
}
5149

52-
// map main item
53-
val main = mapItem(
54-
entity = itemAndExceptions.main,
55-
main = itemAndExceptions.main
50+
// map main jtx object
51+
val main = mapJtxObject(
52+
entity = jtxObjectAndExceptions.main,
53+
main = jtxObjectAndExceptions.main
5654
)
5755

5856
val rRules = main.getProperties<RRule<*>>(Property.RRULE)
5957
val exceptions: List<CalendarComponent> = if (rRules.isNotEmpty()) {
60-
// add exceptions to recurring main item
61-
itemAndExceptions.exceptions.map { exception ->
62-
mapItem(
58+
// add exceptions to recurring main jtx object
59+
jtxObjectAndExceptions.exceptions.map { exception ->
60+
mapJtxObject(
6361
entity = exception,
64-
main = itemAndExceptions.main
62+
main = jtxObjectAndExceptions.main
6563
)
6664
}
6765
} else {
6866
emptyList()
6967
}
7068

7169
return MappingResult(
72-
associatedItems = AssociatedItems(
70+
associatedComponents = AssociatedComponents(
7371
main = main,
7472
exceptions = exceptions,
7573
prodId = prodId
@@ -80,31 +78,31 @@ class JtxItemHandler(
8078
}
8179

8280
/**
83-
* Maps data of an item from the jtx Board content provider to [VJournal] or [VToDo].
81+
* Maps data of a jtx object from the content provider to [VJournal] or [VToDo].
8482
*
85-
* @param entity item row as returned by the jtx Board content provider
86-
* @param main main item row as returned by the jtx Board content provider
83+
* @param entity jtx object row as returned by the jtx Board content provider
84+
* @param main main jtx object row as returned by the jtx Board content provider
8785
*
8886
* @return generated data object
8987
*/
90-
private fun mapItem(entity: Entity, main: Entity): CalendarComponent {
88+
private fun mapJtxObject(entity: Entity, main: Entity): CalendarComponent {
9189
val entityComponent = entity.getComponent()
9290
val mainComponent = main.getComponent()
9391

9492
require(entityComponent == mainComponent) {
9593
"'main' and 'entity' need to be of same jtx Board component type"
9694
}
9795

98-
val item = when (entityComponent) {
96+
val calendarComponent = when (entityComponent) {
9997
JtxContract.JtxICalObject.Component.VJOURNAL -> VJournal()
10098
JtxContract.JtxICalObject.Component.VTODO -> VToDo()
10199
}
102100

103101
for (handler in fieldHandlers) {
104-
handler.process(from = entity, main = main, to = item)
102+
handler.process(from = entity, main = main, to = calendarComponent)
105103
}
106104

107-
return item
105+
return calendarComponent
108106
}
109107

110108
private fun Entity.getComponent(): JtxContract.JtxICalObject.Component {
@@ -115,13 +113,13 @@ class JtxItemHandler(
115113
/**
116114
* Result of the [mapToCalendarComponents] operation.
117115
*
118-
* @param associatedItems mapped items
119-
* @param uid UID of the mapped items
116+
* @param associatedComponents mapped jtx objects
117+
* @param uid UID of the mapped jtx objects
120118
* @param generatedUid whether [uid] was generated by [mapToCalendarComponents]
121119
* (*false*: `UID` was already present before mapping)
122120
*/
123121
class MappingResult(
124-
val associatedItems: AssociatedItems,
122+
val associatedComponents: AssociatedComponents<CalendarComponent>,
125123
val uid: String,
126124
val generatedUid: Boolean
127125
)

lib/src/main/kotlin/at/bitfire/synctools/mapping/jtx/builder/JtxEntityBuilder.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ import net.fortuna.ical4j.model.component.VToDo
1515
interface JtxEntityBuilder {
1616

1717
/**
18-
* Maps a specific part of the given item ([VToDo] or [VJournal]) into the provided [Entity].
18+
* Maps a specific part of the given component ([VToDo] or [VJournal]) into the provided [Entity].
1919
*
20-
* If [from] references the same object as [main], this method is called for a main item (not an
21-
* exception). If [from] references another object as [main], this method is called for an
22-
* exception (not a main item).
20+
* If [from] references the same object as [main], this method is called for a main component
21+
* (not an exception). If [from] references another object as [main], this method is called for
22+
* an exception (not a main component).
2323
*
24-
* Note: The result of the mapping is used to either create or update the item row in the
24+
* Note: The result of the mapping is used to either create or update the jtx object row in the
2525
* jtx Board content provider.
2626
* For updates, explicit `null` values are required for fields that should be `null` (otherwise
27-
* the value wouldn't be updated to `null` in case of an item update). Sub-rows of the [Entity]
28-
* will always be created anew, so there's no need to use `null` values in sub-rows.
27+
* the value wouldn't be updated to `null` in case of a jtx object update). Sub-rows of the
28+
* [Entity] will always be created anew, so there's no need to use `null` values in sub-rows.
2929
*
30-
* @param from item to map (will always be [VToDo] or [VJournal])
31-
* @param main main item (will always be [VToDo] or [VJournal])
30+
* @param from component to map (will always be [VToDo] or [VJournal])
31+
* @param main main component (will always be [VToDo] or [VJournal])
3232
* @param to destination object where built values are stored (set `null` values, see note)
3333
*
3434
* @throws InvalidICalendarException on missing or invalid required properties

lib/src/main/kotlin/at/bitfire/synctools/mapping/jtx/builder/RecurrenceFieldsBuilder.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ class RecurrenceFieldsBuilder : JtxEntityBuilder {
2222

2323
override fun build(from: CalendarComponent, main: CalendarComponent, to: Entity) {
2424
if (from === main) {
25-
buildMainItem(main, to)
25+
buildMain(main, to)
2626
} else {
27-
buildExceptionItem(from, to)
27+
buildException(from, to)
2828
}
2929
}
3030

31-
private fun buildMainItem(main: CalendarComponent, to: Entity) {
31+
private fun buildMain(main: CalendarComponent, to: Entity) {
3232
to.entityValues.putNull(JtxContract.JtxICalObject.RECURID)
3333
to.entityValues.putNull(JtxContract.JtxICalObject.RECURID_TIMEZONE)
3434

@@ -83,7 +83,7 @@ class RecurrenceFieldsBuilder : JtxEntityBuilder {
8383
}
8484
}
8585

86-
private fun buildExceptionItem(exception: CalendarComponent, to: Entity) {
86+
private fun buildException(exception: CalendarComponent, to: Entity) {
8787
buildRecurrenceId(exception, to)
8888

8989
to.entityValues.putNull(JtxContract.JtxICalObject.RRULE)

lib/src/main/kotlin/at/bitfire/synctools/mapping/jtx/handler/JtxFieldHandler.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import net.fortuna.ical4j.model.component.CalendarComponent
1313
interface JtxFieldHandler {
1414

1515
/**
16-
* Takes specific data from a jtx Board item (= item row plus data rows, taken from the jtx
16+
* Takes specific data from a jtx object (= jtx object row plus data rows, taken from the jtx
1717
* Board content provider) and maps it into the given [CalendarComponent].
1818
*
19-
* If [from] references the same object as [main], this method is called for a main item (not an
20-
* exception). If [from] references another object as [main], this method is called for an
21-
* exception (not a main item).
19+
* If [from] references the same object as [main], this method is called for a main jtx object
20+
* (not an exception). If [from] references another object as [main], this method is called for
21+
* an exception (not a main jtx object).
2222
*
23-
* @param from item from content provider
24-
* @param main main item from content provider
23+
* @param from jtx object from content provider
24+
* @param main main jtx object from content provider
2525
* @param to destination object where the mapped data are stored (no explicit `null` values
2626
* needed for fields that are not present)
2727
*

lib/src/main/kotlin/at/bitfire/synctools/storage/jtx/JtxItemAndExceptions.kt renamed to lib/src/main/kotlin/at/bitfire/synctools/storage/jtx/JtxObjectAndExceptions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ package at.bitfire.synctools.storage.jtx
88

99
import at.bitfire.synctools.storage.MainItemAndExceptions
1010

11-
typealias JtxItemAndExceptions = MainItemAndExceptions
11+
typealias JtxObjectAndExceptions = MainItemAndExceptions

lib/src/test/kotlin/at/bitfire/synctools/mapping/jtx/JtxItemBuilderTest.kt renamed to lib/src/test/kotlin/at/bitfire/synctools/mapping/jtx/JtxObjectBuilderTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import org.robolectric.RobolectricTestRunner
2323
import java.time.Instant
2424

2525
@RunWith(RobolectricTestRunner::class)
26-
class JtxItemBuilderTest {
26+
class JtxObjectBuilderTest {
2727

28-
private val builder = JtxItemBuilder(
28+
private val builder = JtxObjectBuilder(
2929
collectionId = 1,
3030
fileName = null,
3131
eTag = null,

lib/src/test/kotlin/at/bitfire/synctools/mapping/jtx/JtxItemHandlerTest.kt renamed to lib/src/test/kotlin/at/bitfire/synctools/mapping/jtx/JtxObjectHandlerTest.kt

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package at.bitfire.synctools.mapping.jtx
88

99
import android.content.Entity
1010
import androidx.core.content.contentValuesOf
11-
import at.bitfire.synctools.storage.jtx.JtxItemAndExceptions
11+
import at.bitfire.synctools.storage.jtx.JtxObjectAndExceptions
1212
import at.techbee.jtx.JtxContract
1313
import net.fortuna.ical4j.model.component.VJournal
1414
import net.fortuna.ical4j.model.component.VToDo
@@ -22,15 +22,15 @@ import org.junit.runner.RunWith
2222
import org.robolectric.RobolectricTestRunner
2323

2424
@RunWith(RobolectricTestRunner::class)
25-
class JtxItemHandlerTest {
25+
class JtxObjectHandlerTest {
2626

27-
private val handler = JtxItemHandler(
27+
private val handler = JtxObjectHandler(
2828
prodId = ProdId(javaClass.simpleName)
2929
)
3030

3131
@Test
3232
fun `mapToCalendarComponents maps VTODO component`() {
33-
val itemAndExceptions = JtxItemAndExceptions(
33+
val jtxObjectAndExceptions = JtxObjectAndExceptions(
3434
main = Entity(
3535
contentValuesOf(
3636
JtxContract.JtxICalObject.COMPONENT to "VTODO",
@@ -40,16 +40,14 @@ class JtxItemHandlerTest {
4040
exceptions = emptyList()
4141
)
4242

43-
val result = handler.mapToCalendarComponents(
44-
itemAndExceptions = itemAndExceptions
45-
)
43+
val result = handler.mapToCalendarComponents(jtxObjectAndExceptions)
4644

47-
assertEquals(VToDo::class.java, result.associatedItems.main?.javaClass)
45+
assertEquals(VToDo::class.java, result.associatedComponents.main?.javaClass)
4846
}
4947

5048
@Test
5149
fun `mapToCalendarComponents maps VJOURNAL component`() {
52-
val itemAndExceptions = JtxItemAndExceptions(
50+
val jtxObjectAndExceptions = JtxObjectAndExceptions(
5351
main = Entity(
5452
contentValuesOf(
5553
JtxContract.JtxICalObject.COMPONENT to "VJOURNAL",
@@ -59,16 +57,14 @@ class JtxItemHandlerTest {
5957
exceptions = emptyList()
6058
)
6159

62-
val result = handler.mapToCalendarComponents(
63-
itemAndExceptions = itemAndExceptions
64-
)
60+
val result = handler.mapToCalendarComponents(jtxObjectAndExceptions)
6561

66-
assertEquals(VJournal::class.java, result.associatedItems.main?.javaClass)
62+
assertEquals(VJournal::class.java, result.associatedComponents.main?.javaClass)
6763
}
6864

6965
@Test
7066
fun `mapToCalendarComponents returns UID`() {
71-
val itemAndExceptions = JtxItemAndExceptions(
67+
val jtxObjectAndExceptions = JtxObjectAndExceptions(
7268
main = Entity(
7369
contentValuesOf(
7470
JtxContract.JtxICalObject.COMPONENT to "VTODO",
@@ -78,17 +74,15 @@ class JtxItemHandlerTest {
7874
exceptions = emptyList()
7975
)
8076

81-
val result = handler.mapToCalendarComponents(
82-
itemAndExceptions = itemAndExceptions
83-
)
77+
val result = handler.mapToCalendarComponents(jtxObjectAndExceptions)
8478

8579
assertFalse(result.generatedUid)
8680
assertEquals("uid", result.uid)
8781
}
8882

8983
@Test
9084
fun `mapToCalendarComponents creates UID`() {
91-
val itemAndExceptions = JtxItemAndExceptions(
85+
val jtxObjectAndExceptions = JtxObjectAndExceptions(
9286
main = Entity(
9387
contentValuesOf(
9488
JtxContract.JtxICalObject.COMPONENT to "VTODO"
@@ -98,9 +92,7 @@ class JtxItemHandlerTest {
9892
exceptions = emptyList()
9993
)
10094

101-
val result = handler.mapToCalendarComponents(
102-
itemAndExceptions = itemAndExceptions
103-
)
95+
val result = handler.mapToCalendarComponents(jtxObjectAndExceptions)
10496

10597
assertTrue(result.generatedUid)
10698
assertNotNull(result.uid)

0 commit comments

Comments
 (0)