You can replace orElseThrow () with orElseGet () to call your VisualMessage method and return 0. 0 if no value is found.