https://github.com/steinfletcher/paf-address-format
Java utility to format PAF UK delivery points for print
https://github.com/steinfletcher/paf-address-format
addresses formatting paf uk
Last synced: about 1 year ago
JSON representation
Java utility to format PAF UK delivery points for print
- Host: GitHub
- URL: https://github.com/steinfletcher/paf-address-format
- Owner: steinfletcher
- Created: 2016-09-12T00:37:06.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-01-11T16:41:18.000Z (over 6 years ago)
- Last Synced: 2025-03-23T20:04:40.953Z (about 1 year ago)
- Topics: addresses, formatting, paf, uk
- Language: Java
- Homepage:
- Size: 40 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
paf-address-format
===
[](https://circleci.com/gh/steinfletcher/paf-address-format)
[](https://maven-badges.herokuapp.com/maven-central/com.steinf/paf-address-format)
[](https://coveralls.io/github/steinfletcher/paf-address-format)
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](http://www.royalmail.com/sites/default/files/docs/pdf/programmers_guide_edition_7_v5.pdf)
## 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:
```
com.steinf
paf-address-format
0.0.2
```
To add a dependency using Gradle:
```
dependencies {
compile 'com.steinf:paf-address-format:0.0.2'
}
```
## Usage
### Extract the lines of the print address
```java
DeliveryPoint deliveryPoint = new DeliveryPoint.Builder()
.withSubBuildingName("A")
.withBuildingNumber("12")
.withThroughfare("HIGH STREET NORTH")
.withDependentLocality("COOMBE BISSETT")
.withPostTown("SALISBURY")
.withPostcode("SP5 4NA")
.build();
List 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
```java
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"
);
```