예제 #1
0
  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  // 根据区段获得属于区段内的所有车站信息  并排序
  public void getAllStationInfoByDistrict(String districtName) {

    StationDistrictRelation tableName = new StationDistrictRelation(); // 设置要进行操作的数据库表名
    String sqlStr =
        "select * from stationdistrictrelation where District_name = '" + districtName + "'";

    // 获取区段内所有车站信息
    List<StationDistrictRelation> list =
        databaseAccessHandler.sqlQuery(tableName, "StationDistrictRelation", sqlStr);

    List<StationDistrictRelation> sortedStationDistrictRelationList =
        new ArrayList<StationDistrictRelation>();

    // 对区段内所有车站信息进行排序 : 首站->终点站
    sortedStationDistrictRelationList = this.sortStations(list);

    baseParam.setSortedStationDistrictRelationList(sortedStationDistrictRelationList);
    if (sortedStationDistrictRelationList == null || sortedStationDistrictRelationList.size() == 0)
      return;

    int len = sortedStationDistrictRelationList.size();
    List<String> stationNameList = new ArrayList<String>();
    // 计算区段内站的总距离 和提取车站名
    int sumStationDistance = 0;
    for (int i = 0; i < len; i++) {
      StationDistrictRelation sdr = sortedStationDistrictRelationList.get(i);
      sumStationDistance = sumStationDistance + sdr.getPredistance();
      stationNameList.add(sdr.getStation_name()); // 提取车站名
    }

    BaseParam.setSortedStationNameList(stationNameList);

    baseParam.setSumStationDistance(sumStationDistance);
  }
예제 #2
0
  // 对list序列进行排序 首站->终点站
  private List<StationDistrictRelation> sortStations(List<StationDistrictRelation> list) {

    List<StationDistrictRelation> sortedList = new ArrayList<StationDistrictRelation>();

    if ((list == null) || (list.size() == 0)) {
      return null;
    }
    StationDistrictRelation sdr = new StationDistrictRelation();
    int listLength = list.size();
    String preStationName = "";

    // 查找区段内首站,即第一个车站
    for (int i = 0; i < listLength; i++) {
      sdr = list.get(i);
      String stationName = sdr.getStation_name();
      if (stationName.equalsIgnoreCase(sdr.getPrestation_name())) {
        preStationName = stationName;
        sortedList.add(sdr);
        break;
      }
    }

    // 没有找到首站
    if (preStationName.length() == 0) {
      return null;
    }
    // 依据首站 依次查找区段内其他站
    for (int i = 0; i < listLength; i++) {
      sdr = list.get(i);
      if (sdr.getStation_name().equalsIgnoreCase(sdr.getPrestation_name())) { // 首站
        continue;
      }
      for (int j = 0; j < listLength; j++) {
        sdr = list.get(j);
        String stationName = sdr.getStation_name();
        if (stationName.equalsIgnoreCase(sdr.getPrestation_name())) { // 首站
          continue;
        } else // 非首站
        if (preStationName.equalsIgnoreCase(sdr.getPrestation_name())) {
          preStationName = stationName;
          sortedList.add(sdr);
        }
      }
    }
    return sortedList;
  }