/**
  * Within search radius search for the closest link that has the current mode as allowed travel
  * mode and return this link.
  *
  * @param stopFacility Stop facility to search a link for.
  * @return Null if no such link could be found.
  */
 private Id<Link> findClosestLink(TransitStopFacility stopFacility) {
   Link nearestLink = NetworkUtils.getNearestLink(this.network, stopFacility.getCoord());
   if (NetworkUtils.getEuclidianDistance(
           stopFacility.getCoord(), nearestLink.getToNode().getCoord())
       <= SEARCH_RADIUS) {
     // If nearest link is within search radius, return it.
     return nearestLink.getId();
   } else {
     return null;
   }
 }
 ArtificiallyConnectedStopFacility(TransitStopFacility facility) {
   myNode =
       networkFactory.createNode(
           Id.create(prefix + facility.getId(), Node.class), facility.getCoord());
   myLink = getNewLink(myNode, myNode);
   facility.setLinkId(myLink.getId());
 }
 /**
  * Create and add to schedule new stops with the id-endings "_1" to "_numberOfCopies" by copying
  * the provided stopFacility.
  *
  * @param stopFacility which will be copied. The original becomes the first element of the
  *     returned array.
  * @param numberOfCopies of stopFacility which are created.
  * @return TransitStopFacilities stopFacility, and copies stop_1 to stop_numberOfCopies
  */
 private TransitStopFacility[] multiplyStop(TransitStopFacility stopFacility, int numberOfCopies) {
   TransitStopFacility[] facilities = new TransitStopFacility[numberOfCopies + 1];
   facilities[0] = stopFacility;
   for (int i = 1; i <= numberOfCopies; i++) {
     // Copy facility at stopFacility:
     Id<TransitStopFacility> idNewFacility =
         Id.create(stopFacility.getId().toString() + "_" + i, TransitStopFacility.class);
     TransitStopFacility newFacility =
         this.scheduleFactory.createTransitStopFacility(
             idNewFacility, stopFacility.getCoord(), stopFacility.getIsBlockingLane());
     newFacility.setName(stopFacility.getName());
     // Add new facility to schedule and to array:
     facilities[i] = newFacility;
   }
   return facilities;
 }
 private void setConnectedStopFacilitiesToIsBlocking() {
   Set<TransitStopFacility> facilitiesToExchange = new HashSet<>();
   for (TransitStopFacility oldFacility : this.schedule.getFacilities().values()) {
     if (this.network
         .getLinks()
         .get(oldFacility.getLinkId())
         .getAllowedModes()
         .contains(TransportMode.car)) {
       TransitStopFacility newFacility =
           this.scheduleFactory.createTransitStopFacility(
               oldFacility.getId(), oldFacility.getCoord(), true);
       newFacility.setName(oldFacility.getName());
       newFacility.setLinkId(oldFacility.getLinkId());
       newFacility.setStopPostAreaId(oldFacility.getStopPostAreaId());
       facilitiesToExchange.add(newFacility);
     }
   }
   for (TransitStopFacility facility : facilitiesToExchange) {
     TransitStopFacility facilityToRemove = this.schedule.getFacilities().get(facility.getId());
     this.schedule.removeStopFacility(facilityToRemove);
     this.schedule.addStopFacility(facility);
   }
 }