All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.kit.ifv.mobitopp.dataimport.RangeItemParser Maven / Gradle / Ivy

Go to download

mobiTopp (http://mobitopp.ifv.kit.edu/) is an agent-based travel demand model developed at the Institute for transport studies at the Karlsruhe Institute of Technology (http://www.ifv.kit.edu/english/index.php). Publications about mobiTopp can be found on the project site (http://mobitopp.ifv.kit.edu/28.php).

The newest version!
package edu.kit.ifv.mobitopp.dataimport;

import edu.kit.ifv.mobitopp.data.demand.RangeDistributionItem;

public class RangeItemParser {

  static final String separator = "-";
  private final String prefix;

  public RangeItemParser(String prefix) {
    super();
    this.prefix = prefix;
  }

  public RangeDistributionItem parse(int number, String columnName) {
    String bounds = columnName.replaceFirst(prefix, "");
    if (isRange(bounds)) {
      return parseRange(number, bounds);
    }
    return parseSingle(number, bounds);
  }

  private boolean isRange(String bounds) {
    return bounds.contains(separator);
  }

  private RangeDistributionItem parseRange(int number, String bounds) {
    String[] parts = bounds.split(separator);
    int lowerBound = Integer.parseInt(parts[0]);
    int upperBound = (parts.length == 2) ? Integer.parseInt(parts[1]) : Integer.MAX_VALUE;
    return new RangeDistributionItem(lowerBound, upperBound, number);
  }

  private RangeDistributionItem parseSingle(int number, String bounds) {
    int bound = Integer.parseInt(bounds);
    return new RangeDistributionItem(bound, number);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy