Class Years
java.lang.Object
cloud.opencode.base.date.extra.Years
- All Implemented Interfaces:
Serializable, Comparable<Years>, TemporalAmount
Years unit class representing a number of years
年数单位类,表示年数
This class represents a number of years, similar to Period but focused on the years unit. It implements TemporalAmount for use with java.time.
此类表示年数,类似于Period但专注于年单位。实现TemporalAmount以与java.time配合使用。
Features | 主要功能:
- Type-safe years representation - 类型安全的年数表示
- Arithmetic operations (plus, minus, multiply, divide) - 算术操作(加、减、乘、除)
- Conversion to Period, Months - 转换为Period、Months
- TemporalAmount implementation for java.time integration - 实现TemporalAmount以集成java.time
Usage Examples | 使用示例:
Years y = Years.of(5);
Months m = y.toMonths(); // 60 months
Period p = y.toPeriod();
LocalDate date = LocalDate.now().plus(y);
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Overflow-safe: Yes (uses Math.addExact/multiplyExact) - 溢出安全: 是(使用Math.addExact/multiplyExact)
- Since:
- JDK 25, opencode-base-date V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionabs()static YearsintdividedBy(int divisor) booleanstatic Yearslongget(TemporalUnit unit) intgetUnits()inthashCode()booleanisLeap()booleanbooleanbooleanisZero()minus(int yearsToSubtract) multipliedBy(int multiplicand) negated()static Yearsof(int years) static Yearsof(long years) plus(int yearsToAdd) subtractFrom(Temporal temporal) toMonths()toPeriod()toString()
-
Field Details
-
ZERO
-
ONE
-
-
Method Details
-
of
-
of
-
from
-
between
-
getAmount
public int getAmount() -
isZero
public boolean isZero() -
isNegative
public boolean isNegative() -
isPositive
public boolean isPositive() -
isLeap
public boolean isLeap() -
plus
-
plus
-
minus
-
minus
-
multipliedBy
-
dividedBy
-
negated
-
abs
-
toPeriod
-
toMonths
-
get
- Specified by:
getin interfaceTemporalAmount
-
getUnits
- Specified by:
getUnitsin interfaceTemporalAmount
-
addTo
- Specified by:
addToin interfaceTemporalAmount
-
subtractFrom
- Specified by:
subtractFromin interfaceTemporalAmount
-
compareTo
- Specified by:
compareToin interfaceComparable<Years>
-
equals
-
hashCode
-
toString
-