@Test public void testFullAddress() { assertIsAddress("1600 Amphitheatre Parkway Mountain View, CA 94043"); assertIsAddress("201 S. Division St. Suite 500 Ann Arbor, MI 48104"); Assert.assertTrue(containsAddress( "Millennium at Midtown 10 10th Street NE Suite 600 Atlanta, GA 30309")); assertIsAddress("9606 North MoPac Expressway Suite 400 Austin, TX 78759"); assertIsAddress("2590 Pearl Street Suite 100 Boulder, CO 80302"); assertIsAddress("5 Cambridge Center, Floors 3-6 Cambridge, MA 02142"); assertIsAddress("410 Market St Suite 415 Chapel Hill, NC 27516"); assertIsAddress("20 West Kinzie St. Chicago, IL 60654"); assertIsAddress("114 Willits Street Birmingham, MI 48009"); assertIsAddress("19540 Jamboree Road 2nd Floor Irvine, CA 92612"); assertIsAddress("747 6th Street South, Kirkland, WA 98033"); assertIsAddress("301 S. Blount St. Suite 301 Madison, WI 53703"); assertIsAddress("76 Ninth Avenue 4th Floor New York, NY 10011"); Assert.assertTrue(containsAddress( "Chelsea Markset Space, 75 Ninth Avenue 2nd and 4th Floors New York, NY 10011")); assertIsAddress("6425 Penn Ave. Suite 700 Pittsburgh, PA 15206"); assertIsAddress("1818 Library Street Suite 400 Reston, VA 20190"); assertIsAddress("345 Spear Street Floors 2-4 San Francisco, CA 94105"); assertIsAddress("604 Arizona Avenue Santa Monica, CA 90401"); assertIsAddress("651 N. 34th St. Seattle, WA 98103"); Assert.assertTrue( isAddress("1101 New York Avenue, N.W. Second Floor Washington, DC 20005")); assertIsAddress("57th Street and Lake Shore Drive\nChicago, IL 60637"); assertIsAddress("308 Congress Street Boston, MA 02210"); Assert.assertTrue( containsAddress("Central Park West at 79th Street, New York, NY, 10024-5192")); Assert.assertTrue(containsAddress( "Lincoln Park | 100 34th Avenue • San Francisco, CA 94121 | 41575036")); Assert.assertEquals( FindAddress.findAddress( "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do " + "1600 Amphitheatre Parkway Mountain View, CA 94043 eiusmod " + "tempor incididunt ut labore et dolore magna aliqua."), "1600 Amphitheatre Parkway Mountain View, CA 94043"); Assert.assertEquals(FindAddress.findAddress("2590 Pearl Street Suite 100 Boulder, CO 80302 " + "6425 Penn Ave. Suite 700 Pittsburgh, PA 15206"), "2590 Pearl Street Suite 100 Boulder, CO 80302"); assertIsAddress("5400 Preston Oaks Rd Dallas TX 75254"); assertIsAddress("5400 Preston Oaks Road Dallas TX 75254"); assertIsAddress("5400 Preston Oaks Ave Dallas TX 75254"); Assert.assertTrue( containsAddress("住所は 1600 Amphitheatre Parkway Mountain View, CA 94043 です。")); Assert.assertFalse(containsAddress("1 st. too-short, CA 90000")); Assert.assertTrue(containsAddress("1 st. long enough, CA 90000")); Assert.assertTrue(containsAddress("1 st. some city in al 35000")); Assert.assertFalse(containsAddress("1 book st Aquinas et al 35000")); Assert.assertFalse(containsAddress("1 this comes too late: street, CA 90000")); Assert.assertTrue(containsAddress("1 this is ok: street, CA 90000")); Assert.assertFalse( containsAddress("1 street I love verbosity, so I'm writing an address with " + "too many words CA 90000")); Assert.assertTrue(containsAddress("1 street 2 3 4 5 6 7 8 9 10 11 12, CA 90000")); assertIsAddress("79th Street 1st Floor New York City, NY 10024-5192"); assertIsAddress("79th Street 1st Floor New York 10024-5192"); assertIsAddress("79th Street 1st Floor New York 10024-5192"); Assert.assertNull(FindAddress.findAddress("79th Street 1st Floor New\nYork 10024-5192")); Assert.assertNull(FindAddress.findAddress("79th Street 1st Floor New, York 10024-5192")); Assert.assertFalse(containsAddress("123 Fake Street, Springfield, Springfield")); Assert.assertFalse(containsAddress("999 Street Avenue, City, ZZ 98765")); Assert.assertFalse(containsAddress("76 Here be dragons, CA 94043")); Assert.assertFalse(containsAddress("1 This, has, too* many, lines, to, be* valid")); Assert.assertFalse( containsAddress("1 Supercalifragilisticexpialidocious is too long, CA 90000")); Assert.assertFalse(containsAddress("")); }
static String findAddress(String content) { Matcher houseNumberMatcher = sHouseNumberRe.matcher(content); int start = 0; while (houseNumberMatcher.find(start)) { if (checkHouseNumber(houseNumberMatcher.group(0))) { start = houseNumberMatcher.start(); int end = attemptMatch(content, houseNumberMatcher); if (end > 0) { return content.substring(start, end); } start = -end; } else { start = houseNumberMatcher.end(); } } return null; }
FindAddress { static String findAddress(String content) { Matcher houseNumberMatcher = sHouseNumberRe.matcher(content); int start = 0; while (houseNumberMatcher.find(start)) { if (checkHouseNumber(houseNumberMatcher.group(0))) { start = houseNumberMatcher.start(); int end = attemptMatch(content, houseNumberMatcher); if (end > 0) { return content.substring(start, end); } start = -end; } else { start = houseNumberMatcher.end(); } } return null; } }
FindAddress { static String findAddress(String content) { Matcher houseNumberMatcher = sHouseNumberRe.matcher(content); int start = 0; while (houseNumberMatcher.find(start)) { if (checkHouseNumber(houseNumberMatcher.group(0))) { start = houseNumberMatcher.start(); int end = attemptMatch(content, houseNumberMatcher); if (end > 0) { return content.substring(start, end); } start = -end; } else { start = houseNumberMatcher.end(); } } return null; } private  FindAddress(); }
FindAddress { static String findAddress(String content) { Matcher houseNumberMatcher = sHouseNumberRe.matcher(content); int start = 0; while (houseNumberMatcher.find(start)) { if (checkHouseNumber(houseNumberMatcher.group(0))) { start = houseNumberMatcher.start(); int end = attemptMatch(content, houseNumberMatcher); if (end > 0) { return content.substring(start, end); } start = -end; } else { start = houseNumberMatcher.end(); } } return null; } private  FindAddress(); @VisibleForTesting static MatchResult matchHouseNumber(String content, int offset); @VisibleForTesting static MatchResult matchState(String content, int offset); @VisibleForTesting static boolean isValidZipCode(String zipCode, String state); @VisibleForTesting static boolean isValidZipCode(String zipCode); @VisibleForTesting static boolean isValidLocationName(String location); }
FindAddress { static String findAddress(String content) { Matcher houseNumberMatcher = sHouseNumberRe.matcher(content); int start = 0; while (houseNumberMatcher.find(start)) { if (checkHouseNumber(houseNumberMatcher.group(0))) { start = houseNumberMatcher.start(); int end = attemptMatch(content, houseNumberMatcher); if (end > 0) { return content.substring(start, end); } start = -end; } else { start = houseNumberMatcher.end(); } } return null; } private  FindAddress(); @VisibleForTesting static MatchResult matchHouseNumber(String content, int offset); @VisibleForTesting static MatchResult matchState(String content, int offset); @VisibleForTesting static boolean isValidZipCode(String zipCode, String state); @VisibleForTesting static boolean isValidZipCode(String zipCode); @VisibleForTesting static boolean isValidLocationName(String location);  }