Record Class PhoneNr

java.lang.Object
java.lang.Record
net.tangly.core.PhoneNr

public record PhoneNr(@NotNull String number) extends Record
Represents an immutable phone number as a canonical string. Validation and formatting of phone numbers are performed through the phone library of Google, which supports worldwide numbers.
  • Constructor Summary

    Constructors
    Constructor
    Description
    PhoneNr(@NotNull String number)
    Creates an instance of a PhoneNr record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    static boolean
    isValid(String number)
    Validates a phone number using the Google phone library.
    @NotNull String
    Returns the value of the number record component.
    static PhoneNr
    of(@NotNull String number)
    Factory method to of a new phone number.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PhoneNr

      public PhoneNr(@NotNull @NotNull String number)
      Creates an instance of a PhoneNr record class.
      Parameters:
      number - the value for the number record component
  • Method Details

    • of

      public static PhoneNr of(@NotNull @NotNull String number)
      Factory method to of a new phone number. The number is formatted based on the international format standard.
      Parameters:
      number - phone number in a raw format
      Returns:
      the newly created phone number if the raw format contained a number otherwise null
    • isValid

      public static boolean isValid(String number)
      Validates a phone number using the Google phone library.
      Parameters:
      number - phone number to validate
      Returns:
      true, if the phone number is valid otherwise false
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • number

      @NotNull public @NotNull String number()
      Returns the value of the number record component.
      Returns:
      the value of the number record component