コード例 #1
0
  private void initTruckGroupTotals() {
    this.truckGroupTotalsMap =
        this.truckGroupService.getTruckGroupTotalsForTransport(transport.getId());

    this.truckGroupTotalsKeys = new ArrayList<String>();
    this.truckGroupTotalsKeys.addAll(truckGroupTotalsMap.keySet());

    Collections.sort(this.truckGroupTotalsKeys);

    this.truckGroupTotals = new ArrayList<TruckGroupTotalsModel>();

    for (String string : this.truckGroupTotalsKeys) {
      TruckGroupTotalsModel model = this.truckGroupTotalsMap.get(string);
      this.truckGroupTotals.add(model);
      this.truckGroupsPrice += model.getTotalPrice().intValue();
    }

    Collections.sort(
        this.truckGroupTotals,
        new Comparator<TruckGroupTotalsModel>() {

          @Override
          public int compare(TruckGroupTotalsModel o1, TruckGroupTotalsModel o2) {
            return sortTruckGroupTotals(o1, o2);
          }
        });
  }
コード例 #2
0
  public int sortTruckGroupTotals(TruckGroupTotalsModel model1, TruckGroupTotalsModel model2) {
    Integer model1Number = null;
    Integer model2Number = null;
    try {
      model1Number = Integer.parseInt(model1.getName());
    } catch (NumberFormatException exception) {

    }

    try {
      model2Number = Integer.parseInt(model2.getName());
    } catch (NumberFormatException exception) {

    }

    if (model1Number == null) {
      return 1;
    } else if (model2Number == null) {
      return -1;
    } else {
      return model1Number.compareTo(model2Number);
    }
  }