@@ -11,10 +11,10 @@ import com.stop.domain.model.route.gyeonggi.GyeonggiBusRoute
11
11
import com.stop.domain.model.route.gyeonggi.GyeonggiBusLastTime
12
12
import com.stop.domain.model.route.seoul.bus.*
13
13
import com.stop.domain.model.route.seoul.subway.*
14
+ import com.stop.domain.model.route.seoul.subway.Station
14
15
import com.stop.domain.model.route.tmap.RouteRequest
15
16
import com.stop.domain.model.route.tmap.custom.Coordinate
16
- import com.stop.domain.model.route.tmap.origin.ReverseGeocodingResponse
17
- import com.stop.domain.model.route.tmap.origin.RouteResponse
17
+ import com.stop.domain.model.route.tmap.origin.*
18
18
import javax.inject.Inject
19
19
20
20
internal class RouteRemoteDataSourceImpl @Inject constructor(
@@ -195,6 +195,45 @@ internal class RouteRemoteDataSourceImpl @Inject constructor(
195
195
}
196
196
}
197
197
198
+ private fun eraseDuplicateLeg (itineraries : List <Itinerary >): List <Itinerary > {
199
+ return itineraries.map { itinerary ->
200
+ var beforeInfo: Pair <String , Coordinate >? = null
201
+ var subtractTime = 0.0
202
+ var subtractDistance = 0.0
203
+
204
+ val newLegs = itinerary.legs.fold(listOf<Leg >()) { legs, leg ->
205
+ val current =
206
+ Pair (leg.mode, Coordinate (leg.start.lat.toString(), leg.start.lon.toString()))
207
+
208
+ if (legs.isEmpty()) {
209
+ beforeInfo = current
210
+ return @fold legs + leg
211
+ }
212
+
213
+ if (beforeInfo == current) {
214
+ subtractDistance + = leg.distance
215
+ subtractTime + = leg.sectionTime
216
+ return @fold legs
217
+ }
218
+ beforeInfo = current
219
+ legs + leg
220
+ }
221
+
222
+ with (itinerary) {
223
+ Itinerary (
224
+ fare = fare,
225
+ legs = newLegs,
226
+ pathType = pathType,
227
+ totalDistance = totalDistance - subtractDistance,
228
+ totalTime = totalTime - subtractTime.toInt(),
229
+ transferCount = transferCount,
230
+ walkDistance = walkDistance,
231
+ walkTime = walkTime,
232
+ )
233
+ }
234
+ }
235
+ }
236
+
198
237
private fun findStationCd (stationId : String , data : SubwayStationResponse ): String {
199
238
return data.searchInfoBySubwayNameService.row.firstOrNull {
200
239
it.frCode == stationId
0 commit comments