optional examples (#2537)
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package com.stackify.optional;
|
||||
|
||||
public class Address {
|
||||
private String addressLine;
|
||||
private String city;
|
||||
private Country country;
|
||||
|
||||
public Address(String addressLine, String city, Country country) {
|
||||
super();
|
||||
this.addressLine = addressLine;
|
||||
this.city = city;
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getAddressLine() {
|
||||
return addressLine;
|
||||
}
|
||||
|
||||
public void setAddressLine(String addressLine) {
|
||||
this.addressLine = addressLine;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public Country getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(Country country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.stackify.optional;
|
||||
|
||||
public class Country {
|
||||
private String name;
|
||||
private String isocode;
|
||||
|
||||
public Country(String name, String isocode) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.isocode = isocode;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getIsocode() {
|
||||
return isocode;
|
||||
}
|
||||
|
||||
public void setIsocode(String isocode) {
|
||||
this.isocode = isocode;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.stackify.optional;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class User {
|
||||
private String email;
|
||||
private String password;
|
||||
|
||||
private Address address;
|
||||
|
||||
private String position;
|
||||
|
||||
public User(String email, String password) {
|
||||
super();
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public Address getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(Address address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public Optional<String> getPosition() {
|
||||
return Optional.ofNullable(position);
|
||||
}
|
||||
|
||||
public void setPosition(String position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.stackify.optional.chaining;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class Address {
|
||||
private String addressLine;
|
||||
private String city;
|
||||
private Country country;
|
||||
|
||||
public Address(String addressLine, String city) {
|
||||
this.addressLine = addressLine;
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getAddressLine() {
|
||||
return addressLine;
|
||||
}
|
||||
|
||||
public void setAddressLine(String addressLine) {
|
||||
this.addressLine = addressLine;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public Optional<Country> getCountry() {
|
||||
return Optional.ofNullable(country);
|
||||
}
|
||||
|
||||
public void setCountry(Country country) {
|
||||
this.country = country;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.stackify.optional.chaining;
|
||||
|
||||
public class Country {
|
||||
private String name;
|
||||
private String isocode;
|
||||
|
||||
public Country(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getIsocode() {
|
||||
return isocode;
|
||||
}
|
||||
|
||||
public void setIsocode(String isocode) {
|
||||
this.isocode = isocode;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.stackify.optional.chaining;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class User {
|
||||
private String email;
|
||||
private String password;
|
||||
|
||||
private Address address;
|
||||
|
||||
private String position;
|
||||
|
||||
public User(String email, String password) {
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public Optional<Address> getAddress() {
|
||||
return Optional.ofNullable(address);
|
||||
}
|
||||
|
||||
public void setAddress(Address address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public Optional<String> getPosition() {
|
||||
return Optional.ofNullable(position);
|
||||
}
|
||||
|
||||
public void setPosition(String position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%msg%n" />
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="info">
|
||||
<AppenderRef ref="Console" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
Reference in New Issue
Block a user