java.lang.Object
uk.ac.leeds.ccg.ukpc.UKPC_Checker
public class UKPC_Checker
extends java.lang.Object
For checking Strings to see if they might be viable UK unit, sector, district
or area postcodes and for returning the type of unit, sector and district
postcodes.
Postcodes take various forms comprised of alphanumeric characters. This class
contains methods for efficiently check if Strings are of the right length and
have the digits 0 to 9 and restricted sets of alphabetic characters in viable
places.
The general format of a postcode is given in:
https://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom
- Version:
- 1.0.0
- Author:
- Andy Turner
-
Field Summary
Fields Modifier and Type Field Description static char[]ABCDEFGHJKSTUWstatic char[]ABEHMNPRVWXYstatic char[]AtoZstatic char[]AtoZ_not_CIKMOVstatic char[]AtoZ_not_IJZstatic char[]AtoZ_not_QVXstatic char[]digitsstatic intTYPE_AAAstatic intTYPE_AANstatic intTYPE_AANAstatic intTYPE_AANNstatic intTYPE_ANstatic intTYPE_ANAstatic intTYPE_ANN -
Constructor Summary
Constructors Constructor Description UKPC_Checker()Creates a new UKPC_Checker. -
Method Summary
Modifier and Type Method Description booleancontains(char c, char[] a)intgetFirstPartPostcodeType(char[] fpp)intgetPostcodeSectorType(java.lang.String s, int length)intgetUnitPostcodeType(java.lang.String s)intgetUnitPostcodeType(java.lang.String s, int length)booleanisValidPostcodeArea(java.lang.String s)L and LS are valid postcode areas.booleanisValidPostcodeDistrict(java.lang.String s)LS2 is a valid postcode district.booleanisValidPostcodeSector(java.lang.String s)LS2 9 is a valid postcode sector.booleanisValidPostcodeUnit(java.lang.String s)LS2 9JT is a valid unit postcode.booleanisValidSecondPartUnitPostcode(char[] spp)booleanisValidSecondPartUnitPostcodeOld(char[] spp)
-
Field Details
-
TYPE_AANN
public static final int TYPE_AANN- See Also:
- Constant Field Values
-
TYPE_AANA
public static final int TYPE_AANA- See Also:
- Constant Field Values
-
TYPE_ANN
public static final int TYPE_ANN- See Also:
- Constant Field Values
-
TYPE_ANA
public static final int TYPE_ANA- See Also:
- Constant Field Values
-
TYPE_AAN
public static final int TYPE_AAN- See Also:
- Constant Field Values
-
TYPE_AAA
public static final int TYPE_AAA- See Also:
- Constant Field Values
-
TYPE_AN
public static final int TYPE_AN- See Also:
- Constant Field Values
-
AtoZ
public static final char[] AtoZ -
AtoZ_not_CIKMOV
public static final char[] AtoZ_not_CIKMOV -
AtoZ_not_QVX
public static final char[] AtoZ_not_QVX -
AtoZ_not_IJZ
public static final char[] AtoZ_not_IJZ -
ABCDEFGHJKSTUW
public static final char[] ABCDEFGHJKSTUW -
ABEHMNPRVWXY
public static final char[] ABEHMNPRVWXY -
digits
public static final char[] digits
-
-
Constructor Details
-
UKPC_Checker
public UKPC_Checker()Creates a new UKPC_Checker.
-
-
Method Details
-
isValidPostcodeArea
public boolean isValidPostcodeArea(java.lang.String s)L and LS are valid postcode areas.- Parameters:
s- The String to test if it is in a valid postcode area form. It is assumed to have no white space and be in uppercase. If that is not the case useGeneric_Stringor equivalent to first format s.- Returns:
trueifshas a valid postcode area form.
-
isValidPostcodeDistrict
public boolean isValidPostcodeDistrict(java.lang.String s)LS2 is a valid postcode district.- Parameters:
s- The string to test if it is in a valid postcode area form.- Returns:
- True iff s has a valid postcode area form.
-
isValidPostcodeSector
public boolean isValidPostcodeSector(java.lang.String s)LS2 9 is a valid postcode sector.- Parameters:
s- The string to test if it is in a valid postcode sector form.- Returns:
- True iff s has a valid postcode sector form.
-
isValidPostcodeUnit
public boolean isValidPostcodeUnit(java.lang.String s)LS2 9JT is a valid unit postcode.- Parameters:
s- The string to test if it is in a valid unit postcode form. Is assumed to be uper case and contain no whhitespace.- Returns:
- True iff s has a valid unit postcode form.
-
getUnitPostcodeType
public int getUnitPostcodeType(java.lang.String s)- Parameters:
s- The postcode for which the form is returned. This may contain white-space.- Returns:
- an int which is: 0 if s is not a valid unit postcode and 1 to 7 inclusive if s is a valid unit postcode of the following forms: AANA NAA; ANN NAA; ANA NAA; AAN NAA; AN NAA.
-
getUnitPostcodeType
public int getUnitPostcodeType(java.lang.String s, int length)- Parameters:
s- A full unit postcode for which the form is returned. This is expected to have been stripped of all white-space.length- The length of postcode.- Returns:
- an int which is: 0 if the length is less than 5 or both the first and second parts of the the postcode are invalid; Completely valid postcodes return 2 to 7 inclusive. These are respectively of the form AANN NAA; AANA NAA; ANN NAA; ANA NAA; AAN NAA; AN NAA.
-
getPostcodeSectorType
public int getPostcodeSectorType(java.lang.String s, int length)- Parameters:
s- A postcode sector s for which the form is returned. This is expected to have been stripped of all whitespace.length- The length of postcode.- Returns:
- an int which is: 0 if the length is less than 4 or both the first and second parts of the the postcode are invalid; Completely valid postcode sectors return 2 to 7 inclusive. These are respectively of the form AANN N; AANA N; ANN N; ANA N; AAN N; AN N.
-
isValidSecondPartUnitPostcode
public boolean isValidSecondPartUnitPostcode(char[] spp)- Parameters:
spp- the second part of the postcode to test if it is a valid second part of a postcode for a unit postcode.- Returns:
- true if spp is of length 3 and where: spp[0] is in
digits; spp[1] is inAtoZ_not_CIKMOV; and, spp[1] is inAtoZ_not_CIKMOV.
-
isValidSecondPartUnitPostcodeOld
public boolean isValidSecondPartUnitPostcodeOld(char[] spp)- Parameters:
spp- the second part of the postcode to test if it is a valid second part of a postcode for a unit postcode.- Returns:
- true if spp is of length 3 and where: spp[0] is in
digits; spp[1] is inAtoZ_not_CIKMOV; and, spp[1] is inAtoZ_not_CIKMOV.
-
getFirstPartPostcodeType
public int getFirstPartPostcodeType(char[] fpp)- Parameters:
fpp- First Part of a Postcode.- Returns:
- Where A stands for an alphabetical character and N stands for digit: 0 if fpp is not a valid first part for a postcode; 1 if it is of the form AANN; 2 if it is of the form AANA; 3 if it is of the form ANN; 4 if it is of the form ANA; 5 if it is of the form AAN; 6 if it is of the form AAA; 7 if it is of the form AN.
-
contains
public boolean contains(char c, char[] a)- Parameters:
c- The char to test to see if it is in arraya- The array to test to see if it contains c.- Returns:
- true if c is in a and false otherwise.
-