OBJ - The type of object.public class OptionalObject<OBJ> extends BaseOptional<OBJ>
| 修飾子とタイプ | フィールドと説明 |
|---|---|
protected static OptionalObject<Object> |
EMPTY_INSTANCE |
protected static OptionalThingExceptionThrower |
NOWAY_THROWER |
_obj, _thrower, IF_PRESENT_AFTER_EMPTY, IF_PRESENT_AFTER_NONE_FIRE| コンストラクタと説明 |
|---|
OptionalObject(OBJ thing,
OptionalThingExceptionThrower thrower) |
| 修飾子とタイプ | メソッドと説明 |
|---|---|
void |
alwaysPresent(OptionalThingConsumer<? super OBJ> oneArgLambda)
Handle the thing in the optional thing or (detail message) exception if not present.
|
protected <ARG> OptionalObject<ARG> |
createOptionalFilteredObject(ARG obj) |
protected <ARG> OptionalObject<ARG> |
createOptionalFlatMappedObject(ARG obj) |
protected <ARG> OptionalObject<ARG> |
createOptionalMappedObject(ARG obj) |
static <EMPTY> OptionalObject<EMPTY> |
empty() |
OptionalObject<OBJ> |
filter(OptionalThingPredicate<? super OBJ> oneArgLambda)
Filter the thing by the predicate.
|
<RESULT> OptionalThing<RESULT> |
flatMap(OptionalThingFunction<? super OBJ,OptionalThing<RESULT>> oneArgLambda)
Apply the flat-mapping of thing to result thing.
|
OBJ |
get()
Get the thing or (detail message) exception if not present.
|
OptionalThingIfPresentAfter |
ifPresent(OptionalThingConsumer<? super OBJ> oneArgLambda)
Handle the wrapped thing if it is present.
|
void |
ifPresentOrElse(OptionalThingConsumer<? super OBJ> oneArgLambda,
IndependentProcessor noArgLambda)
Handle the wrapped thing if it is both present and empty.
|
boolean |
isEmpty()
Is the object instance empty?
|
boolean |
isPresent()
Is the object instance present?
|
<RESULT> OptionalThing<RESULT> |
map(OptionalThingFunction<? super OBJ,? extends RESULT> oneArgLambda)
Apply the mapping of thing to result thing.
|
static <OBJ> OptionalObject<OBJ> |
of(OBJ object) |
static <OBJ> OptionalObject<OBJ> |
ofNullable(OBJ object,
OptionalThingExceptionThrower noArgLambda) |
OptionalThing<OBJ> |
or(OptionalThingSupplier<? extends OptionalThing<? extends OBJ>> noArgLambda)
Switch this to other optional if not present.
|
OBJ |
orElse(OBJ other)
Get the wrapped instance or returns the specified thing.
|
OBJ |
orElseGet(OptionalThingSupplier<? extends OBJ> noArgLambda)
Get the thing or get from the supplier.
|
OBJ |
orElseThrow()
Get the thing or throw the embedded exception.
|
<CAUSE extends Throwable> |
orElseThrow(OptionalThingSupplier<? extends CAUSE> noArgLambda)
Get the thing or throw the exception.
|
<CAUSE extends Throwable,TRANSLATED extends Throwable> |
orElseTranslatingThrow(OptionalThingFunction<CAUSE,TRANSLATED> causeLambda)
Get the thing or throw the exception with translating the cause.
|
Stream<OBJ> |
stream()
Handle the optional thing as stream.
|
assertCauseLambdaNotNull, assertNoArgLambdaNotNull, assertOneArgLambdaNotNull, callbackAlwaysPresent, callbackFilter, callbackFlatMapping, callbackGetOrElseGet, callbackGetOrElseThrow, callbackGetOrElseTranslatingThrow, callbackIfPresent, callbackIfPresentOrElse, callbackMapping, callbackOr, convertToStream, determineEmpty, determinePresent, directlyGet, directlyGetOrElse, equals, exists, hashCode, toOptional, toStringmigratedFrom, translatedFromprotected static final OptionalObject<Object> EMPTY_INSTANCE
protected static final OptionalThingExceptionThrower NOWAY_THROWER
public OptionalObject(OBJ thing, OptionalThingExceptionThrower thrower)
thing - The wrapped instance of thing. (NullAllowed)thrower - The exception thrower when illegal access. (NotNull)public static <EMPTY> OptionalObject<EMPTY> empty()
EMPTY - The type of empty optional object.public static <OBJ> OptionalObject<OBJ> of(OBJ object)
OBJ - The type of object wrapped in the optional object.object - The wrapped thing which is optional. (NotNull)public static <OBJ> OptionalObject<OBJ> ofNullable(OBJ object, OptionalThingExceptionThrower noArgLambda)
OBJ - The type of object wrapped in the optional object.object - The wrapped instance or thing. (NullAllowed)noArgLambda - The callback for exception when illegal access. (NotNull)public OptionalThingIfPresentAfter ifPresent(OptionalThingConsumer<? super OBJ> oneArgLambda)
oneArgLambda - The callback interface to consume the optional thing. (NotNull)public void ifPresentOrElse(OptionalThingConsumer<? super OBJ> oneArgLambda, IndependentProcessor noArgLambda)
oneArgLambda - The present-case callback interface to consume the optional thing. (NotNull)noArgLambda - The empty-case callback interface to handle or-else. (NotNull)public boolean isPresent()
public boolean isEmpty()
public OBJ get()
public OptionalThing<OBJ> or(OptionalThingSupplier<? extends OptionalThing<? extends OBJ>> noArgLambda)
noArgLambda - The supplier of other optional if not present. (NotNull)public OBJ orElse(OBJ other)
other - The object instance to be returned when the optional is empty. (NullAllowed)public OBJ orElseGet(OptionalThingSupplier<? extends OBJ> noArgLambda)
noArgLambda - The supplier of other instance if not present. (NotNull)public OBJ orElseThrow()
public <CAUSE extends Throwable> OBJ orElseThrow(OptionalThingSupplier<? extends CAUSE> noArgLambda) throws CAUSE extends Throwable
CAUSE - The type of cause.noArgLambda - The supplier of exception if not present. (NotNull)CAUSE - When the value is null.CAUSE extends Throwablepublic <CAUSE extends Throwable,TRANSLATED extends Throwable> OBJ orElseTranslatingThrow(OptionalThingFunction<CAUSE,TRANSLATED> causeLambda) throws TRANSLATED extends Throwable
OptionalThing<String> optSea = ... String sea = optSea.orElseTranslatingThrow(cause -> { return new YourBusinessException("...", cause); // you can wrap the detail exception }
CAUSE - The type of original cause.TRANSLATED - The type of translated cause.causeLambda - The translator function of cause exception if not present, returning your exception. (NotNull)TRANSLATED - When the value is null.TRANSLATED extends Throwablepublic OptionalObject<OBJ> filter(OptionalThingPredicate<? super OBJ> oneArgLambda)
oneArgLambda - The callback to predicate whether the object is remained. (NotNull)protected <ARG> OptionalObject<ARG> createOptionalFilteredObject(ARG obj)
createOptionalFilteredObject クラス内 BaseOptional<OBJ>ARG - The type of value for optional thing.obj - The plain object for the optional thing. (NullAllowed: if null, returns empty optional)public <RESULT> OptionalThing<RESULT> map(OptionalThingFunction<? super OBJ,? extends RESULT> oneArgLambda)
RESULT - The type of mapping result.oneArgLambda - The callback interface to apply, null return allowed as empty. (NotNull)protected <ARG> OptionalObject<ARG> createOptionalMappedObject(ARG obj)
createOptionalMappedObject クラス内 BaseOptional<OBJ>ARG - The type of value for optional thing.obj - The plain object for the optional thing. (NullAllowed: if null, returns empty optional)public <RESULT> OptionalThing<RESULT> flatMap(OptionalThingFunction<? super OBJ,OptionalThing<RESULT>> oneArgLambda)
RESULT - The type of mapping result.oneArgLambda - The callback interface to apply, cannot return null. (NotNull)protected <ARG> OptionalObject<ARG> createOptionalFlatMappedObject(ARG obj)
createOptionalFlatMappedObject クラス内 BaseOptional<OBJ>ARG - The type of value for optional thing.obj - The plain object for the optional thing. (NullAllowed: if null, returns empty optional)public Stream<OBJ> stream()
public void alwaysPresent(OptionalThingConsumer<? super OBJ> oneArgLambda)
memberBhv.selectEntity(cb -> { cb.setupSelect_MemberStatus(); cb.query().setMemberId_Equal(1); }).alwaysPresent(member -> { // called if value exists, or exception ... = member.getMemberName(); member.getMemberStatus().alwaysPresent(status -> { // also relationship ... = status.getMemberStatusName(); }); });
oneArgLambda - The callback interface to consume the optional thing. (NotNull)Copyright © 2014–2021 The DBFlute Project. All rights reserved.