concept insurance company in category java

appears as: insurce company, n insurance company, An insurce company, insurce company, insurce companies
Modern Java in Action: Lambdas, streams, reactive and functional programming

This is an excerpt from Manning's book Modern Java in Action: Lambdas, streams, reactive and functional programming.

This method performs a null check every time it dereferences a variable, returning the string "Unknown" if any of the variables traversed in this dereferencing chain is a null value. The only exception to this rule is that you’re not checking to see whether the name of the insurance company is null because (like any other company) you know it must have a name. Note that you can avoid this last check only because of your knowledge of the business domain, but that fact isn’t reflected in the Java classes modeling your data.

At this point the resulting optional will be empty if any of the methods in this invocation chain returns an empty optional or otherwise contains the desired insurance company name. How do you read that value? After all, you’ll end up getting an Optional<String> that may or may not contain the name of the insurance company. In listing 11.5, we used another method called orElse, which provides a default value in case the optional is empty. Many methods provide default actions or unwrap an optional. In the next section, we look at those methods in detail.

Java 8 in Action: Lambdas, streams, and functional-style programming

This is an excerpt from Manning's book Java 8 in Action: Lambdas, streams, and functional-style programming.

This method performs a null check every time it dereferences a variable, returning the string “Unknown” if any of the variables traversed in this dereferencing chain is a null value. The only exception to this is that you’re not checking to see if the name of the insurance company is null because, like any other company, you know it must have a name. Note that you can avoid this last check only because of your knowledge of the business domain, but that isn’t reflected in the Java classes modeling your data.

Listing 10.4. Redefining the Person/Car/Insurance data model using Optional
public class Person { private Optional<Car> car; #1 public Optional<Car> getCar() { return car; } } public class Car { private Optional<Insurance> insurance; #2 public Optional<Insurance> getInsurance() { return insurance; } } public class Insurance { private String name; #3 public String getName() { return name; } } #1: A person might or might not own a car, so you declare this field Optional. #2: A car might or might not be insured, so you declare this field Optional. #3: An insurance company must have a name.

At this point the resulting optional will be empty if any of the methods in this invocation chain returns an empty optional or will contain the desired insurance company name otherwise. So how do you read that value? After all, you’ll end up getting an Optional<String> that may or may not contain the name of the insurance company. In listing 10.5, we used another method called orElse, which provides a default value in case the optional is empty. There are many methods to provide default actions or unwrap an optional. Let’s look at them in more detail.