Class EmailAddress
java.lang.Object
cloud.opencode.base.email.EmailAddress
- All Implemented Interfaces:
Comparable<EmailAddress>
Validated Email Address Value Type
经过验证的邮箱地址值类型
Immutable value object representing a validated email address.
表示经过验证的邮箱地址的不可变值对象。
Features | 主要功能:
- RFC 5321 email address validation - RFC 5321 邮箱地址验证
- Case-insensitive domain comparison - 域名部分大小写不敏感比较
- Fail-fast validation at creation - 创建时快速失败验证
Usage Examples | 使用示例:
EmailAddress addr = EmailAddress.of("user@example.com");
String local = addr.localPart(); // "user"
String domain = addr.domain(); // "example.com"
String full = addr.address(); // "user@example.com"
// Validation at creation
EmailAddress.of("invalid"); // throws EmailException
// Case-insensitive domain
EmailAddress.of("user@EXAMPLE.COM").equals(EmailAddress.of("user@example.com")); // true
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Null-safe: of() rejects null - 空值安全: of() 拒绝null
- Since:
- JDK 25, opencode-base-email V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaddress()Get the full email address 获取完整邮箱地址intcompareTo(EmailAddress other) domain()Get the domain part (after @, lowercased) 获取域名部分(@之后,已小写化)booleaninthashCode()static booleanCheck if a string is a valid email address 检查字符串是否是有效的邮箱地址Get the local part (before @) 获取本地部分(@之前)static EmailAddressCreate a validated EmailAddress from a string 从字符串创建经过验证的EmailAddresstoString()
-
Method Details
-
of
Create a validated EmailAddress from a string 从字符串创建经过验证的EmailAddress- Parameters:
address- the email address string | 邮箱地址字符串- Returns:
- the validated EmailAddress | 经过验证的EmailAddress
- Throws:
EmailException- if the address is invalid | 地址无效时抛出
-
isValid
Check if a string is a valid email address 检查字符串是否是有效的邮箱地址- Parameters:
address- the email address string | 邮箱地址字符串- Returns:
- true if valid | 有效返回true
-
address
-
localPart
-
domain
Get the domain part (after @, lowercased) 获取域名部分(@之后,已小写化)- Returns:
- the domain | 域名
-
compareTo
- Specified by:
compareToin interfaceComparable<EmailAddress>
-
equals
-
hashCode
-
toString
-