From 175c3f5182ad68e525f4c2a8560249065390b6b7 Mon Sep 17 00:00:00 2001 From: TopMass99 Date: Sat, 26 Apr 2025 21:32:57 -0400 Subject: [PATCH] adds to null-objects --- .../java/com/iluwatar/datamapper/Student.java | 5 +++ .../com/iluwatar/leaderfollowers/App.java | 24 ++++++++++ null-objects/EnrolledStudent.java | 36 +++++++++++++++ null-objects/Main.java | 44 +++++++++++++++++++ null-objects/README.md | 18 ++++++++ null-objects/Student.java | 27 ++++++++++++ null-objects/nullstudent | 7 +++ 7 files changed, 161 insertions(+) create mode 100644 null-objects/EnrolledStudent.java create mode 100644 null-objects/Main.java create mode 100644 null-objects/README.md create mode 100644 null-objects/Student.java create mode 100644 null-objects/nullstudent diff --git a/data-mapper/src/main/java/com/iluwatar/datamapper/Student.java b/data-mapper/src/main/java/com/iluwatar/datamapper/Student.java index 8d8a42116a06..67c88e2c1c1d 100644 --- a/data-mapper/src/main/java/com/iluwatar/datamapper/Student.java +++ b/data-mapper/src/main/java/com/iluwatar/datamapper/Student.java @@ -26,6 +26,7 @@ import java.io.Serial; import java.io.Serializable; + import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -45,4 +46,8 @@ public final class Student implements Serializable { @EqualsAndHashCode.Include private int studentId; private String name; private char grade; + + public Student(String name) { + throw new UnsupportedOperationException("Not supported yet."); + } } diff --git a/leader-followers/src/main/java/com/iluwatar/leaderfollowers/App.java b/leader-followers/src/main/java/com/iluwatar/leaderfollowers/App.java index 28b039cc7738..88ff5c55fa56 100644 --- a/leader-followers/src/main/java/com/iluwatar/leaderfollowers/App.java +++ b/leader-followers/src/main/java/com/iluwatar/leaderfollowers/App.java @@ -1,3 +1,27 @@ +/* + * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). + * + * The MIT License + * Copyright © 2014-2022 Ilkka Seppälä + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package com.iluwatar.leaderfollowers; import java.security.SecureRandom; diff --git a/null-objects/EnrolledStudent.java b/null-objects/EnrolledStudent.java new file mode 100644 index 000000000000..731714b3ee5f --- /dev/null +++ b/null-objects/EnrolledStudent.java @@ -0,0 +1,36 @@ +/* + * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). + * + * The MIT License + * Copyright © 2014-2022 Ilkka Seppälä + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +public class EnrolledStudent { + + private final String name; + + public EnrolledStudent(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} \ No newline at end of file diff --git a/null-objects/Main.java b/null-objects/Main.java new file mode 100644 index 000000000000..1276b58aa016 --- /dev/null +++ b/null-objects/Main.java @@ -0,0 +1,44 @@ + +import com.iluwatar.datamapper.Student; + +/* + * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). + * + * The MIT License + * Copyright © 2014-2022 Ilkka Seppälä + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +public class Main { + + public static void main(String[] args) { + Student student1 = University.getStudent("Rob"); + Student student2 = University.getStudent("Bob"); + + System.out.println(student1.getName()); + System.out.println(student2.getName()); + } +} + +class University { + public static Student getStudent(String name) { + return new Student(1, name, 'A'); + } +} + diff --git a/null-objects/README.md b/null-objects/README.md new file mode 100644 index 000000000000..eab06f6b422a --- /dev/null +++ b/null-objects/README.md @@ -0,0 +1,18 @@ +Intent + +The intent is to show how to utilize null references from the absence of a real object. + +Explanation + +a null object pattern allows for when an object is not found it returns without causing errors in the system + +Example + +If a null object pattern was not implemented into a system the input may come back with an error causing issues for the user. + +Structure + +Student: Defines the common method +EnrolledStudent: represents a student who is enrolled at a university +NullStudent: represents a student who is not enrolled at a university + diff --git a/null-objects/Student.java b/null-objects/Student.java new file mode 100644 index 000000000000..480959822c24 --- /dev/null +++ b/null-objects/Student.java @@ -0,0 +1,27 @@ +/* + * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). + * + * The MIT License + * Copyright © 2014-2022 Ilkka Seppälä + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +public class Student { + +} \ No newline at end of file diff --git a/null-objects/nullstudent b/null-objects/nullstudent new file mode 100644 index 000000000000..4616da6152d4 --- /dev/null +++ b/null-objects/nullstudent @@ -0,0 +1,7 @@ +public class NullStudent implements Student { + + @Override + public String getName() { + return "Not Enrolled in Student Database"; + } +} \ No newline at end of file