Class BusItinerary

    • Constructor Detail

      • BusItinerary

        public BusItinerary​(BusLine busline,
                            String name)
        Create bus itinerary with attributes stored in memory.
        Parameters:
        busline - is the line which is containing this itinerary.
        name - is the name of the new bus itinerary
      • BusItinerary

        public BusItinerary​(UUID id,
                            BusLine busline,
                            String name)
        Create bus itinerary with attributes stored in memory.
        Parameters:
        id - is the unique identifier of this element, or null if unknown.
        busline - is the line which is containing this itinerary.
        name - is the name of the new bus itinerary
        Since:
        2.0
      • BusItinerary

        public BusItinerary​(BusLine busline,
                            String name,
                            AttributeCollection attributeProvider)
        Create bus itinerary.
        Parameters:
        busline - is the line which is containing this itinerary.
        name - is the name of the new bus itinerary
        attributeProvider - is the attribute provider for this instance.
      • BusItinerary

        public BusItinerary​(UUID id,
                            BusLine busline,
                            String name,
                            AttributeCollection attributeProvider)
        Create bus itinerary.
        Parameters:
        id - is the unique identifier of this element, or null if unknown.
        busline - is the line which is containing this itinerary.
        name - is the name of the new bus itinerary
        attributeProvider - is the attribute provider for this instance.
        Since:
        2.0
      • BusItinerary

        public BusItinerary​(String name)
        Create bus itinerary with attributes stored in memory.
        Parameters:
        name - is the name of the new bus itinerary
      • BusItinerary

        public BusItinerary​(UUID id,
                            String name)
        Create bus itinerary with attributes stored in memory.
        Parameters:
        id - is the unique identifier of this element, or null if unknown.
        name - is the name of the new bus itinerary
        Since:
        2.0
      • BusItinerary

        public BusItinerary​(String name,
                            AttributeCollection attributeProvider)
        Create bus itinerary.
        Parameters:
        name - is the name of the new bus itinerary
        attributeProvider - is the attribute provider for this instance.
      • BusItinerary

        public BusItinerary​(UUID id,
                            String name,
                            AttributeCollection attributeProvider)
        Create bus itinerary.
        Parameters:
        id - is the unique identifier of this element, or null if unknown.
        name - is the name of the new bus itinerary
        attributeProvider - is the attribute provider for this instance.
        Since:
        2.0
      • BusItinerary

        public BusItinerary​(BusLine busline)
        Create bus itinerary with attributes stored in memory.
        Parameters:
        busline - is the line which is containing this itinerary.
      • BusItinerary

        public BusItinerary​(UUID id,
                            BusLine busline)
        Create bus itinerary with attributes stored in memory.
        Parameters:
        id - is the unique identifier of this element, or null if unknown.
        busline - is the line which is containing this itinerary.
        Since:
        2.0
      • BusItinerary

        public BusItinerary​(BusLine busline,
                            AttributeCollection attributeProvider)
        Create bus itinerary.
        Parameters:
        busline - is the line which is containing this itinerary.
        attributeProvider - is the attribute provider for this instance.
      • BusItinerary

        public BusItinerary​(UUID id,
                            BusLine busline,
                            AttributeCollection attributeProvider)
        Create bus itinerary.
        Parameters:
        id - is the unique identifier of this element, or null if unknown.
        busline - is the line which is containing this itinerary.
        attributeProvider - is the attribute provider for this instance.
        Since:
        2.0
      • BusItinerary

        public BusItinerary()
        Create bus itinerary with attributes stored in memory.
      • BusItinerary

        public BusItinerary​(UUID id)
        Create bus itinerary with attributes stored in memory.
        Parameters:
        id - is the unique identifier of this element, or null if unknown.
        Since:
        2.0
      • BusItinerary

        public BusItinerary​(AttributeCollection attributeProvider)
        Create bus itinerary.
        Parameters:
        attributeProvider - is the attribute provider for this instance.
      • BusItinerary

        public BusItinerary​(UUID id,
                            AttributeCollection attributeProvider)
        Create bus itinerary.
        Parameters:
        id - is the unique identifier of this element, or null if unknown.
        attributeProvider - is the attribute provider for this instance.
        Since:
        2.0
    • Method Detail

      • getFirstFreeBusItineraryName

        @Pure
        public static String getFirstFreeBusItineraryName​(BusLine busline)
        Replies a bus itinerary name that was not exist in the specified bus line.
        Parameters:
        busline - the line.
        Returns:
        a free name
      • checkPrimitiveValidity

        protected void checkPrimitiveValidity()
        Check if the validity of this primitive is correctly set and change its values if necessary. This function DO NOT revalidate the primitives inside this primitive.

        An itinerary could be invalid if one of the following critera is not true:

        1. an itinerary must contains one road segment,
        2. all the road segment are connected in a sequence,
        3. the count of bus halts must be at least 2,
        4. each bus halt must be valid,
        5. the first halt must be a starting bus halt,
        6. the last halt must be of terminus,
        7. the other bus halts must not be of type starting bus halt nor terminus,
        8. each bus halt must be located on a road segment of the itinerary,
        9. the bus halts must be ordered, no cycle nor go-back is allowed.
        Specified by:
        checkPrimitiveValidity in class AbstractBusPrimitive<BusLine>
        See Also:
        AbstractBusPrimitive.revalidate()
      • getBusNetwork

        @Pure
        public BusNetwork getBusNetwork()
        Description copied from interface: BusPrimitive
        Replies the bus network in which this primitive is.
        Specified by:
        getBusNetwork in interface BusPrimitive<BusLine>
        Returns:
        the bus network in which this primitive is.
      • toPath2D

        @Pure
        public Path2d toPath2D()
        Replies the path representation of this itinerary.
        Returns:
        the path.
      • toPath2D

        @Pure
        public void toPath2D​(Path2d path)
        Replies the path representation of this itinerary.
        Parameters:
        path - the path to fill.
      • getRoadSegmentDirection

        @Pure
        public Direction1D getRoadSegmentDirection​(int idxSegment)
        Replies the direction of the itinerary along the road segment at the specified index.
        Parameters:
        idxSegment - is the index of the road segment in the itinerary.
        Returns:
        the direction followed on the road segment.
      • invert

        public void invert()
        Invert the order of this itinerary.

        This function reverses the direction of the itinerary, ie. the order of the road segments of the itinerary.

        This function does not reverse the location of the bus halts on the itinerary. Their locations will be unchanged.

      • hasBusHaltOnSegment

        @Pure
        public boolean hasBusHaltOnSegment​(RoadSegment segment)
        Replies if the given segment has a bus halt on it.
        Parameters:
        segment - is the segment to search on.
        Returns:
        true if a bus halt was located on the segment, otherwhise false
      • getBusHaltsOnSegment

        @Pure
        public List<BusItineraryHalt> getBusHaltsOnSegment​(RoadSegment segment)
        Replies the bus halts on the given segment.
        Parameters:
        segment - is the segment to search on.
        Returns:
        the list of bus halts.
      • getBusHaltBinding

        @Pure
        public Map<BusItineraryHalt,​org.eclipse.xtext.xbase.lib.Pair<Integer,​Double>> getBusHaltBinding()
        Replies the binding informations for all the bus halts of this itinerary.
        Returns:
        the pairs containing the index of the road segment and the curviline position of each bus itinerary halt.
      • setBusHaltBinding

        public void setBusHaltBinding​(Map<BusItineraryHalt,​org.eclipse.xtext.xbase.lib.Pair<Integer,​Float>> binding)
        Set the binding informations for all the bus halts of this itinerary.
        Parameters:
        binding - are the pairs containing the index of the road segment and the curviline position of each bus itinerary halt.
      • getLength

        @Pure
        public double getLength()
        Replies the length of this itinerary.

        If the itinerary is valid, replies the distance between the start bus halt and the terminus. If the itinerary is not valid, replies the sum of the road segment lengths.

        Returns:
        the length of the itinerary.
      • getDistanceBetweenBusHalts

        @Pure
        public double getDistanceBetweenBusHalts​(int firsthaltIndex,
                                                 int lasthaltIndex)
        Replies the distance between two bus halt.
        Parameters:
        firsthaltIndex - is the index of the first bus halt.
        lasthaltIndex - is the index of the last bus halt.
        Returns:
        the distance in meters between the given bus halts.
      • getTroneonLength

        @Pure
        public double getTroneonLength​(int troneonIndex)
        Replies the distance between two bus halt. A segment between bus halts is named troneon.
        Parameters:
        troneonIndex - is the index of the troneon
        Returns:
        the distance in meters between the given bus halt and the following one.
      • getTroneonCount

        @Pure
        public int getTroneonCount()
        Replies the count of troneon. A segment between bus halts is named troneon.
        Returns:
        the count of troneons.
      • getNearestBusHalt

        @Pure
        public final BusItineraryHalt getNearestBusHalt​(Point2D<?,​?> point)
        Replies the nearest bus halt to the given point.
        Parameters:
        point - the point.
        Returns:
        the nearest bus halt or null if none was found.
      • getNearestBusHalt

        @Pure
        public final BusItineraryHalt getNearestBusHalt​(GeoLocationPoint point)
        Replies the nearest bus halt to the given point.
        Parameters:
        point - the point.
        Returns:
        the nearest bus halt or null if none was found.
      • getNearestBusHalt

        @Pure
        public BusItineraryHalt getNearestBusHalt​(double x,
                                                  double y)
        Replies the nearest bus halt to the given point.
        Parameters:
        x - x coordinate.
        y - y coordinate.
        Returns:
        the nearest bus halt or null if none was found.
      • addBusHalt

        public BusItineraryHalt addBusHalt​(UUID id,
                                           String name,
                                           BusItineraryHalt.BusItineraryHaltType type)
        Add a bus halt inside the bus itinerary.

        The insertion index is computed automatically

        Parameters:
        id - is the identifier of the bus halt.
        name - is the name of the bus halt
        type - is the type of the bus halt.
        Returns:
        the added bus halt, otherwise null
      • addBusHalt

        BusItineraryHalt addBusHalt​(UUID id,
                                    String name,
                                    BusItineraryHalt.BusItineraryHaltType type,
                                    int insertToIndex)
        Add a bus halt inside the bus itinerary.
        Parameters:
        id - is the identifier of the bus halt.
        name - is the name of the bus halt
        type - is the type of the bus halt.
        insertToIndex - the inserted index
        Returns:
        the added bus halt, otherwise null
      • addBusHalt

        public final BusItineraryHalt addBusHalt​(UUID id,
                                                 BusItineraryHalt.BusItineraryHaltType type)
        Add a bus halt inside the bus itinerary.
        Parameters:
        id - is the identifier of the bus halt.
        type - is the type of the bus halt.
        Returns:
        the added bus halt, otherwise null
      • addBusHalt

        boolean addBusHalt​(BusItineraryHalt halt,
                           int insertToIndex)
        Add the given bus halt in this itinerary.
        Parameters:
        halt - the halt.
        insertToIndex - the insertion index.
        Returns:
        true if the addition was successful, false otherwise.
      • removeAllBusHalts

        public void removeAllBusHalts()
        Remove all the bus halts from the current itinerary.
      • removeBusHalt

        public boolean removeBusHalt​(BusItineraryHalt bushalt)
        Remove a bus bus from this itinerary.
        Parameters:
        bushalt - is the bus halt to remove.
        Returns:
        true if the bus halt was successfully removed, otherwise false
      • removeBusHalt

        public boolean removeBusHalt​(String name)
        Remove the bus halt with the given name.
        Parameters:
        name - is the name of the bus halt to remove.
        Returns:
        true if the bus halt was successfully removed, otherwise false
      • removeBusHalt

        public boolean removeBusHalt​(int index)
        Remove the bus halt at the specified index.
        Parameters:
        index - is the index of the bus halt to remove.
        Returns:
        true if the bus halt was successfully removed, otherwise false
      • indexOf

        @Pure
        public int indexOf​(BusItineraryHalt bushalt)
        Replies the index of the specified bus halt.
        Parameters:
        bushalt - is the bus halt to search for.
        Returns:
        the index or -1 if it was not found.
      • indexOf

        @Pure
        public int indexOf​(RoadSegment segment)
        Replies the index of the first occurrence of the specified road segment.
        Parameters:
        segment - the segment.
        Returns:
        the index or -1 if it was not found.
      • lastIndexOf

        @Pure
        public int lastIndexOf​(RoadSegment segment)
        Replies the index of the last occurrence of the specified road segment.
        Parameters:
        segment - the segment.
        Returns:
        the index or -1 if it was not found.
      • contains

        @Pure
        public boolean contains​(BusItineraryHalt bushalt)
        Replies if the given bus halt is inside this bus itinerary.
        Parameters:
        bushalt - is the bus halt to search for.
        Returns:
        true if the bus halt is inside the itinerary, otherwise false
      • contains

        @Pure
        public boolean contains​(RoadSegment segment)
        Replies if the given segment is inside this bus itinerary.
        Parameters:
        segment - is the road segment to search for.
        Returns:
        true if the road segment is inside the itinerary, otherwise false
      • getBusHaltAt

        @Pure
        public BusItineraryHalt getBusHaltAt​(int index)
        Replies the halt at the specified index.
        Parameters:
        index - the index.
        Returns:
        a bus halt
      • getBusHalt

        @Pure
        public BusItineraryHalt getBusHalt​(String name)
        Replies the bus halt with the specified name.
        Parameters:
        name - is the desired name
        Returns:
        a bus halt or null
      • getBusHalt

        @Pure
        public BusItineraryHalt getBusHalt​(UUID uuid)
        Replies the bus halt with the specified uuid.
        Parameters:
        uuid - the identifier.
        Returns:
        BusItineraryHalt or null
      • getBusHalt

        @Pure
        public BusItineraryHalt getBusHalt​(String name,
                                           Comparator<String> nameComparator)
        Replies the bus halt with the specified name.
        Parameters:
        name - is the desired name
        nameComparator - is used to compare the names.
        Returns:
        a bus halt or null
      • busHaltIterator

        @Pure
        public Iterator<BusItineraryHalt> busHaltIterator()
        Replies the list of the bus halts of the bus itinerary.
        Returns:
        a list of bus halts
      • busHalts

        @Pure
        public Iterable<BusItineraryHalt> busHalts()
        Replies the list of the bus halts of the bus itinerary.
        Returns:
        a list of bus halts
      • toBusHaltArray

        @Pure
        public BusItineraryHalt[] toBusHaltArray()
        Replies an array of the bus halts inside this itinerary. This function copy the internal data structures into the array.
        Returns:
        an array of the bus halts inside this itinerary.
      • toInvalidBusHaltArray

        @Pure
        public BusItineraryHalt[] toInvalidBusHaltArray()
        Replies an array of the invalid bus halts inside this itinerary. This function copy the internal data structures into the array.
        Returns:
        an array of the invalid bus halts inside this itinerary.
      • toValidBusHaltArray

        @Pure
        public BusItineraryHalt[] toValidBusHaltArray()
        Replies an array of the valid bus halts inside this itinerary. This function copy the internal data structures into the array.
        Returns:
        an array of the invalid bus halts inside this itinerary.
      • getNearestRoadSegment

        @Pure
        public final RoadSegment getNearestRoadSegment​(double x,
                                                       double y)
        Replies the nearest road segment from this itinerary to the given point.
        Parameters:
        x - x coordinate.
        y - y coordinate
        Returns:
        the nearest road segment or null if none was found.
      • getNearestRoadSegment

        @Pure
        public final RoadSegment getNearestRoadSegment​(GeoLocationPoint point)
        Replies the nearest road segment from this itinerary to the given point.
        Parameters:
        point - the point
        Returns:
        the nearest road segment or null if none was found.
      • getNearestRoadSegment

        @Pure
        public RoadSegment getNearestRoadSegment​(Point2D<?,​?> point)
        Replies the nearest road segment from this itinerary to the given point.
        Parameters:
        point - the point.
        Returns:
        the nearest road segment or null if none was found.
      • putInvalidHaltsOnRoads

        public void putInvalidHaltsOnRoads​(BusItineraryHalt... restrictionList)
        Try to put the invalid halts on the roads traversed by the bus itinerary. This function is automatically invoked by addRoadSegments(RoadPath), addRoadSegment(RoadSegment), and by addRoadSegments(RoadPath, boolean), addRoadSegment(RoadSegment, boolean) when the boolean parameter is true.

        This function traverses all the candidate halts and tries to find the nearest road segment. If one was found, the bus halt is associated to the road segment. A bus itinerary halt is a candidate iff:

        1. it is invalid; and
        2. it is binded to a valid bus stop; and
          1. the size of restrictionList is zero; or
          2. the list restrictionList contains the halt.
        Parameters:
        restrictionList - is the list of the bus itinerary halts that can be binded.
        Since:
        4.0
      • putHaltOnRoad

        public boolean putHaltOnRoad​(BusItineraryHalt halt,
                                     RoadSegment road)
        Put the given bus itinerary halt on the nearest point on road.
        Parameters:
        halt - is the halt to put on the road.
        road - is the road.
        Returns:
        false if the road was not found; otherwise true. If the bus halt is not binded to a valid bus stop, replies true also.
      • putHaltOnRoad

        public boolean putHaltOnRoad​(BusItineraryHalt halt,
                                     RoadSegment road,
                                     Point2D<?,​?> nearPoint)
        Put the given bus itinerary halt on the nearest point on road depending on nearPoint position.
        Parameters:
        halt - is the halt to put on the road.
        road - is the road.
        nearPoint - the near point from road
        Returns:
        false if the road was not found; otherwise true. If the bus halt is not binded to a valid bus stop, replies true also.
      • removeAllRoadSegments

        public void removeAllRoadSegments()
        Remove all the road segments from the current itinerary.

        All the bus halts will also be removed.

      • removeRoadSegment

        public boolean removeRoadSegment​(int segmentIndex)
        Remove a road segment from this itinerary.

        The bus halts on the segment will also be removed.

        Parameters:
        segmentIndex - is the index of the segment to remove.
        Returns:
        true if the segment was successfully removed, otherwise false
      • removeRoadSegment

        public Set<Integer> removeRoadSegment​(RoadSegment segment)
        Remove a road segment from this itinerary. This function remove all the road segment occurrences.

        The bus halts on the segments will also be removed.

        This function tries to reconnect the paths that are previously attached to the remove segment. See removeRoadSegment(RoadSegment, boolean) for details.

        Parameters:
        segment - is the segment to remove.
        Returns:
        the collection of the indexes of the removed occurrences; never null.
        See Also:
        removeRoadSegment(RoadSegment, boolean)
      • removeRoadSegment

        public Set<Integer> removeRoadSegment​(RoadSegment segment,
                                              boolean tryToReconnect)
        Remove a road segment from this itinerary. This function remove all the road segment occurrences.

        The bus halts on the segments will also be removed.

        The parameter tryToReconnect indicates if the function tries to reconnect the paths previously attached to the removed segments.

        Parameters:
        segment - is the segment to remove.
        tryToReconnect - indicates if the path connections should be preserved when possible.
        Returns:
        the collection of the indexes of the removed occurrences; never null.
        See Also:
        removeRoadSegment(RoadSegment)
      • getRoadSegmentCount

        @Pure
        public int getRoadSegmentCount()
        Replies the count of road segments into this itinerary.
        Returns:
        the count of road segments into this itinerary.
      • getRoadSegmentAt

        @Pure
        public RoadSegment getRoadSegmentAt​(int index)
        Replies the segment at the specified index.
        Parameters:
        index - the index.
        Returns:
        a road segment
      • roadSegmentsIterator

        @Pure
        public Iterator<RoadSegment> roadSegmentsIterator()
        Replies the list of the road segments of the bus itinerary.
        Returns:
        a list of road segments
      • roadSegments

        @Pure
        public Iterable<RoadSegment> roadSegments()
        Replies the list of the road segments of the bus itinerary.
        Returns:
        a list of road segments
      • getRoadPath

        @Pure
        public RoadPath getRoadPath()
        Replies a road path that is containing all road segments of this itinerary when they are correctly connected.

        Connected Road segments that are covered by the itinerary are put into the same cluster of road segments. If no path between two road segments, covered by the itinerary, cannot be found without discontinuity; the two road segments are inside two different clusters of road segments.

        Returns:
        a road path for this itinerary, or null if the road segments for this itinerary ar not well connected.
      • getRoadPaths

        @Pure
        public Collection<RoadPath> getRoadPaths()
        Replies the unconnected road paths which are used by this bus itinerary.

        Connected Road segments that are covered by the itinerary are put into the same cluster of road segments. If no path between two road segments, covered by the itinerary, cannot be found without discontinuity; the two road segments are inside two different clusters of road segments.

        Returns:
        a set of road paths for this itinerary.
      • getRoadPathCount

        @Pure
        public int getRoadPathCount()
        Replies the number of road-path clusters for this itinerary.

        Connected Road segments that are covered by the itinerary are put into the same cluster of road segments. If no path between two road segments, covered by the itinerary, cannot be found without discontinuity; the two road segments are inside two different clusters of road segments.

        Returns:
        the number of road-path clusters.