Package org.pgpainless.key.util

# Class UserId

java.lang.Object
org.pgpainless.key.util.UserId

All Implemented Interfaces:
  `CharSequence`

public final class UserId extends Object implements CharSequence

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static final class`
`UserId.Builder`
`static class`
`UserId.DefaultComparator`
`static class`
`UserId.DefaultIgnoreCaseComparator`

## Method Summary

Modifier and Type
Method
Description
`String`
`asString()`
Deprecated.
use `toString()` instead.
`char`
`charAt(int i)`
`static int`
`compare(UserId o1, UserId o2, Comparator<UserId> comparator)`
`boolean`
`equals(Object o)`
`String`
`getComment()`
`String`
`getEmail()`
`String`
`getName()`
`String`
`getName(boolean preserveQuotes)`
`int`
`hashCode()`
`int`
`length()`
`static UserId`
`nameAndEmail(String name, String email)`
`static UserId.Builder`
`newBuilder()`
`static UserId`
`onlyEmail(String email)`
`static UserId`
`parse(String string)`
Parse a `UserId` from free-form text,
`CharSequence`
`subSequence(int i, int i1)`
`UserId.Builder`
`toBuilder()`
`String`
`toString()`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.lang.CharSequence

`chars, codePoints, isEmpty`

## 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:
  - RFC5322 §3.4. Address Specification

### 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)