Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package ch.opentransportdata.ojp.data.dto.response.tir

import android.os.Parcelable
import ch.opentransportdata.ojp.data.dto.response.PlacesDto
import ch.opentransportdata.ojp.data.dto.response.tir.leg.AbstractLegType
import ch.opentransportdata.ojp.data.dto.response.tir.leg.ContinuousLegDto
import ch.opentransportdata.ojp.data.dto.response.tir.leg.TimedLegDto
import ch.opentransportdata.ojp.data.dto.response.tir.leg.TransferLegDto
import ch.opentransportdata.ojp.data.dto.response.tir.leg.replaceWithParentRef
import com.tickaroo.tikxml.annotation.Element
import com.tickaroo.tikxml.annotation.PropertyElement
import com.tickaroo.tikxml.annotation.Xml
Expand All @@ -27,7 +29,6 @@ data class LegDto(
val transferLeg: TransferLegDto? = null,
@Element(name = "ContinuousLeg")
val continuousLeg: ContinuousLegDto? = null

) : Parcelable {

val legType: AbstractLegType?
Expand All @@ -42,4 +43,12 @@ fun LegDto.minimalCopy(): LegDto {
transferLeg = transferLeg,
continuousLeg = continuousLeg
)
}

fun LegDto.replaceWithParentRef(places: PlacesDto): LegDto {
return this.copy(
timedLeg = timedLeg?.replaceWithParentRef(places),
transferLeg = transferLeg,
continuousLeg = continuousLeg
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data class TripResultDto(

val TripResultDto.minimalTripResult: TripResultDto
get() = TripResultDto(
trip = trip?.minimalCopy(),
trip = trip?.minimalCopy(places = null),
id = id,
isAlternativeOption = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ch.opentransportdata.ojp.data.dto.response.tir.leg

import android.os.Parcelable
import ch.opentransportdata.ojp.data.dto.response.NameDto
import ch.opentransportdata.ojp.data.dto.response.PlacesDto
import com.tickaroo.tikxml.annotation.Element
import com.tickaroo.tikxml.annotation.PropertyElement
import com.tickaroo.tikxml.annotation.Xml
Expand Down Expand Up @@ -68,3 +69,7 @@ fun LegAlightDto.minimalCopy(): LegAlightDto {
noAlightingAtStop = null,
)
}

fun LegAlightDto.replaceWithParentRef(places: PlacesDto): LegAlightDto {
return this.copy(stopPointRef = places.findParentStation(stopPointRef))
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ch.opentransportdata.ojp.data.dto.response.tir.leg

import android.os.Parcelable
import ch.opentransportdata.ojp.data.dto.response.NameDto
import ch.opentransportdata.ojp.data.dto.response.PlacesDto
import com.tickaroo.tikxml.annotation.Element
import com.tickaroo.tikxml.annotation.PropertyElement
import com.tickaroo.tikxml.annotation.Xml
Expand Down Expand Up @@ -65,3 +66,7 @@ fun LegBoardDto.minimalCopy(): LegBoardDto {
noAlightingAtStop = null,
)
}

fun LegBoardDto.replaceWithParentRef(places: PlacesDto): LegBoardDto {
return this.copy(stopPointRef = places.findParentStation(stopPointRef))
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ch.opentransportdata.ojp.data.dto.response.tir.leg

import android.os.Parcelable
import ch.opentransportdata.ojp.data.dto.response.NameDto
import ch.opentransportdata.ojp.data.dto.response.PlacesDto
import com.tickaroo.tikxml.annotation.Element
import com.tickaroo.tikxml.annotation.PropertyElement
import com.tickaroo.tikxml.annotation.Xml
Expand Down Expand Up @@ -71,4 +72,8 @@ fun LegIntermediateDto.minimalCopy(): LegIntermediateDto {
noBoardingAtStop = null,
noAlightingAtStop = null
)
}

fun LegIntermediateDto.replaceWithParentRef(places: PlacesDto): LegIntermediateDto {
return this.copy(stopPointRef = places.findParentStation(stopPointRef))
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.opentransportdata.ojp.data.dto.response.tir.leg

import android.os.Parcelable
import ch.opentransportdata.ojp.data.dto.response.PlacesDto
import ch.opentransportdata.ojp.data.dto.response.tir.situations.PtSituationDto
import com.tickaroo.tikxml.annotation.Element
import com.tickaroo.tikxml.annotation.Xml
Expand Down Expand Up @@ -52,4 +53,12 @@ fun TimedLegDto.minimalCopy(): TimedLegDto {
service = service.minimalCopy(),
legTrack = null
)
}

fun TimedLegDto.replaceWithParentRef(places: PlacesDto): TimedLegDto {
return this.copy(
legBoard = legBoard.replaceWithParentRef(places),
legIntermediate = legIntermediate?.map { it.replaceWithParentRef(places) },
legAlight = legAlight.replaceWithParentRef(places)
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.opentransportdata.ojp.data.dto.response.tir.trips

import android.os.Parcelable
import ch.opentransportdata.ojp.data.dto.response.PlacesDto

/**
* Created by Michael Ruppen on 01.07.2024
Expand All @@ -9,9 +10,9 @@ abstract class AbstractTripDto : Parcelable {
abstract val id: String
}

fun AbstractTripDto.minimalCopy(): AbstractTripDto {
fun AbstractTripDto.minimalCopy(placesDto: PlacesDto? = null): AbstractTripDto {
return when (this) {
is TripDto -> this.minimalCopy()
is TripDto -> this.minimalCopy(places = placesDto)
else -> this
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package ch.opentransportdata.ojp.data.dto.response.tir.trips

import android.os.Parcelable
import ch.opentransportdata.ojp.data.dto.response.PlacesDto
import ch.opentransportdata.ojp.data.dto.response.tir.LegDto
import ch.opentransportdata.ojp.data.dto.response.tir.leg.ContinuousLegDto
import ch.opentransportdata.ojp.data.dto.response.tir.leg.TimedLegDto
import ch.opentransportdata.ojp.data.dto.response.tir.leg.TransferLegDto
import ch.opentransportdata.ojp.data.dto.response.tir.minimalCopy
import ch.opentransportdata.ojp.data.dto.response.tir.replaceWithParentRef
import ch.opentransportdata.ojp.data.dto.response.tir.situations.PtSituationDto
import com.tickaroo.tikxml.annotation.Element
import com.tickaroo.tikxml.annotation.PropertyElement
Expand Down Expand Up @@ -68,6 +71,7 @@ data class TripDto(

val isCarTrainTrip: Boolean
get() = legs.any { (it.legType as? TimedLegDto)?.service?.isCarTrain == true }

/**
* If the trip has [TimedLegDto.isCancelled], [isInfeasible] or [TimedLegDto.hasAnyPlatformChanges]
* set to true, it is marked to have disruptions
Expand All @@ -82,7 +86,7 @@ data class TripDto(
* [infeasible] flag is also set when trip is cancelled. [isInfeasible] shows if the trip is infeasible but not cancelled
*/
val isInfeasible: Boolean
get() = !isCancelled && infeasible == true
get() = !isCancelled && infeasible == true

val isCancelled: Boolean
get() = legs.any { (it.legType as? TimedLegDto)?.isCancelled == true }
Expand Down Expand Up @@ -124,14 +128,14 @@ data class TripDto(
}
}

fun TripDto.minimalCopy(): TripDto {
fun TripDto.minimalCopy(places: PlacesDto?): TripDto {
return TripDto(
id = id,
duration = duration,
startTime = startTime,
endTime = endTime,
transfers = transfers,
legs = legs,
legs = places?.let { p -> legs.map { it.minimalCopy().replaceWithParentRef(p) } } ?: legs.map { it.minimalCopy() },
unplanned = null,
delayed = null,
infeasible = null,
Expand Down
Loading