refactor: retrieving value with Optional
This commit is contained in:
1 file changed
+5
-1
+5
-1
@@ -4,6 +4,8 @@ import com.onixbyte.deltaforceguide.enumeration.ModificationStatus;
|
|||||||
import jakarta.persistence.AttributeConverter;
|
import jakarta.persistence.AttributeConverter;
|
||||||
import jakarta.persistence.Converter;
|
import jakarta.persistence.Converter;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JPA attribute converter that maps {@link ModificationStatus} enum to/from its integer database representation.
|
* JPA attribute converter that maps {@link ModificationStatus} enum to/from its integer database representation.
|
||||||
*
|
*
|
||||||
@@ -14,7 +16,9 @@ public class ModificationStatusConverter implements AttributeConverter<Modificat
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer convertToDatabaseColumn(ModificationStatus attribute) {
|
public Integer convertToDatabaseColumn(ModificationStatus attribute) {
|
||||||
return attribute == null ? null : attribute.getCode();
|
return Optional.ofNullable(attribute)
|
||||||
|
.map(ModificationStatus::getCode)
|
||||||
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in new issue
Block a user