添加注释。

feature/net-util
ZhouXY108 2023-05-13 13:16:14 +08:00
parent 0067fce7af
commit 14d7a53147
1 changed files with 57 additions and 0 deletions

View File

@ -38,26 +38,83 @@ import javax.annotation.Nullable;
*/
public class OptionalUtil {
/**
* {@link Integer} {@link OptionalInt}not null
* <p>
* {@code null} {@link OptionalInt}
* {@link OptionalInt#empty()}
* </p>
*
* @param value
* @return {@link OptionalInt}
*/
public static OptionalInt optionalOf(@Nullable Integer value) {
return value != null ? OptionalInt.of(value) : OptionalInt.empty();
}
/**
* {@code Optional<Integer>} {@link OptionalInt}
* <p>
* {@code Optional<Integer>} 使 {@link OptionalInt}
* </p>
*
* @param value
* @return {@link OptionalInt}
*/
public static OptionalInt toOptionalInt(Optional<Integer> objectOptional) {
return optionalOf(objectOptional.orElse(null));
}
/**
* {@link Long} {@link OptionalLong}not null
* <p>
* {@code null} {@link OptionalLong}
* {@link OptionalLong#empty()}
* </p>
*
* @param value
* @return {@link OptionalLong}
*/
public static OptionalLong optionalOf(@Nullable Long value) {
return value != null ? OptionalLong.of(value) : OptionalLong.empty();
}
/**
* {@code Optional<Long>} {@link OptionalLong}
* <p>
* {@code Optional<Long>} 使 {@link OptionalLong}
* </p>
*
* @param value
* @return {@link OptionalLong}
*/
public static OptionalLong toOptionalLong(Optional<Long> objectOptional) {
return optionalOf(objectOptional.orElse(null));
}
/**
* {@link Double} {@link OptionalDouble}not null
* <p>
* {@code null} {@link OptionalDouble}
* {@link OptionalDouble#empty()}
* </p>
*
* @param value
* @return {@link OptionalDouble}
*/
public static OptionalDouble optionalOf(@Nullable Double value) {
return value != null ? OptionalDouble.of(value) : OptionalDouble.empty();
}
/**
* {@code Optional<Double>} {@link OptionalDouble}
* <p>
* {@code Optional<Double>} 使 {@link OptionalDouble}
* </p>
*
* @param value
* @return {@link OptionalDouble}
*/
public static OptionalDouble toOptionalDouble(Optional<Double> objectOptional) {
return optionalOf(objectOptional.orElse(null));
}