ENTITY - The type of entity.public class OptionalEntity<ENTITY> extends BaseOptional<ENTITY>
// if the data always exists as your business rule memberBhv.selectEntity(cb -> { cb.setupSelect_MemberStatus(); cb.query().setMemberId_Equal(1); }).alwaysPresent(member -> { // called if present, or exception ... = member.getMemberName(); }); // if it might be no data, ... memberBhv.selectEntity(cb -> cb.acceptPK(1)).ifPresent(member -> { // called if present ... = member.getMemberName(); }).orElse(() -> { // called if not present });
| 修飾子とタイプ | フィールドと説明 |
|---|---|
protected static OptionalEntity<Object> |
EMPTY_INSTANCE |
protected static OptionalThingExceptionThrower |
NOWAY_THROWER |
_obj, _thrower, IF_PRESENT_AFTER_EMPTY, IF_PRESENT_AFTER_NONE_FIRE| コンストラクタと説明 |
|---|
OptionalEntity(ENTITY entity,
OptionalThingExceptionThrower thrower) |
| 修飾子とタイプ | メソッドと説明 |
|---|---|
void |
alwaysPresent(OptionalThingConsumer<? super ENTITY> entityLambda)
Handle the entity in the optional object or exception if not present.
|
protected void |
assertEntityLambdaNotNull(Object entityLambda) |
protected <ARG> OptionalEntity<ARG> |
createOptionalFilteredObject(ARG obj) |
protected <ARG> OptionalEntity<ARG> |
createOptionalFlatMappedObject(ARG obj) |
protected <ARG> OptionalEntity<ARG> |
createOptionalMappedObject(ARG obj) |
static <EMPTY> OptionalEntity<EMPTY> |
empty() |
OptionalEntity<ENTITY> |
filter(OptionalThingPredicate<? super ENTITY> entityLambda)
Filter the entity by the predicate.
|
<RESULT> OptionalThing<RESULT> |
flatMap(OptionalThingFunction<? super ENTITY,OptionalThing<RESULT>> entityLambda)
Apply the flat-mapping of entity to result object.
|
ENTITY |
get()
Get the entity or (detail-message) exception if not present.
|
OptionalThingIfPresentAfter |
ifPresent(OptionalThingConsumer<? super ENTITY> entityLambda)
Handle the wrapped entity if it is present.
|
void |
ifPresentOrElse(OptionalThingConsumer<? super ENTITY> entityLambda,
IndependentProcessor noArgLambda)
Handle the wrapped thing if it is both present and empty.
|
boolean |
isEmpty()
Is the entity instance empty?
|
boolean |
isPresent()
Is the entity instance present?
|
<RESULT> OptionalEntity<RESULT> |
map(OptionalThingFunction<? super ENTITY,? extends RESULT> entityLambda)
Apply the mapping of entity to result object.
|
static <ENTITY> OptionalEntity<ENTITY> |
of(ENTITY entity) |
static <ENTITY> OptionalEntity<ENTITY> |
ofNullable(ENTITY entity,
OptionalThingExceptionThrower noArgLambda) |
OptionalThing<ENTITY> |
or(OptionalThingSupplier<? extends OptionalThing<? extends ENTITY>> noArgLambda)
Switch this to other optional if not present.
|
ENTITY |
orElse(ENTITY other)
Get the wrapped instance or returns the specified thing.
|
ENTITY |
orElseGet(OptionalThingSupplier<? extends ENTITY> noArgLambda)
Get the thing or get from the supplier.
|
ENTITY |
orElseThrow()
Get the entity or (detail-message) exception if not present.
|
<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.
|
static <EMPTY> OptionalEntity<EMPTY> |
relationEmpty(Object entity,
String relation) |
Stream<ENTITY> |
stream()
Handle the optional thing as stream.
|
protected static void |
throwNonSetupSelectRelationAccessException(Object entity,
String relation) |
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 OptionalEntity<Object> EMPTY_INSTANCE
protected static final OptionalThingExceptionThrower NOWAY_THROWER
public OptionalEntity(ENTITY entity, OptionalThingExceptionThrower thrower)
entity - The wrapped instance of entity. (NullAllowed)thrower - The exception thrower when illegal access. (NotNull)public static <EMPTY> OptionalEntity<EMPTY> empty()
EMPTY - The type of empty optional entity.public static <ENTITY> OptionalEntity<ENTITY> of(ENTITY entity)
ENTITY - The type of entity wrapped in the optional entity.entity - The wrapped entity for the optional object. (NotNull)public static <ENTITY> OptionalEntity<ENTITY> ofNullable(ENTITY entity, OptionalThingExceptionThrower noArgLambda)
ENTITY - The type of entity for the optional type.entity - The wrapped instance or entity. (NullAllowed)noArgLambda - The exception thrower when illegal access. (NotNull)public static <EMPTY> OptionalEntity<EMPTY> relationEmpty(Object entity, String relation)
EMPTY - The type of empty optional entity.entity - The base entity of the relation for exception message. (NotNull)relation - The property name of the relation for exception message. (NotNull)protected static void throwNonSetupSelectRelationAccessException(Object entity, String relation)
public OptionalThingIfPresentAfter ifPresent(OptionalThingConsumer<? super ENTITY> entityLambda)
memberBhv.selectEntity(cb -> { cb.setupSelect_MemberWithdrawal(); cb.query().setMemberId_Equal(1); }).ifPresent(member -> { // called if value exists, or not called ... = member.getMemberName(); member.getMemberWithdrawal().ifPresent(withdrawal -> { // also relation ... = withdrawal.getWithdrawalDatetime(); }); }).orElse(() -> { // called if no value });
entityLambda - The callback interface to consume the optional entity. (NotNull)public void ifPresentOrElse(OptionalThingConsumer<? super ENTITY> entityLambda, IndependentProcessor noArgLambda)
entityLambda - 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()
OptionalEntity<Member> optMember = memberBhv.selectEntity(cb -> { cb.query()...; }); if (optMember.isPresent()) { // true if the entity exists Member member = optMember.get(); } else { ... }
public boolean isEmpty()
OptionalEntity<Member> optMember = memberBhv.selectEntity(cb -> { cb.query()...; }); if (optMember.isEmpty()) { // true if the entity does not exist ... } else { // present here Member member = optMember.get(); }
public ENTITY get()
OptionalEntity<Member> optMember = memberBhv.selectEntity(cb -> { cb.setupSelect_MemberStatus(); cb.query().setMemberId_Equal(1); }); // if the data always exists as your business rule Member member = optMember.get(); // if it might be no data, isPresent(), orElse(), ... if (optMember.isPresent()) { Member member = optMember.get(); } else { ... }
EntityAlreadyDeletedException - When the entity instance wrapped in this optional object is null, which means entity has already been deleted (point is not found).public OptionalThing<ENTITY> or(OptionalThingSupplier<? extends OptionalThing<? extends ENTITY>> noArgLambda)
noArgLambda - The supplier of other optional if not present. (NotNull)public ENTITY orElse(ENTITY other)
other - The object instance to be returned when the optional is empty. (NullAllowed)public ENTITY orElseGet(OptionalThingSupplier<? extends ENTITY> noArgLambda)
noArgLambda - The supplier of other instance if not present. (NotNull)public ENTITY orElseThrow()
OptionalEntity<Member> optMember = memberBhv.selectEntity(cb -> { cb.setupSelect_MemberStatus(); cb.query().setMemberId_Equal(1); }); // if the data always exists as your business rule Member member = optMember.orElseThrow();
EntityAlreadyDeletedException - When the entity instance wrapped in this optional object is null, which means entity has already been deleted (point is not found).public <CAUSE extends Throwable> ENTITY 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> ENTITY 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 OptionalEntity<ENTITY> filter(OptionalThingPredicate<? super ENTITY> entityLambda)
memberBhv.selectEntity(cb -> cb.acceptPK(1)).filter(member -> { // called if value exists, not called if not present return member.getMemberId() % 2 == 0; }).ifPresent(member -> { ... });
entityLambda - The callback to predicate whether the entity is remained. (NotNull)protected <ARG> OptionalEntity<ARG> createOptionalFilteredObject(ARG obj)
createOptionalFilteredObject クラス内 BaseOptional<ENTITY>ARG - The type of value for optional thing.obj - The plain object for the optional thing. (NullAllowed: if null, returns empty optional)public <RESULT> OptionalEntity<RESULT> map(OptionalThingFunction<? super ENTITY,? extends RESULT> entityLambda)
memberBhv.selectEntity(cb -> cb.acceptPK(1)).map(member -> { // called if value exists, not called if not present return new MemberWebBean(member); }).alwaysPresent(member -> { ... });
RESULT - The type of mapping result.entityLambda - The callback interface to apply, null return allowed as empty. (NotNull)protected <ARG> OptionalEntity<ARG> createOptionalMappedObject(ARG obj)
createOptionalMappedObject クラス内 BaseOptional<ENTITY>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 ENTITY,OptionalThing<RESULT>> entityLambda)
memberBhv.selectEntity(cb -> cb.acceptPK(1)).flatMap(member -> { // called if value exists, not called if not present return member.getMemberWithdrawal(); }).ifPresent(withdrawal -> { ... });
RESULT - The type of mapping result.entityLambda - The callback interface to apply, cannot return null. (NotNull)protected <ARG> OptionalEntity<ARG> createOptionalFlatMappedObject(ARG obj)
createOptionalFlatMappedObject クラス内 BaseOptional<ENTITY>ARG - The type of value for optional thing.obj - The plain object for the optional thing. (NullAllowed: if null, returns empty optional)public Stream<ENTITY> stream()
public void alwaysPresent(OptionalThingConsumer<? super ENTITY> entityLambda)
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(); }); });
entityLambda - The callback interface to consume the optional value. (NotNull)EntityAlreadyDeletedException - When the entity instance wrapped in this optional object is null, which means entity has already been deleted (point is not found).protected void assertEntityLambdaNotNull(Object entityLambda)
Copyright © 2014–2021 The DBFlute Project. All rights reserved.