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<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<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 exception if null.
|
OptionalThingIfPresentAfter |
ifPresent(OptionalThingConsumer<ENTITY> entityLambda)
Handle the wrapped entity if it is present.
|
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) |
ENTITY |
orElse(ENTITY other)
Get the wrapped instance or returns the specified thing.
|
ENTITY |
orElseGet(OptionalThingSupplier<ENTITY> noArgLambda)
Get the thing or get from the supplier.
|
ENTITY |
orElseNull()
非推奨です。
basically use ifPresent() or use orElse(null)
|
<CAUSE extends Throwable> |
orElseThrow(OptionalThingSupplier<? extends CAUSE> noArgLambda)
Get the thing or throw the exception.
|
static <EMPTY> OptionalEntity<EMPTY> |
relationEmpty(Object entity,
String relation) |
protected static void |
throwNonSetupSelectRelationAccessException(Object entity,
String relation) |
callbackAlwaysPresent, callbackFilter, callbackFlatMapping, callbackIfPresent, callbackMapping, directlyGet, directlyGetOrElse, directlyGetOrElseGet, directlyGetOrElseThrow, equals, exists, hashCode, toOptional, toStringprotected 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<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 boolean isPresent()
OptionalEntity<Member> optMember = memberBhv.selectEntity(cb -> { cb.query()...; }); if (optMember.isPresent()) { // true if the entity exists Member member = optMember.get(); } else { ... }
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 OptionalEntity<ENTITY> filter(OptionalThingPredicate<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, return s 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, return s 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, return s empty optional)public ENTITY orElse(ENTITY other)
other - The object instance to be returned when the optional is empty. (NullAllowed)public ENTITY orElseGet(OptionalThingSupplier<ENTITY> noArgLambda)
noArgLambda - The supplier of other instance if null. (NotNull)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 null. (NotNull)CAUSE - When the value is null.CAUSE extends Throwablepublic void alwaysPresent(OptionalThingConsumer<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 relation ... = 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).public ENTITY orElseNull()
protected void assertEntityLambdaNotNull(Object entityLambda)
Copyright © 2014–2015 The DBFlute Project. All rights reserved.