Class PersonalIdentityNumber

java.lang.Object
se.swedenconnect.bankid.rpapi.support.PersonalIdentityNumber
All Implemented Interfaces:
Serializable

public class PersonalIdentityNumber extends Object implements Serializable
A representation of a Swedish personal identity number. Also handles "samordningsnummer".
Author:
Martin Lindström
See Also:
  • Constructor Details

    • PersonalIdentityNumber

      public PersonalIdentityNumber(String number) throws PersonalIdentityNumberException
      Constructor that parses the supplied personal identity number.

      The following formats are supported:

      • 12 digits with no delimiter, e.g. "196904146856".
      • 12 digits with a delimiter, e.g. "19690414-6856".
      • 10 digits with no delimiter, e.g. "6904146856". In these cases the person is assumed to be under 100 years old.
      • 10 digits with a delimiter, e.g. "690414-6856". The year the person is 100 years old, the delimiter changes to '+'.
      Parameters:
      number - the string representation of the personal identity number
      Throws:
      PersonalIdentityNumberException - if the supplied number is not valid
  • Method Details

    • parse

      public static PersonalIdentityNumber parse(String number) throws PersonalIdentityNumberException
      Parses a personal identity number string into a PersonalIdentityNumber. See PersonalIdentityNumber(String).
      Parameters:
      number - the string representation of the personal identity number
      Returns:
      a PersonalIdentityNumber object
      Throws:
      PersonalIdentityNumberException - if the supplied number is not valid
    • getNumber

      public String getNumber()
      Returns the personal identity number according to the PersonalIdentityNumber.Format.TWELVE_DIGITS_NO_DELIMITER format.
      Returns:
      the personal identity number as twelve digits with no delimiter
    • getNumber

      public String getNumber(PersonalIdentityNumber.Format format)
      Returns the personal identity number according to the required format.
      Parameters:
      format - the required format for the personal identity number string
      Returns:
      personal identity number string
    • isSamordningsnummer

      public boolean isSamordningsnummer()
      Predicate that returns true if this is a "samordningsnummer".

      See https://www.skatteverket.se/foretagochorganisationer/myndigheter/informationsutbytemellanmyndigheter/folkbokforingsamordningsnummer.4.46ae6b26141980f1e2d3643.html.

      Returns:
      true if this is a "samordningsnummer" and false otherwise
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object