Class UKPC_Checker

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 Details

  • 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 use Generic_String or equivalent to first format s.
      Returns:
      true if s has 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 in AtoZ_not_CIKMOV; and, spp[1] is in AtoZ_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 in AtoZ_not_CIKMOV; and, spp[1] is in AtoZ_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 array
      a - The array to test to see if it contains c.
      Returns:
      true if c is in a and false otherwise.