Skip to content

steinfletcher/paf-address-format

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

paf-address-format

CircleCI Maven Central Coverage Status

A simple library (with no dependencies) that formats a PAF address for print.

Attempts to comply with the Royal Mail's PAF Programmer's guide

Why?

There are 7 rules which determine the print format of an address and several exceptions can be applied to these rules. Writing some code to format an address is not a trivial task. Given an address, this library determines the rule type, analyzes which exceptions should be applied and invokes a specific formatter for the address.

Release

To add the dependency using Maven, use the following:

<dependency>
    <groupId>com.steinf</groupId>
    <artifactId>paf-address-format</artifactId>
    <version>0.0.2</version>
</dependency>

To add a dependency using Gradle:

dependencies {
  compile 'com.steinf:paf-address-format:0.0.2'
}

Usage

Extract the lines of the print address

DeliveryPoint deliveryPoint = new DeliveryPoint.Builder()
  .withSubBuildingName("A")
  .withBuildingNumber("12")
  .withThroughfare("HIGH STREET NORTH")
  .withDependentLocality("COOMBE BISSETT")
  .withPostTown("SALISBURY")
  .withPostcode("SP5 4NA")
  .build();

List<String> parts = deliveryPoint.formattedParts();

assertThat(parts.get(0)).isEqualTo("12A HIGH STREET NORTH");
assertThat(parts.get(1)).isEqualTo("COOMBE BISSETT");
assertThat(parts.get(2)).isEqualTo("SALISBURY");
assertThat(parts.get(3)).isEqualTo("SP5 4NA");

Get the entire address as a string

DeliveryPoint deliveryPoint = new DeliveryPoint.Builder()
  .withSubBuildingName("2B")
  .withBuildingName("THE TOWER")
  .withBuildingNumber("27")
  .withThroughfare("JOHN STREET")
  .withPostTown("WINCHESTER")
  .withPostcode("SO23 9AP")
  .build();

String formatted = deliveryPoint.toString();

assertThat(formatted).isEqualTo(
    "2B THE TOWER\n" +
    "27 JOHN STREET\n" +
    "WINCHESTER\n" +
    "SO23 9AP"
);

About

Java utility to format PAF UK delivery points for print

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages