This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void settingThings(Address address, AddressDTO addressDTO) { | |
| Optional.ofNullable(addressDTO.getDescription()).ifPresent(address::setDescription); | |
| Optional.ofNullable(addressDTO.getStreet()).ifPresent(address::setStreet); | |
| Optional.ofNullable(addressDTO.getZip()).ifPresent(address::setZip); | |
| Optional.ofNullable(addressDTO.getCity()).ifPresent(address::setCity); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test | |
| public String gettingDeskOwnerPrettyWay(School school) { | |
| return Optional.ofNullable(school) | |
| .map(School::getClassroom) | |
| .map(Classroom::getDesk) | |
| .map(Desk::getOwner) | |
| .map(User::getName) | |
| .orElse(""); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test | |
| public String gettingDeskOwnerUglyWay(School school) { | |
| if (school.getClassroom() != null) { | |
| Classroom classroom = school.getClassroom(); | |
| if (classroom.getDesk() != null) { | |
| Desk desk = classroom.getDesk(); | |
| if (desk.getOwner() != null) { | |
| User owner = desk.getOwner(); | |
| if (owner != null) | |
| return owner.getName(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test | |
| public void OptionalIfElse() { | |
| String cat = new String("Cat without a tail"); | |
| String dog = null; | |
| Optional.ofNullable(cat).ifPresentOrElse(c -> System.out.println(cat), () -> System.out.println("No cat.")); | |
| Optional.ofNullable(dog).ifPresentOrElse(c -> System.out.println(dog), () -> System.out.println("No dog.")); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if(Optional.of(something).isPresent()) | |
| { | |
| doSomething(); | |
| } | |
| else | |
| { | |
| doSometingElse(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| class SnakeSequenceFactory : MonoBehaviour | |
| { | |
| public static GameObject headPrefab = (GameObject) Resources.Load("HeadPrefab"); | |
| public static GameObject bodyPrefab = (GameObject) Resources.Load("BodyPrefab"); | |
| public static GameObject tailPrefab = (GameObject) Resources.Load("TailPrefab"); | |
| public static GameObject createHeadController(Vector2 position) { | |
| return Instantiate(headPrefab, position, Quaternion.identity); |
NewerOlder