Class UserId

java.lang.Object
org.pgpainless.key.util.UserId
All Implemented Interfaces:
CharSequence

public final class UserId extends Object implements CharSequence
  • Method Details

    • parse

      public static UserId parse(@Nonnull String string)
      Parse a UserId from free-form text,
      name-addr
      or
      mailbox
      string and split it up into its components. Example inputs for this method:
      • john@pgpainless.org
      • <john@pgpainless.org>
      • John Doe
      • John Doe <john@pgpainless.org>
      • John Doe (work email) <john@pgpainless.org>
      In these cases, this method will detect email addresses, names and comments and expose those via the respective getters. This method does not support parsing mail addresses of the following formats:
      • Local domains without TLDs (
        user@localdomain1
        )
      • " "@example.org
        (spaces between the quotes)
      • "very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com
      Note: This method does not guarantee that
      string.equals(UserId.parse(string).toString())
      is true. For example,
      UserId.parse("alice@pgpainless.org").toString()
      wraps the mail address in angled brackets.
      Parameters:
      string - user-id
      Returns:
      parsed UserId object
      See Also:
    • onlyEmail

      public static UserId onlyEmail(@Nonnull String email)
    • nameAndEmail

      public static UserId nameAndEmail(@Nonnull String name, @Nonnull String email)
    • newBuilder

      public static UserId.Builder newBuilder()
    • toBuilder

      public UserId.Builder toBuilder()
    • getName

      public String getName()
    • getName

      public String getName(boolean preserveQuotes)
    • getComment

      public String getComment()
    • getEmail

      public String getEmail()
    • length

      public int length()
      Specified by:
      length in interface CharSequence
    • charAt

      public char charAt(int i)
      Specified by:
      charAt in interface CharSequence
    • subSequence

      @Nonnull public CharSequence subSequence(int i, int i1)
      Specified by:
      subSequence in interface CharSequence
    • toString

      @Nonnull public String toString()
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object
    • asString

      @Deprecated public String asString()
      Deprecated.
      use toString() instead.
      Returns a string representation of the object.
      Returns:
      a string representation of the object.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

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

      public static int compare(@Nullable UserId o1, @Nullable UserId o2, @Nonnull Comparator<UserId> comparator)