package de.ivu.elect.nl.interfaces.gbav.mapper;

public class GbavPostcodeMapper {
  public static String mapGbavPostcodeToPostcode(String valuePostcode) {
    if (valuePostcode != null && valuePostcode.length() == 6) {
      StringBuilder sb = new StringBuilder();
      sb.append(valuePostcode.substring(0, 4));
      sb.append(" ");
      sb.append(valuePostcode.substring(4, 6));
      return sb.toString();
    }
    return valuePostcode;
  }

  public static String mapPostcodeToGbavPostcode(String postcode) {
    if (postcode != null && postcode.matches("\\d{4} [a-zA-Z]{2}")) {
      StringBuilder sb = new StringBuilder();
      sb.append(postcode.substring(0, 4));
      sb.append(postcode.substring(5, 7));
      return sb.toString();
    }
    return postcode;
  }
}
