com.steinf:paf-address-format

A library to format a UK postal address (PAF) for printing

License

License

Categories

Categories

ORM Data
GroupId

GroupId

com.steinf
ArtifactId

ArtifactId

paf-address-format
Last Version

Last Version

0.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

com.steinf:paf-address-format
A library to format a UK postal address (PAF) for printing
Project URL

Project URL

https://github.com/steinfletcher/paf-address-format
Source Code Management

Source Code Management

https://github.com/steinfletcher/paf-address-format

Download paf-address-format

How to add to project

<!-- https://jarcasting.com/artifacts/com.steinf/paf-address-format/ -->
<dependency>
    <groupId>com.steinf</groupId>
    <artifactId>paf-address-format</artifactId>
    <version>0.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.steinf/paf-address-format/
implementation 'com.steinf:paf-address-format:0.0.2'
// https://jarcasting.com/artifacts/com.steinf/paf-address-format/
implementation ("com.steinf:paf-address-format:0.0.2")
'com.steinf:paf-address-format:jar:0.0.2'
<dependency org="com.steinf" name="paf-address-format" rev="0.0.2">
  <artifact name="paf-address-format" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.steinf', module='paf-address-format', version='0.0.2')
)
libraryDependencies += "com.steinf" % "paf-address-format" % "0.0.2"
[com.steinf/paf-address-format "0.0.2"]

Dependencies

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
org.assertj : assertj-core jar 3.4.1

Project Modules

There are no modules declared in this project.

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"
);

Versions

Version
0.0.2
0.0.1