| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | import ObjId from '../data/ObjId.js'; |
| 25 | import ObjType from '../data/ObjType.js'; |
| 26 | import Collection from '../data/Collection.js'; |
| 27 | import ItineraryPoint from '../data/ItineraryPoint.js'; |
| 28 | import Maneuver from '../data/Maneuver.js'; |
| 29 | import theHTMLSanitizer from '../core/htmlSanitizer/HTMLSanitizer.js'; |
| 30 | import TravelObject from '../data/TravelObject.js'; |
| 31 | import { ZERO, INVALID_OBJ_ID } from '../main/Constants.js'; |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | class Itinerary extends TravelObject { |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | static #objType = new ObjType ( |
| 47 | 'Itinerary', |
| 48 | [ 'hasProfile', 'ascent', 'descent', 'itineraryPoints', 'maneuvers', 'provider', 'transitMode', 'objId' ] |
| 49 | ); |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | #objId = INVALID_OBJ_ID; |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | #hasProfile = false; |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | #ascent = ZERO; |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | #descent = ZERO; |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | #provider = ''; |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | #transitMode = ''; |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | #itineraryPoints = new Collection ( ItineraryPoint ); |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | #maneuvers = new Collection ( Maneuver ); |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | constructor ( ) { |
| 112 | super ( ); |
| 113 | this.#objId = ObjId.nextObjId; |
| 114 | } |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | get hasProfile ( ) { return this.#hasProfile; } |
| 122 | |
| 123 | set hasProfile ( hasProfile ) { |
| 124 | this.#hasProfile = 'boolean' === typeof ( hasProfile ) ? hasProfile : false; |
| 125 | } |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | get ascent ( ) { return this.#ascent; } |
| 133 | |
| 134 | set ascent ( ascent ) { |
| 135 | this.#ascent = 'number' === typeof ( ascent ) ? Number.parseInt ( ascent ) : ZERO; |
| 136 | } |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | get descent ( ) { return this.#descent; } |
| 144 | |
| 145 | set descent ( descent ) { |
| 146 | this.#descent = 'number' === typeof ( descent ) ? Number.parseInt ( descent ) : ZERO; |
| 147 | } |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | get provider ( ) { return this.#provider; } |
| 155 | |
| 156 | set provider ( provider ) { |
| 157 | this.#provider = 'string' === typeof ( provider ) ? theHTMLSanitizer.sanitizeToJsString ( provider ) : ''; |
| 158 | } |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | get transitMode ( ) { return this.#transitMode; } |
| 166 | |
| 167 | set transitMode ( transitMode ) { |
| 168 | this.#transitMode = 'string' === typeof ( transitMode ) ? theHTMLSanitizer.sanitizeToJsString ( transitMode ) : ''; |
| 169 | } |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | get itineraryPoints ( ) { return this.#itineraryPoints; } |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | get maneuvers ( ) { return this.#maneuvers; } |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | get objType ( ) { return Itinerary.#objType; } |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | get objId ( ) { return this.#objId; } |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | get jsonObject ( ) { |
| 206 | return { |
| 207 | hasProfile : this.hasProfile, |
| 208 | ascent : this.ascent, |
| 209 | descent : this.descent, |
| 210 | itineraryPoints : this.itineraryPoints.jsonObject, |
| 211 | maneuvers : this.maneuvers.jsonObject, |
| 212 | provider : this.provider, |
| 213 | transitMode : this.transitMode, |
| 214 | objId : this.#objId, |
| 215 | objType : this.objType.jsonObject |
| 216 | }; |
| 217 | } |
| 218 | set jsonObject ( something ) { |
| 219 | const otherthing = this.validateObject ( something ); |
| 220 | this.hasProfile = otherthing.hasProfile; |
| 221 | this.ascent = otherthing.ascent; |
| 222 | this.descent = otherthing.descent; |
| 223 | this.itineraryPoints.jsonObject = otherthing.itineraryPoints; |
| 224 | this.maneuvers.jsonObject = otherthing.maneuvers; |
| 225 | this.provider = otherthing.provider; |
| 226 | this.transitMode = otherthing.transitMode; |
| 227 | this.#objId = ObjId.nextObjId; |
| 228 | |
| 229 | |
| 230 | const itineraryPointObjIdMap = new Map ( ); |
| 231 | let sourceCounter = ZERO; |
| 232 | const itineraryPointsIterator = this.itineraryPoints.iterator; |
| 233 | while ( ! itineraryPointsIterator.done ) { |
| 234 | itineraryPointObjIdMap.set ( |
| 235 | otherthing.itineraryPoints [ sourceCounter ].objId, |
| 236 | itineraryPointsIterator.value.objId |
| 237 | ); |
| 238 | sourceCounter ++; |
| 239 | } |
| 240 | const maneuverIterator = this.maneuvers.iterator; |
| 241 | while ( ! maneuverIterator.done ) { |
| 242 | maneuverIterator.value.itineraryPointObjId = |
| 243 | itineraryPointObjIdMap.get ( maneuverIterator.value.itineraryPointObjId ); |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | export default Itinerary; |
| 249 | |
| 250 | |
| 251 | |