我想使用java为具有特定站点ID的公交站点分配链接ID

yvfmudvl  于 2021-07-08  发布在  Java
关注(0)|答案(1)|浏览(188)

我已经创建了一个28个链接id的列表,这些id是在一个巴士站编号的序列中,我想将这些id分配给具有相同id编号的巴士站。。我在写这样的代码:

//create transitStops
Map<String, Coord> busStopToCoordinate = getStopsCoordinates(); //contains the bus stop ids and coordinate.
for (Map.Entry<String, Coord> entry : busStopToCoordinate.entrySet()) {
            String k = entry.getKey();
            Coord v = entry.getValue();
            TransitStopFacility stop = factory.createTransitStopFacility(Id.create(k, TransitStopFacility.class), v, false);

//stopLinkIds
       final List<Id<Link>> stopLinkIdList = List.of(Id.createLinkId("5823673530001f"), Id.createLinkId("5145215680000f"), Id.createLinkId("317565150006f"),
                Id.createLinkId("1504018850006f"), Id.createLinkId("5705260710001f"), Id.createLinkId("317565100018f"), Id.createLinkId("5637147670004f"),
                Id.createLinkId("5606511090002f"), Id.createLinkId("5831437080006f"), Id.createLinkId("6568056490001f"), Id.createLinkId("6888270010007f"), //11
                Id.createLinkId("6140720190001f"), Id.createLinkId("6598332090009f"), Id.createLinkId("6044866480001f"), Id.createLinkId("5637147760010f"), //15
                Id.createLinkId("5418873140000f"), Id.createLinkId("295304080021f"), Id.createLinkId("6866052960004f"), //18-need to edit the link
                Id.createLinkId("5542886270001f"), Id.createLinkId("281215370005f"), Id.createLinkId("5714501110001f"), Id.createLinkId("6036480960000f"), //22-traffic signal
                Id.createLinkId("1504018850002f"), Id.createLinkId("6156254680000f"), Id.createLinkId("317565150042f"), Id.createLinkId("773640050003f"),
                Id.createLinkId("3120319040006f"), Id.createLinkId("1912048840014f"));

//adding link ids to the stop. ~ Main Problem

            for (int i = 0; i < stopLinkIdList.size(); i++) {
                stop.setLinkId(stopLinkIdList.get(i));
            }

\\adding stop to the transit schedule
            schedule.addStopFacility(stop);

        }

但是最后一个链接id被添加到所有站点。如何纠正这个错误?我正在添加输出的图像,以便更好地理解问题和问题

whhtz7ly

whhtz7ly1#

你在问题中提到:

I want to assign those ids to the bus stop with the same id numbers..

为此,应将此for循环替换为:

for (int i = 0; i < stopLinkIdList.size(); i++) {
                stop.setLinkId(stopLinkIdList.get(i));
      }

由此:

int stopId = stop.id;//fill in the stopId variable accordingly by the id of the bus_stop
  stop.setLinkId(stopLinkIdList.get(stopId-1));

最好在代码的开头定义“stopLinkId列表”列表,而不是在foreach循环中

相关问题