19 package org.turro.financials.cart.delivery;
21 import java.io.Serializable;
22 import java.util.regex.Matcher;
23 import java.util.regex.Pattern;
24 import org.turro.string.Strings;
25 import org.turro.util.Range;
33 private static final Pattern
34 PREFIX = Pattern.compile(
"([^\\(]+) \\(([^\\)]*)"),
35 RANGE = Pattern.compile(
"[^0-9]*([0-9]+)[^0-9]*");
38 String[] fields = line.split(
"\\s*,\\s*");
39 if(fields.length >= 5) {
41 String street = fields[2];
42 Matcher matcher = PREFIX.matcher(street);
44 street = matcher.group(2) +
" " + matcher.group(1);
46 Range even = parseRange(fields[3]);
47 Range odd = parseRange(fields[4]);
48 return new StreetItem(fields[0], fields[1], street, even, odd);
53 private static Range parseRange(String field) {
54 String[] numbers = field.split(
"\\s*\\-\\s*");
55 Integer start = 1, end = Integer.MAX_VALUE;
56 if(numbers.length == 2) {
57 Matcher matcher = RANGE.matcher(numbers[0]);
59 start = Integer.valueOf(matcher.group(1));
61 matcher = RANGE.matcher(numbers[1]);
63 end = Integer.valueOf(matcher.group(1));
66 return new Range<>(start, end);
69 private final String city, zipcode, street;
70 private final Range<Integer> even, odd;
72 public StreetItem(String city, String zipcode, String street, Range<Integer> even, Range<Integer> odd) {
74 this.zipcode = zipcode;
101 return street.matches(
".*" + search +
".*");
105 return !Strings.isBlank(city) && !Strings.isBlank(street) &&
106 !Strings.isBlank(zipcode) && zipcode.matches(
"[0-9]{5}");
StreetItem(String city, String zipcode, String street, Range< Integer > even, Range< Integer > odd)
Range< Integer > getEven()
Range< Integer > getOdd()
boolean matches(String search)
static StreetItem parseLine(String line)