├── .gitignore ├── 02-one-module └── src │ └── packt.addressbook │ ├── module-info.java │ └── packt │ └── addressbook │ ├── Main.java │ ├── model │ └── Contact.java │ └── util │ ├── ContactUtil.java │ └── SortUtil.java ├── 03-two-modules └── src │ ├── packt.addressbook │ ├── module-info.java │ └── packt │ │ └── addressbook │ │ ├── Main.java │ │ ├── model │ │ └── Contact.java │ │ └── util │ │ └── ContactUtil.java │ └── packt.sortutil │ ├── module-info.java │ └── packt │ └── util │ ├── SortUtil.java │ └── impl │ └── BubbleSortUtilImpl.java ├── 05-jdk-modules └── src │ ├── packt.addressbook.ui │ ├── module-info.java │ └── packt │ │ └── addressbook │ │ └── ui │ │ └── Main.java │ ├── packt.addressbook │ ├── module-info.java │ └── packt │ │ └── addressbook │ │ └── Main.java │ ├── packt.contact │ ├── module-info.java │ └── packt │ │ └── contact │ │ ├── internal │ │ └── XmlUtil.java │ │ ├── model │ │ ├── Address.java │ │ └── Contact.java │ │ └── util │ │ ├── ContactLoadException.java │ │ └── ContactLoader.java │ └── packt.sortutil │ ├── module-info.java │ └── packt │ └── util │ ├── SortUtil.java │ └── impl │ └── BubbleSortUtilImpl.java ├── 06-readability-accessibility └── src │ ├── packt.addressbook.lib │ └── module-info.java │ ├── packt.addressbook.ui │ ├── module-info.java │ └── packt │ │ └── addressbook │ │ └── ui │ │ └── Main.java │ ├── packt.addressbook │ ├── module-info.java │ └── packt │ │ └── addressbook │ │ └── Main.java │ ├── packt.contact │ ├── module-info.java │ └── packt │ │ └── contact │ │ ├── internal │ │ └── XmlUtil.java │ │ ├── model │ │ ├── Address.java │ │ └── Contact.java │ │ └── util │ │ ├── ContactLoadException.java │ │ └── ContactLoader.java │ └── packt.sortutil │ ├── module-info.java │ └── packt │ └── util │ ├── SortUtil.java │ └── impl │ └── BubbleSortUtilImpl.java ├── 07-services ├── addressbook-ui.jar ├── contact.jar └── src │ ├── packt.addressbook.lib │ └── module-info.java │ ├── packt.addressbook.ui │ ├── module-info.java │ └── packt │ │ └── addressbook │ │ └── ui │ │ └── Main.java │ ├── packt.addressbook │ ├── module-info.java │ └── packt │ │ └── addressbook │ │ └── Main.java │ ├── packt.contact │ ├── module-info.java │ └── packt │ │ └── contact │ │ ├── internal │ │ └── XmlUtil.java │ │ ├── model │ │ ├── Address.java │ │ └── Contact.java │ │ └── util │ │ ├── ContactLoadException.java │ │ └── ContactLoader.java │ ├── packt.sort.bubblesort │ ├── module-info.java │ └── packt │ │ └── util │ │ └── impl │ │ └── bubblesort │ │ └── BubbleSortUtilImpl.java │ ├── packt.sort.javasort │ ├── module-info.java │ └── packt │ │ └── util │ │ └── impl │ │ └── javasort │ │ └── JavaSortUtilImpl.java │ └── packt.sortutil │ ├── module-info.java │ └── packt │ └── util │ └── SortUtil.java ├── 09-module-patterns ├── 01-seperate-interface-impl │ └── src │ │ ├── consumer │ │ ├── app │ │ │ └── Main.java │ │ └── module-info.java │ │ └── pattern.one │ │ ├── module-info.java │ │ └── pattern │ │ └── one │ │ ├── external │ │ ├── Factory.java │ │ └── PublicInterface.java │ │ └── internal │ │ ├── PrivateImplA.java │ │ └── PrivateImplB.java ├── 02-services │ └── src │ │ ├── consumer │ │ ├── app │ │ │ └── Main.java │ │ └── module-info.java │ │ ├── pattern.two.implA │ │ ├── module-info.java │ │ └── pattern │ │ │ └── two │ │ │ └── implA │ │ │ └── ImplA.java │ │ ├── pattern.two.implB │ │ ├── module-info.java │ │ └── pattern │ │ │ └── two │ │ │ └── implB │ │ │ └── ImplB.java │ │ └── pattern.two.service │ │ ├── module-info.java │ │ └── pattern │ │ └── two │ │ └── external │ │ └── PublicInterface.java ├── 03-optional-dependencies │ └── src │ │ ├── consumer │ │ ├── app │ │ │ └── Main.java │ │ └── module-info.java │ │ ├── pattern.three.optlib │ │ ├── module-info.java │ │ └── pattern │ │ │ └── three │ │ │ └── lib │ │ │ └── LibImpl.java │ │ ├── pattern.three │ │ ├── module-info.java │ │ └── pattern │ │ │ └── three │ │ │ └── external │ │ │ └── Util.java │ │ └── pattern.two.implB │ │ ├── module-info.java │ │ └── pattern │ │ └── two │ │ └── implB │ │ └── ImplB.java ├── 04-optional-dependencies-with-services │ └── src │ │ ├── consumer │ │ ├── app │ │ │ └── Main.java │ │ └── module-info.java │ │ ├── pattern.four.optlib │ │ ├── module-info.java │ │ └── pattern │ │ │ └── four │ │ │ └── lib │ │ │ └── LibImpl.java │ │ └── pattern.four │ │ ├── module-info.java │ │ └── pattern │ │ └── four │ │ └── external │ │ ├── LibInterface.java │ │ └── Util.java ├── 06-open-modules │ └── src │ │ ├── consumer │ │ ├── app │ │ │ └── Main.java │ │ └── module-info.java │ │ └── pattern.six │ │ ├── module-info.java │ │ └── pattern │ │ └── six │ │ └── internal │ │ └── Contact.java ├── 07-maven-integration │ └── util │ │ ├── .project │ │ └── bin │ │ └── .project └── 09-aggregator-and-facade-modules │ └── src │ ├── consumer │ ├── app │ │ └── Main.java │ └── module-info.java │ ├── module.one │ ├── module-info.java │ └── module │ │ └── one │ │ └── external │ │ └── ApiOne.java │ ├── module.two │ ├── module-info.java │ └── module │ │ └── two │ │ └── external │ │ └── ApiTwo.java │ └── pattern.nine.facade │ ├── module-info.java │ └── pattern │ └── nine │ └── external │ └── FacadeApi.java ├── 10-migrating-application ├── 01-app-migration │ ├── lib │ │ └── commons-collections4-4.1.jar │ └── src │ │ └── com │ │ └── packt │ │ └── sortstrings │ │ ├── app │ │ └── App.java │ │ ├── data │ │ └── ShoppingBag.java │ │ └── input │ │ └── UserInputUtil.java └── 02-non-standard-api │ └── src │ └── packt │ └── app │ ├── App.java │ └── AppFixed.java ├── 11-migrating-application ├── 01-legacy-app │ ├── lib │ │ └── commons-collections4-4.1.jar │ └── src │ │ └── com │ │ └── packt │ │ └── shoppingbag │ │ ├── app │ │ └── App.java │ │ ├── data │ │ └── ShoppingBag.java │ │ └── input │ │ └── UserInputUtil.java ├── 02-migrating-to-one-module │ ├── lib │ │ └── commons-collections4-4.1.jar │ └── src │ │ └── packt.shoppingbag │ │ ├── com │ │ └── packt │ │ │ └── shoppingbag │ │ │ ├── app │ │ │ └── App.java │ │ │ ├── data │ │ │ └── ShoppingBag.java │ │ │ └── input │ │ │ └── UserInputUtil.java │ │ └── module-info.java ├── 03-splitting-modules │ ├── lib │ │ └── commons-collections4-4.1.jar │ └── src │ │ ├── packt.app │ │ ├── com │ │ │ └── packt │ │ │ │ └── app │ │ │ │ └── App.java │ │ └── module-info.java │ │ ├── packt.shoppingbag │ │ ├── com │ │ │ └── packt │ │ │ │ └── shoppingbag │ │ │ │ └── ShoppingBag.java │ │ └── module-info.java │ │ └── packt.userinput │ │ ├── com │ │ └── packt │ │ │ └── userinput │ │ │ └── UserInputUtil.java │ │ └── module-info.java └── 04-multirelease-jars │ ├── MANIFEST.MF │ ├── base │ └── src │ │ └── packt │ │ └── mylib │ │ └── PrintList.java │ └── java9 │ └── src │ └── packt.mylib │ ├── module-info.java │ └── packt │ └── mylib │ └── PrintList.java ├── 12-build-tools-and-testing ├── 01-maven-integration │ └── root │ │ ├── .project │ │ ├── .settings │ │ └── org.eclipse.m2e.core.prefs │ │ ├── lib │ │ ├── .classpath │ │ ├── .project │ │ ├── .settings │ │ │ ├── org.eclipse.jdt.core.prefs │ │ │ └── org.eclipse.m2e.core.prefs │ │ ├── pom.xml │ │ ├── src │ │ │ └── main │ │ │ │ └── java │ │ │ │ ├── com │ │ │ │ └── packt │ │ │ │ │ └── lib │ │ │ │ │ └── Lib.java │ │ │ │ └── module-info.java │ │ └── target │ │ │ └── classes │ │ │ └── com │ │ │ └── packt │ │ │ └── lib │ │ │ └── Lib.class │ │ ├── main │ │ ├── .classpath │ │ ├── .project │ │ ├── .settings │ │ │ ├── org.eclipse.jdt.core.prefs │ │ │ └── org.eclipse.m2e.core.prefs │ │ ├── pom.xml │ │ ├── src │ │ │ └── main │ │ │ │ └── java │ │ │ │ ├── com │ │ │ │ └── packt │ │ │ │ │ └── App.java │ │ │ │ └── module-info.java │ │ └── target │ │ │ └── classes │ │ │ └── com │ │ │ └── packt │ │ │ └── App.class │ │ └── pom.xml └── 02-testing │ ├── lib │ ├── hamcrest-core-1.3.jar │ └── junit-4.12.jar │ ├── packt.util.test.SortUtilTest │ └── src │ ├── packt.sortutil.test │ ├── module-info.java │ └── packt │ │ └── util │ │ └── test │ │ ├── SortUtilTest.java │ │ └── SortUtilTestMain.java │ └── packt.sortutil │ ├── module-info.java │ └── packt │ └── util │ ├── SortUtil.java │ └── impl │ └── BubbleSortUtilImpl.java ├── README.md └── input.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | out/ 3 | *.class 4 | 5 | # Log file 6 | *.log 7 | 8 | # BlueJ files 9 | *.ctxt 10 | 11 | # Mobile Tools for Java (J2ME) 12 | .mtj.tmp/ 13 | 14 | # Package Files # 15 | *.jar 16 | *.war 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | # IDE 26 | .idea/ -------------------------------------------------------------------------------- /02-one-module/src/packt.addressbook/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.addressbook { 2 | 3 | } -------------------------------------------------------------------------------- /02-one-module/src/packt.addressbook/packt/addressbook/Main.java: -------------------------------------------------------------------------------- 1 | package packt.addressbook; 2 | 3 | import java.util.List; 4 | import sun.misc.Unsafe; 5 | 6 | import packt.addressbook.util.ContactUtil; 7 | import packt.addressbook.util.SortUtil; 8 | import packt.addressbook.model.Contact; 9 | 10 | public class Main { 11 | public static void main(String[] args) { 12 | System.out.println("Hello! Testing"); 13 | ContactUtil contactUtil = new ContactUtil(); 14 | SortUtil sortUtil = new SortUtil(); 15 | List contacts = contactUtil.getContacts(); 16 | sortUtil.sortList(contacts); 17 | System.out.println(contacts); 18 | } 19 | } -------------------------------------------------------------------------------- /02-one-module/src/packt.addressbook/packt/addressbook/model/Contact.java: -------------------------------------------------------------------------------- 1 | package packt.addressbook.model; 2 | 3 | public class Contact implements Comparable{ 4 | 5 | private String id; 6 | private String firstName; 7 | private String lastName; 8 | 9 | public Contact(String id, String firstName, String lastName) { 10 | this.id = id; 11 | this.firstName = firstName; 12 | this.lastName = lastName; 13 | } 14 | 15 | public String getId() { 16 | return this.id; 17 | } 18 | 19 | public String getFirstName() { 20 | return this.firstName; 21 | } 22 | 23 | public String getLastName() { 24 | return this.lastName; 25 | } 26 | 27 | public String toString() { 28 | return this.firstName + " " + this.lastName; 29 | } 30 | 31 | public int compareTo(Object other) { 32 | Contact otherContact = (Contact)other; 33 | return this.lastName.compareTo(otherContact.lastName); 34 | } 35 | 36 | 37 | } -------------------------------------------------------------------------------- /02-one-module/src/packt.addressbook/packt/addressbook/util/ContactUtil.java: -------------------------------------------------------------------------------- 1 | package packt.addressbook.util; 2 | 3 | import java.util.List; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | import packt.addressbook.model.Contact; 7 | 8 | public class ContactUtil { 9 | 10 | public List getContacts() { 11 | List contacts = Arrays.asList( 12 | new Contact("Edsger", "Dijkstra", "345-678-9012"), 13 | new Contact("Alan", "Turing", "456-789-0123"), 14 | new Contact("Ada", "Lovelace", "234-567-8901"), 15 | new Contact("Charles", "Babbage", "123-456-7890"), 16 | new Contact("Tim", "Berners-Lee", "456-789-0123") 17 | ); 18 | return contacts; 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /02-one-module/src/packt.addressbook/packt/addressbook/util/SortUtil.java: -------------------------------------------------------------------------------- 1 | package packt.addressbook.util; 2 | 3 | import java.util.List; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | 7 | 8 | public class SortUtil { 9 | 10 | @SuppressWarnings("unchecked") 11 | public List sortList(List list) { 12 | for (int outer = 0; outer < list.size() - 1; outer++) { 13 | for (int inner = 0; inner < list.size()-outer-1; inner++) { 14 | if (list.get(inner).compareTo(list.get(inner + 1)) > 0) { 15 | swap(list, inner); 16 | } 17 | } 18 | } 19 | return list; 20 | } 21 | 22 | private void swap(Listlist, int inner) { 23 | T temp = list.get(inner); 24 | list.set(inner, list.get(inner + 1)); 25 | list.set(inner + 1, temp); 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /03-two-modules/src/packt.addressbook/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.addressbook { 2 | requires packt.sortutil; 3 | } -------------------------------------------------------------------------------- /03-two-modules/src/packt.addressbook/packt/addressbook/Main.java: -------------------------------------------------------------------------------- 1 | package packt.addressbook; 2 | 3 | import java.util.List; 4 | 5 | import packt.addressbook.util.ContactUtil; 6 | import packt.util.SortUtil; 7 | import packt.addressbook.model.Contact; 8 | 9 | public class Main { 10 | public static void main(String[] args) { 11 | System.out.println("Hello! Testing"); 12 | ContactUtil contactUtil = new ContactUtil(); 13 | SortUtil sortUtil = new SortUtil(); 14 | List contacts = contactUtil.getContacts(); 15 | sortUtil.sortList(contacts); 16 | System.out.println(contacts); 17 | } 18 | } -------------------------------------------------------------------------------- /03-two-modules/src/packt.addressbook/packt/addressbook/model/Contact.java: -------------------------------------------------------------------------------- 1 | package packt.addressbook.model; 2 | 3 | public class Contact implements Comparable{ 4 | 5 | private String id; 6 | private String firstName; 7 | private String lastName; 8 | 9 | public Contact(String id, String firstName, String lastName) { 10 | this.id = id; 11 | this.firstName = firstName; 12 | this.lastName = lastName; 13 | } 14 | 15 | public String getId() { 16 | return this.id; 17 | } 18 | 19 | public String getFirstName() { 20 | return this.firstName; 21 | } 22 | 23 | public String getLastName() { 24 | return this.lastName; 25 | } 26 | 27 | public String toString() { 28 | return this.firstName + " " + this.lastName; 29 | } 30 | 31 | public int compareTo(Object other) { 32 | Contact otherContact = (Contact)other; 33 | return this.lastName.compareTo(otherContact.lastName); 34 | } 35 | 36 | 37 | } -------------------------------------------------------------------------------- /03-two-modules/src/packt.addressbook/packt/addressbook/util/ContactUtil.java: -------------------------------------------------------------------------------- 1 | package packt.addressbook.util; 2 | 3 | import java.util.List; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | import packt.addressbook.model.Contact; 7 | 8 | public class ContactUtil { 9 | 10 | public List getContacts() { 11 | List contacts = Arrays.asList( 12 | new Contact("Edsger", "Dijkstra", "345-678-9012"), 13 | new Contact("Alan", "Turing", "456-789-0123"), 14 | new Contact("Ada", "Lovelace", "234-567-8901"), 15 | new Contact("Charles", "Babbage", "123-456-7890"), 16 | new Contact("Tim", "Berners-Lee", "456-789-0123") 17 | ); 18 | return contacts; 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /03-two-modules/src/packt.sortutil/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.sortutil { 2 | exports packt.util; 3 | } -------------------------------------------------------------------------------- /03-two-modules/src/packt.sortutil/packt/util/SortUtil.java: -------------------------------------------------------------------------------- 1 | package packt.util; 2 | 3 | import java.util.List; 4 | 5 | import packt.util.impl.BubbleSortUtilImpl; 6 | 7 | 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | 11 | public class SortUtil { 12 | 13 | private BubbleSortUtilImpl sortImpl = new BubbleSortUtilImpl(); 14 | 15 | public List sortList(List list) { 16 | return this.sortImpl.sortList(list); 17 | } 18 | 19 | 20 | 21 | 22 | } -------------------------------------------------------------------------------- /03-two-modules/src/packt.sortutil/packt/util/impl/BubbleSortUtilImpl.java: -------------------------------------------------------------------------------- 1 | package packt.util.impl; 2 | 3 | import java.util.List; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | 7 | public class BubbleSortUtilImpl { 8 | 9 | @SuppressWarnings("unchecked") 10 | public List sortList(List list) { 11 | for (int outer = 0; outer < list.size() - 1; outer++) { 12 | for (int inner = 0; inner < list.size()-outer-1; inner++) { 13 | if (list.get(inner).compareTo(list.get(inner + 1)) > 0) { 14 | swap(list, inner); 15 | } 16 | } 17 | } 18 | return list; 19 | } 20 | 21 | private void swap(Listlist, int inner) { 22 | T temp = list.get(inner); 23 | list.set(inner, list.get(inner + 1)); 24 | list.set(inner + 1, temp); 25 | } 26 | 27 | 28 | 29 | } -------------------------------------------------------------------------------- /05-jdk-modules/src/packt.addressbook.ui/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.addressbook.ui { 2 | 3 | exports packt.addressbook.ui; 4 | requires java.logging; 5 | requires javafx.base; 6 | requires javafx.controls; 7 | requires javafx.graphics; 8 | requires packt.sortutil; 9 | requires packt.contact; 10 | 11 | } -------------------------------------------------------------------------------- /05-jdk-modules/src/packt.addressbook.ui/packt/addressbook/ui/Main.java: -------------------------------------------------------------------------------- 1 | package packt.addressbook.ui; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | import javafx.application.Application; 8 | import javafx.collections.FXCollections; 9 | import javafx.collections.ObservableList; 10 | import javafx.geometry.HPos; 11 | import javafx.geometry.Insets; 12 | import javafx.geometry.Pos; 13 | import javafx.geometry.VPos; 14 | import javafx.scene.Scene; 15 | import javafx.scene.control.Label; 16 | import javafx.scene.control.ListView; 17 | import javafx.scene.layout.BorderPane; 18 | import javafx.scene.layout.GridPane; 19 | import javafx.scene.layout.HBox; 20 | import javafx.scene.paint.Color; 21 | import javafx.scene.text.Font; 22 | import javafx.scene.text.FontWeight; 23 | import javafx.stage.Stage; 24 | 25 | import packt.util.SortUtil; 26 | import packt.contact.model.Contact; 27 | import packt.contact.util.ContactLoadException; 28 | import packt.contact.util.ContactLoader; 29 | 30 | public class Main extends Application { 31 | 32 | public static void main(String[] args) { 33 | launch(args); 34 | } 35 | 36 | @Override 37 | public void start(Stage primaryStage) throws Exception { 38 | 39 | List contacts = new ArrayList<>(); 40 | ContactLoader contactLoader = new ContactLoader(); 41 | SortUtil sortUtil = new SortUtil(); 42 | try { 43 | contacts = contactLoader.parseXml("/Users/kkothagal/Documents/workspace-new/java-xml/input.txt"); 44 | } catch (ContactLoadException e) { 45 | 46 | System.exit(0); 47 | } 48 | sortUtil.sortList(contacts); 49 | primaryStage.setTitle("Addressbook Viewer"); 50 | 51 | BorderPane root = new BorderPane(); 52 | HBox hbox = generateTitleHBox(); 53 | root.setTop(hbox); 54 | 55 | 56 | 57 | GridPane grid = new GridPane(); 58 | grid.setVgap(10); 59 | grid.setPadding(new Insets(0, 10, 0, 10)); 60 | 61 | Label name = new Label(); 62 | name.setFont(Font.font("Verdana", FontWeight.BOLD, 30)); 63 | GridPane.setHalignment(name, HPos.RIGHT); 64 | grid.add(name, 0, 1); 65 | 66 | Label phone = new Label(); 67 | phone.setFont(Font.font("Verdana", FontWeight.NORMAL, 15)); 68 | GridPane.setHalignment(phone, HPos.RIGHT); 69 | grid.add(phone, 0, 2); 70 | 71 | Label addressLabel = new Label(); 72 | addressLabel.setFont(Font.font("Verdana", FontWeight.BOLD, 12)); 73 | GridPane.setHalignment(addressLabel, HPos.RIGHT); 74 | grid.add(addressLabel, 0, 3); 75 | 76 | Label street = new Label(); 77 | GridPane.setHalignment(street, HPos.RIGHT); 78 | grid.add(street, 0, 4); 79 | 80 | Label city = new Label(); 81 | GridPane.setHalignment(city, HPos.RIGHT); 82 | grid.add(city, 0, 5); 83 | 84 | Label state = new Label(); 85 | GridPane.setHalignment(state, HPos.RIGHT); 86 | grid.add(state, 0, 6); 87 | 88 | Label country = new Label(); 89 | GridPane.setHalignment(country, HPos.RIGHT); 90 | grid.add(country, 0, 7); 91 | 92 | 93 | 94 | final List finalContactList = contacts; 95 | // Create a new JavaFX ListView 96 | ListView list = new ListView(); 97 | // Collect a String list of Contact names in lastName, firstName format 98 | List listContactNames = contacts.stream().map(c -> c.getLastName() + ", " + c.getFirstName()) 99 | .collect(Collectors.toList()); 100 | // Build an ObservableList from the list of names 101 | ObservableList obsContactNames = FXCollections.observableList(listContactNames); 102 | // Pass that to ListView to have them displayed in a list 103 | list.setItems(obsContactNames); 104 | // Add listener to handle click events 105 | list.getSelectionModel().selectedItemProperty().addListener((obs, oldVal, newVal) -> { 106 | // Get the selected index in the ListView 107 | int selectedIndex = list.getSelectionModel().getSelectedIndex(); 108 | name.setText(newVal); 109 | // Get the Contact instance which was clicked 110 | Contact contact = finalContactList.get(selectedIndex); 111 | // Set the values to the labels on the right 112 | phone.setText("Phone: " + contact.getPhone()); 113 | addressLabel.setText("Address"); 114 | street.setText(contact.getAddress().getStreet()); 115 | city.setText(contact.getAddress().getCity()); 116 | state.setText(contact.getAddress().getState()); 117 | country.setText(contact.getAddress().getCountry()); 118 | 119 | }); 120 | 121 | list.setPrefWidth(300); 122 | list.setPrefHeight(650); 123 | root.setLeft(list); 124 | root.setRight(grid); 125 | 126 | 127 | 128 | 129 | 130 | primaryStage.setScene(new Scene(root, 700, 550)); 131 | primaryStage.show(); 132 | 133 | } 134 | 135 | public HBox generateTitleHBox() { 136 | HBox hbox = new HBox(); 137 | hbox.setPadding(new Insets(15, 12, 15, 12)); 138 | hbox.setSpacing(10); 139 | hbox.setStyle("-fx-background-color: #336699;"); 140 | 141 | Label appTitle = new Label("Addressbook Reader"); 142 | appTitle.setTextFill(Color.web("#FFFFFF")); 143 | appTitle.setFont(Font.font("Verdana", FontWeight.BOLD, 20)); 144 | hbox.getChildren().add(appTitle); 145 | 146 | return hbox; 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /05-jdk-modules/src/packt.addressbook/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.addressbook { 2 | 3 | requires java.logging; 4 | requires packt.sortutil; 5 | requires packt.contact; 6 | 7 | } -------------------------------------------------------------------------------- /05-jdk-modules/src/packt.addressbook/packt/addressbook/Main.java: -------------------------------------------------------------------------------- 1 | package packt.addressbook; 2 | 3 | import java.util.List; 4 | import java.util.Date; 5 | import java.util.ArrayList; 6 | import java.util.logging.Logger; 7 | 8 | 9 | import packt.util.SortUtil; 10 | import packt.contact.model.Contact; 11 | import packt.contact.util.ContactLoader; 12 | import packt.contact.util.ContactLoadException; 13 | 14 | 15 | public class Main { 16 | 17 | private static final Logger logger = 18 | Logger.getLogger(Main.class.getName()); 19 | 20 | public static void main(String[] args) { 21 | 22 | logger.info("Address book viewer application: Started"); 23 | List contacts = new ArrayList<>(); 24 | ContactLoader contactLoader = new ContactLoader(); 25 | SortUtil sortUtil = new SortUtil(); 26 | try { 27 | contacts = contactLoader.parseXml("/Users/kkothagal/code/java9/input.xml"); 28 | } catch (ContactLoadException e) { 29 | logger.severe(e.getMessage()); 30 | System.exit(0); 31 | } 32 | 33 | sortUtil.sortList(contacts); 34 | System.out.println(contacts); 35 | logger.info("Address book viewer application: Completed"); 36 | } 37 | } -------------------------------------------------------------------------------- /05-jdk-modules/src/packt.contact/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.contact { 2 | requires java.xml; 3 | exports packt.contact.model; 4 | exports packt.contact.util; 5 | } -------------------------------------------------------------------------------- /05-jdk-modules/src/packt.contact/packt/contact/internal/XmlUtil.java: -------------------------------------------------------------------------------- 1 | package packt.contact.internal; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import javax.xml.parsers.DocumentBuilder; 7 | import javax.xml.parsers.DocumentBuilderFactory; 8 | import javax.xml.parsers.ParserConfigurationException; 9 | 10 | import org.w3c.dom.Document; 11 | import org.w3c.dom.Element; 12 | import org.w3c.dom.Node; 13 | import org.xml.sax.SAXException; 14 | 15 | public class XmlUtil { 16 | 17 | 18 | public Document loadXmlFile(String fileName) throws ParserConfigurationException, SAXException, IOException { 19 | File inputFile = new File(fileName); 20 | DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); 21 | DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); 22 | Document doc = dBuilder.parse(inputFile); 23 | doc.getDocumentElement().normalize(); 24 | return doc; 25 | } 26 | 27 | public String getElement(Node nNode, String tagName) { 28 | if (nNode.getNodeType() == Node.ELEMENT_NODE) { 29 | Element eElement = (Element) nNode; 30 | return eElement.getElementsByTagName(tagName).item(0).getTextContent(); 31 | } 32 | return ""; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /05-jdk-modules/src/packt.contact/packt/contact/model/Address.java: -------------------------------------------------------------------------------- 1 | package packt.contact.model; 2 | 3 | public class Address { 4 | 5 | private String street; 6 | private String city; 7 | private String state; 8 | private String country; 9 | 10 | public String getStreet() { 11 | return street; 12 | } 13 | public void setStreet(String street) { 14 | this.street = street; 15 | } 16 | public String getCity() { 17 | return city; 18 | } 19 | public void setCity(String city) { 20 | this.city = city; 21 | } 22 | public String getState() { 23 | return state; 24 | } 25 | public void setState(String state) { 26 | this.state = state; 27 | } 28 | public String getCountry() { 29 | return country; 30 | } 31 | public void setCountry(String country) { 32 | this.country = country; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /05-jdk-modules/src/packt.contact/packt/contact/model/Contact.java: -------------------------------------------------------------------------------- 1 | package packt.contact.model; 2 | 3 | public class Contact implements Comparable{ 4 | 5 | private String id; 6 | private String firstName; 7 | private String lastName; 8 | private String phone; 9 | private Address address; 10 | 11 | public Contact() {} 12 | 13 | public Contact(String id, String firstName, String lastName) { 14 | this.id = id; 15 | this.firstName = firstName; 16 | this.lastName = lastName; 17 | } 18 | 19 | public String getId() { 20 | return id; 21 | } 22 | 23 | 24 | 25 | public void setId(String id) { 26 | this.id = id; 27 | } 28 | 29 | 30 | 31 | public String getFirstName() { 32 | return firstName; 33 | } 34 | 35 | 36 | 37 | public void setFirstName(String firstName) { 38 | this.firstName = firstName; 39 | } 40 | 41 | 42 | 43 | public String getLastName() { 44 | return lastName; 45 | } 46 | 47 | 48 | 49 | public void setLastName(String lastName) { 50 | this.lastName = lastName; 51 | } 52 | 53 | 54 | 55 | public Address getAddress() { 56 | return address; 57 | } 58 | 59 | 60 | 61 | public void setAddress(Address address) { 62 | this.address = address; 63 | } 64 | 65 | 66 | 67 | public String getPhone() { 68 | return phone; 69 | } 70 | 71 | public void setPhone(String phone) { 72 | this.phone = phone; 73 | } 74 | 75 | public String toString() { 76 | return this.firstName + " " + this.lastName; 77 | } 78 | 79 | public int compareTo(Object other) { 80 | Contact otherContact = (Contact)other; 81 | return this.lastName.compareTo(otherContact.lastName); 82 | } 83 | 84 | 85 | } -------------------------------------------------------------------------------- /05-jdk-modules/src/packt.contact/packt/contact/util/ContactLoadException.java: -------------------------------------------------------------------------------- 1 | package packt.contact.util; 2 | 3 | public class ContactLoadException extends Exception { 4 | 5 | private static final long serialVersionUID = 1900827267795855111L; 6 | 7 | public ContactLoadException() { 8 | super(); 9 | } 10 | 11 | public ContactLoadException(String message) { 12 | super(message); 13 | // TODO Auto-generated constructor stub 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /05-jdk-modules/src/packt.contact/packt/contact/util/ContactLoader.java: -------------------------------------------------------------------------------- 1 | package packt.contact.util; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.ParserConfigurationException; 8 | 9 | import org.w3c.dom.Document; 10 | import org.w3c.dom.Element; 11 | import org.w3c.dom.Node; 12 | import org.w3c.dom.NodeList; 13 | import org.xml.sax.SAXException; 14 | 15 | import packt.contact.internal.XmlUtil; 16 | import packt.contact.model.Address; 17 | import packt.contact.model.Contact; 18 | 19 | public class ContactLoader { 20 | 21 | 22 | public List parseXml(String fileName) throws ContactLoadException { 23 | 24 | List contacts = new ArrayList<>(); 25 | XmlUtil xmlUtil = new XmlUtil(); 26 | 27 | 28 | Document doc; 29 | try { 30 | doc = xmlUtil.loadXmlFile(fileName); 31 | } catch (ParserConfigurationException | SAXException | IOException e) { 32 | throw new ContactLoadException("Unable to load Contact file"); 33 | } 34 | NodeList nList = doc.getElementsByTagName("contact"); 35 | for (int temp = 0; temp < nList.getLength(); temp++) { 36 | Node contactNode = nList.item(temp); 37 | if (contactNode.getNodeType() == Node.ELEMENT_NODE) { 38 | Element eElement = (Element) contactNode; 39 | 40 | Contact contact = new Contact(); 41 | contact.setFirstName(xmlUtil.getElement(contactNode, "firstname")); 42 | contact.setLastName(xmlUtil.getElement(contactNode, "lastname")); 43 | contact.setPhone(xmlUtil.getElement(contactNode, "phone")); 44 | Node addressNode = eElement.getElementsByTagName("address").item(0); 45 | 46 | Address address = new Address(); 47 | address.setStreet(xmlUtil.getElement(addressNode, "street")); 48 | address.setCity(xmlUtil.getElement(addressNode, "city")); 49 | address.setState(xmlUtil.getElement(addressNode, "state")); 50 | address.setCountry(xmlUtil.getElement(addressNode, "country")); 51 | contact.setAddress(address); 52 | 53 | contacts.add(contact); 54 | } 55 | } 56 | return contacts; 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /05-jdk-modules/src/packt.sortutil/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.sortutil { 2 | exports packt.util; 3 | } -------------------------------------------------------------------------------- /05-jdk-modules/src/packt.sortutil/packt/util/SortUtil.java: -------------------------------------------------------------------------------- 1 | package packt.util; 2 | 3 | import java.util.List; 4 | 5 | import packt.util.impl.BubbleSortUtilImpl; 6 | 7 | 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | 11 | public class SortUtil { 12 | 13 | private BubbleSortUtilImpl sortImpl = new BubbleSortUtilImpl(); 14 | 15 | public List sortList(List list) { 16 | return this.sortImpl.sortList(list); 17 | } 18 | 19 | 20 | 21 | 22 | } -------------------------------------------------------------------------------- /05-jdk-modules/src/packt.sortutil/packt/util/impl/BubbleSortUtilImpl.java: -------------------------------------------------------------------------------- 1 | package packt.util.impl; 2 | 3 | import java.util.List; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | 7 | public class BubbleSortUtilImpl { 8 | 9 | @SuppressWarnings("unchecked") 10 | public List sortList(List list) { 11 | for (int outer = 0; outer < list.size() - 1; outer++) { 12 | for (int inner = 0; inner < list.size()-outer-1; inner++) { 13 | if (list.get(inner).compareTo(list.get(inner + 1)) > 0) { 14 | swap(list, inner); 15 | } 16 | } 17 | } 18 | return list; 19 | } 20 | 21 | private void swap(Listlist, int inner) { 22 | T temp = list.get(inner); 23 | list.set(inner, list.get(inner + 1)); 24 | list.set(inner + 1, temp); 25 | } 26 | 27 | 28 | 29 | } -------------------------------------------------------------------------------- /06-readability-accessibility/src/packt.addressbook.lib/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.addressbook.lib { 2 | 3 | requires transitive packt.contact; 4 | requires transitive packt.sortutil; 5 | 6 | } -------------------------------------------------------------------------------- /06-readability-accessibility/src/packt.addressbook.ui/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.addressbook.ui { 2 | 3 | exports packt.addressbook.ui to javafx.graphics; 4 | requires java.logging; 5 | requires javafx.controls; 6 | requires packt.addressbook.lib; 7 | 8 | } -------------------------------------------------------------------------------- /06-readability-accessibility/src/packt.addressbook.ui/packt/addressbook/ui/Main.java: -------------------------------------------------------------------------------- 1 | package packt.addressbook.ui; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | import javafx.application.Application; 8 | import javafx.collections.FXCollections; 9 | import javafx.collections.ObservableList; 10 | import javafx.geometry.HPos; 11 | import javafx.geometry.Insets; 12 | import javafx.geometry.Pos; 13 | import javafx.geometry.VPos; 14 | import javafx.scene.Scene; 15 | import javafx.scene.control.Label; 16 | import javafx.scene.control.ListView; 17 | import javafx.scene.layout.BorderPane; 18 | import javafx.scene.layout.GridPane; 19 | import javafx.scene.layout.HBox; 20 | import javafx.scene.paint.Color; 21 | import javafx.scene.text.Font; 22 | import javafx.scene.text.FontWeight; 23 | import javafx.stage.Stage; 24 | 25 | import packt.util.SortUtil; 26 | import packt.contact.model.Contact; 27 | import packt.contact.util.ContactLoadException; 28 | import packt.contact.util.ContactLoader; 29 | 30 | public class Main extends Application { 31 | 32 | public static void main(String[] args) { 33 | launch(args); 34 | } 35 | 36 | @Override 37 | public void start(Stage primaryStage) throws Exception { 38 | 39 | List contacts = new ArrayList<>(); 40 | ContactLoader contactLoader = new ContactLoader(); 41 | SortUtil sortUtil = new SortUtil(); 42 | try { 43 | contacts = contactLoader.parseXml("/Users/kkothagal/Documents/workspace-new/java-xml/input.txt"); 44 | } catch (ContactLoadException e) { 45 | 46 | System.exit(0); 47 | } 48 | sortUtil.sortList(contacts); 49 | primaryStage.setTitle("Addressbook Viewer"); 50 | 51 | BorderPane root = new BorderPane(); 52 | HBox hbox = generateTitleHBox(); 53 | root.setTop(hbox); 54 | 55 | 56 | 57 | GridPane grid = new GridPane(); 58 | grid.setVgap(10); 59 | grid.setPadding(new Insets(0, 10, 0, 10)); 60 | 61 | Label name = new Label(); 62 | name.setFont(Font.font("Verdana", FontWeight.BOLD, 30)); 63 | GridPane.setHalignment(name, HPos.RIGHT); 64 | grid.add(name, 0, 1); 65 | 66 | Label phone = new Label(); 67 | phone.setFont(Font.font("Verdana", FontWeight.NORMAL, 15)); 68 | GridPane.setHalignment(phone, HPos.RIGHT); 69 | grid.add(phone, 0, 2); 70 | 71 | Label addressLabel = new Label(); 72 | addressLabel.setFont(Font.font("Verdana", FontWeight.BOLD, 12)); 73 | GridPane.setHalignment(addressLabel, HPos.RIGHT); 74 | grid.add(addressLabel, 0, 3); 75 | 76 | Label street = new Label(); 77 | GridPane.setHalignment(street, HPos.RIGHT); 78 | grid.add(street, 0, 4); 79 | 80 | Label city = new Label(); 81 | GridPane.setHalignment(city, HPos.RIGHT); 82 | grid.add(city, 0, 5); 83 | 84 | Label state = new Label(); 85 | GridPane.setHalignment(state, HPos.RIGHT); 86 | grid.add(state, 0, 6); 87 | 88 | Label country = new Label(); 89 | GridPane.setHalignment(country, HPos.RIGHT); 90 | grid.add(country, 0, 7); 91 | 92 | 93 | 94 | final List finalContactList = contacts; 95 | // Create a new JavaFX ListView 96 | ListView list = new ListView(); 97 | // Collect a String list of Contact names in lastName, firstName format 98 | List listContactNames = contacts.stream().map(c -> c.getLastName() + ", " + c.getFirstName()) 99 | .collect(Collectors.toList()); 100 | // Build an ObservableList from the list of names 101 | ObservableList obsContactNames = FXCollections.observableList(listContactNames); 102 | // Pass that to ListView to have them displayed in a list 103 | list.setItems(obsContactNames); 104 | // Add listener to handle click events 105 | list.getSelectionModel().selectedItemProperty().addListener((obs, oldVal, newVal) -> { 106 | // Get the selected index in the ListView 107 | int selectedIndex = list.getSelectionModel().getSelectedIndex(); 108 | name.setText(newVal); 109 | // Get the Contact instance which was clicked 110 | Contact contact = finalContactList.get(selectedIndex); 111 | // Set the values to the labels on the right 112 | phone.setText("Phone: " + contact.getPhone()); 113 | addressLabel.setText("Address"); 114 | street.setText(contact.getAddress().getStreet()); 115 | city.setText(contact.getAddress().getCity()); 116 | state.setText(contact.getAddress().getState()); 117 | country.setText(contact.getAddress().getCountry()); 118 | 119 | }); 120 | 121 | list.setPrefWidth(300); 122 | list.setPrefHeight(650); 123 | root.setLeft(list); 124 | root.setRight(grid); 125 | 126 | 127 | 128 | 129 | 130 | primaryStage.setScene(new Scene(root, 700, 550)); 131 | primaryStage.show(); 132 | 133 | } 134 | 135 | public HBox generateTitleHBox() { 136 | HBox hbox = new HBox(); 137 | hbox.setPadding(new Insets(15, 12, 15, 12)); 138 | hbox.setSpacing(10); 139 | hbox.setStyle("-fx-background-color: #336699;"); 140 | 141 | Label appTitle = new Label("Addressbook Reader"); 142 | appTitle.setTextFill(Color.web("#FFFFFF")); 143 | appTitle.setFont(Font.font("Verdana", FontWeight.BOLD, 20)); 144 | hbox.getChildren().add(appTitle); 145 | 146 | return hbox; 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /06-readability-accessibility/src/packt.addressbook/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.addressbook { 2 | 3 | requires java.logging; 4 | requires packt.addressbook.lib; 5 | 6 | } -------------------------------------------------------------------------------- /06-readability-accessibility/src/packt.addressbook/packt/addressbook/Main.java: -------------------------------------------------------------------------------- 1 | package packt.addressbook; 2 | 3 | import java.util.List; 4 | import java.util.Date; 5 | import java.util.ArrayList; 6 | import java.util.logging.Logger; 7 | 8 | 9 | import packt.util.SortUtil; 10 | import packt.contact.model.Contact; 11 | import packt.contact.util.ContactLoader; 12 | import packt.contact.util.ContactLoadException; 13 | 14 | 15 | public class Main { 16 | 17 | private static final Logger logger = 18 | Logger.getLogger(Main.class.getName()); 19 | 20 | public static void main(String[] args) { 21 | 22 | logger.info("Address book viewer application: Started"); 23 | List contacts = new ArrayList<>(); 24 | ContactLoader contactLoader = new ContactLoader(); 25 | SortUtil sortUtil = new SortUtil(); 26 | try { 27 | contacts = contactLoader.parseXml("/Users/kkothagal/code/java9/input.xml"); 28 | } catch (ContactLoadException e) { 29 | logger.severe(e.getMessage()); 30 | System.exit(0); 31 | } 32 | 33 | sortUtil.sortList(contacts); 34 | System.out.println(contacts); 35 | logger.info("Address book viewer application: Completed"); 36 | } 37 | } -------------------------------------------------------------------------------- /06-readability-accessibility/src/packt.contact/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.contact { 2 | requires java.xml; 3 | exports packt.contact.model; 4 | exports packt.contact.util; 5 | } -------------------------------------------------------------------------------- /06-readability-accessibility/src/packt.contact/packt/contact/internal/XmlUtil.java: -------------------------------------------------------------------------------- 1 | package packt.contact.internal; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import javax.xml.parsers.DocumentBuilder; 7 | import javax.xml.parsers.DocumentBuilderFactory; 8 | import javax.xml.parsers.ParserConfigurationException; 9 | 10 | import org.w3c.dom.Document; 11 | import org.w3c.dom.Element; 12 | import org.w3c.dom.Node; 13 | import org.xml.sax.SAXException; 14 | 15 | public class XmlUtil { 16 | 17 | 18 | public Document loadXmlFile(String fileName) throws ParserConfigurationException, SAXException, IOException { 19 | File inputFile = new File(fileName); 20 | DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); 21 | DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); 22 | Document doc = dBuilder.parse(inputFile); 23 | doc.getDocumentElement().normalize(); 24 | return doc; 25 | } 26 | 27 | public String getElement(Node nNode, String tagName) { 28 | if (nNode.getNodeType() == Node.ELEMENT_NODE) { 29 | Element eElement = (Element) nNode; 30 | return eElement.getElementsByTagName(tagName).item(0).getTextContent(); 31 | } 32 | return ""; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /06-readability-accessibility/src/packt.contact/packt/contact/model/Address.java: -------------------------------------------------------------------------------- 1 | package packt.contact.model; 2 | 3 | public class Address { 4 | 5 | private String street; 6 | private String city; 7 | private String state; 8 | private String country; 9 | 10 | public String getStreet() { 11 | return street; 12 | } 13 | public void setStreet(String street) { 14 | this.street = street; 15 | } 16 | public String getCity() { 17 | return city; 18 | } 19 | public void setCity(String city) { 20 | this.city = city; 21 | } 22 | public String getState() { 23 | return state; 24 | } 25 | public void setState(String state) { 26 | this.state = state; 27 | } 28 | public String getCountry() { 29 | return country; 30 | } 31 | public void setCountry(String country) { 32 | this.country = country; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /06-readability-accessibility/src/packt.contact/packt/contact/model/Contact.java: -------------------------------------------------------------------------------- 1 | package packt.contact.model; 2 | 3 | public class Contact implements Comparable{ 4 | 5 | private String id; 6 | private String firstName; 7 | private String lastName; 8 | private String phone; 9 | private Address address; 10 | 11 | public Contact() {} 12 | 13 | public Contact(String id, String firstName, String lastName) { 14 | this.id = id; 15 | this.firstName = firstName; 16 | this.lastName = lastName; 17 | } 18 | 19 | public String getId() { 20 | return id; 21 | } 22 | 23 | 24 | 25 | public void setId(String id) { 26 | this.id = id; 27 | } 28 | 29 | 30 | 31 | public String getFirstName() { 32 | return firstName; 33 | } 34 | 35 | 36 | 37 | public void setFirstName(String firstName) { 38 | this.firstName = firstName; 39 | } 40 | 41 | 42 | 43 | public String getLastName() { 44 | return lastName; 45 | } 46 | 47 | 48 | 49 | public void setLastName(String lastName) { 50 | this.lastName = lastName; 51 | } 52 | 53 | 54 | 55 | public Address getAddress() { 56 | return address; 57 | } 58 | 59 | 60 | 61 | public void setAddress(Address address) { 62 | this.address = address; 63 | } 64 | 65 | 66 | 67 | public String getPhone() { 68 | return phone; 69 | } 70 | 71 | public void setPhone(String phone) { 72 | this.phone = phone; 73 | } 74 | 75 | public String toString() { 76 | return this.firstName + " " + this.lastName; 77 | } 78 | 79 | public int compareTo(Object other) { 80 | Contact otherContact = (Contact)other; 81 | return this.lastName.compareTo(otherContact.lastName); 82 | } 83 | 84 | 85 | } -------------------------------------------------------------------------------- /06-readability-accessibility/src/packt.contact/packt/contact/util/ContactLoadException.java: -------------------------------------------------------------------------------- 1 | package packt.contact.util; 2 | 3 | public class ContactLoadException extends Exception { 4 | 5 | private static final long serialVersionUID = 1900827267795855111L; 6 | 7 | public ContactLoadException() { 8 | super(); 9 | } 10 | 11 | public ContactLoadException(String message) { 12 | super(message); 13 | // TODO Auto-generated constructor stub 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /06-readability-accessibility/src/packt.contact/packt/contact/util/ContactLoader.java: -------------------------------------------------------------------------------- 1 | package packt.contact.util; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.ParserConfigurationException; 8 | 9 | import org.w3c.dom.Document; 10 | import org.w3c.dom.Element; 11 | import org.w3c.dom.Node; 12 | import org.w3c.dom.NodeList; 13 | import org.xml.sax.SAXException; 14 | 15 | import packt.contact.internal.XmlUtil; 16 | import packt.contact.model.Address; 17 | import packt.contact.model.Contact; 18 | 19 | public class ContactLoader { 20 | 21 | 22 | public List parseXml(String fileName) throws ContactLoadException { 23 | 24 | List contacts = new ArrayList<>(); 25 | XmlUtil xmlUtil = new XmlUtil(); 26 | 27 | 28 | Document doc; 29 | try { 30 | doc = xmlUtil.loadXmlFile(fileName); 31 | } catch (ParserConfigurationException | SAXException | IOException e) { 32 | throw new ContactLoadException("Unable to load Contact file"); 33 | } 34 | NodeList nList = doc.getElementsByTagName("contact"); 35 | for (int temp = 0; temp < nList.getLength(); temp++) { 36 | Node contactNode = nList.item(temp); 37 | if (contactNode.getNodeType() == Node.ELEMENT_NODE) { 38 | Element eElement = (Element) contactNode; 39 | 40 | Contact contact = new Contact(); 41 | contact.setFirstName(xmlUtil.getElement(contactNode, "firstname")); 42 | contact.setLastName(xmlUtil.getElement(contactNode, "lastname")); 43 | contact.setPhone(xmlUtil.getElement(contactNode, "phone")); 44 | Node addressNode = eElement.getElementsByTagName("address").item(0); 45 | 46 | Address address = new Address(); 47 | address.setStreet(xmlUtil.getElement(addressNode, "street")); 48 | address.setCity(xmlUtil.getElement(addressNode, "city")); 49 | address.setState(xmlUtil.getElement(addressNode, "state")); 50 | address.setCountry(xmlUtil.getElement(addressNode, "country")); 51 | contact.setAddress(address); 52 | 53 | contacts.add(contact); 54 | } 55 | } 56 | return contacts; 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /06-readability-accessibility/src/packt.sortutil/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.sortutil { 2 | exports packt.util; 3 | } -------------------------------------------------------------------------------- /06-readability-accessibility/src/packt.sortutil/packt/util/SortUtil.java: -------------------------------------------------------------------------------- 1 | package packt.util; 2 | 3 | import java.util.List; 4 | 5 | import packt.util.impl.BubbleSortUtilImpl; 6 | 7 | 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | 11 | public class SortUtil { 12 | 13 | private BubbleSortUtilImpl sortImpl = new BubbleSortUtilImpl(); 14 | 15 | public List sortList(List list) { 16 | return this.sortImpl.sortList(list); 17 | } 18 | 19 | 20 | 21 | 22 | } -------------------------------------------------------------------------------- /06-readability-accessibility/src/packt.sortutil/packt/util/impl/BubbleSortUtilImpl.java: -------------------------------------------------------------------------------- 1 | package packt.util.impl; 2 | 3 | import java.util.List; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | 7 | public class BubbleSortUtilImpl { 8 | 9 | public List sortList(List list) { 10 | for (int outer = 0; outer < list.size() - 1; outer++) { 11 | for (int inner = 0; inner < list.size()-outer-1; inner++) { 12 | if (list.get(inner).compareTo(list.get(inner + 1)) > 0) { 13 | swap(list, inner); 14 | } 15 | } 16 | } 17 | return list; 18 | } 19 | 20 | private void swap(Listlist, int inner) { 21 | T temp = list.get(inner); 22 | list.set(inner, list.get(inner + 1)); 23 | list.set(inner + 1, temp); 24 | } 25 | 26 | 27 | 28 | } -------------------------------------------------------------------------------- /07-services/addressbook-ui.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koushikkothagal/Modular-Programming-in-Java-9/153ff1ef2b64497aca4a5cc883b7ca4c2a2bf815/07-services/addressbook-ui.jar -------------------------------------------------------------------------------- /07-services/contact.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koushikkothagal/Modular-Programming-in-Java-9/153ff1ef2b64497aca4a5cc883b7ca4c2a2bf815/07-services/contact.jar -------------------------------------------------------------------------------- /07-services/src/packt.addressbook.lib/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.addressbook.lib { 2 | 3 | requires transitive packt.contact; 4 | requires transitive packt.sortutil; 5 | 6 | } -------------------------------------------------------------------------------- /07-services/src/packt.addressbook.ui/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.addressbook.ui { 2 | 3 | exports packt.addressbook.ui to javafx.graphics; 4 | requires java.logging; 5 | requires javafx.controls; 6 | requires packt.addressbook.lib; 7 | 8 | } -------------------------------------------------------------------------------- /07-services/src/packt.addressbook.ui/packt/addressbook/ui/Main.java: -------------------------------------------------------------------------------- 1 | package packt.addressbook.ui; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | import javafx.application.Application; 8 | import javafx.collections.FXCollections; 9 | import javafx.collections.ObservableList; 10 | import javafx.geometry.HPos; 11 | import javafx.geometry.Insets; 12 | import javafx.geometry.Pos; 13 | import javafx.geometry.VPos; 14 | import javafx.scene.Scene; 15 | import javafx.scene.control.Label; 16 | import javafx.scene.control.ListView; 17 | import javafx.scene.layout.BorderPane; 18 | import javafx.scene.layout.GridPane; 19 | import javafx.scene.layout.HBox; 20 | import javafx.scene.paint.Color; 21 | import javafx.scene.text.Font; 22 | import javafx.scene.text.FontWeight; 23 | import javafx.stage.Stage; 24 | 25 | import packt.util.SortUtil; 26 | import packt.contact.model.Contact; 27 | import packt.contact.util.ContactLoadException; 28 | import packt.contact.util.ContactLoader; 29 | 30 | public class Main extends Application { 31 | 32 | public static void main(String[] args) { 33 | launch(args); 34 | } 35 | 36 | @Override 37 | public void start(Stage primaryStage) throws Exception { 38 | 39 | List contacts = new ArrayList<>(); 40 | ContactLoader contactLoader = new ContactLoader(); 41 | try { 42 | contacts = contactLoader.parseXml("/Users/kkothagal/Documents/workspace-new/java-xml/input.txt"); 43 | } catch (ContactLoadException e) { 44 | 45 | System.exit(0); 46 | } 47 | SortUtil sortUtil = SortUtil.getProviderInstance(contacts.size()); 48 | if (sortUtil != null) { 49 | sortUtil.sortList(contacts); 50 | } 51 | 52 | primaryStage.setTitle("Addressbook Viewer"); 53 | 54 | BorderPane root = new BorderPane(); 55 | HBox hbox = generateTitleHBox(); 56 | root.setTop(hbox); 57 | 58 | 59 | 60 | GridPane grid = new GridPane(); 61 | grid.setVgap(10); 62 | grid.setPadding(new Insets(0, 10, 0, 10)); 63 | 64 | Label name = new Label(); 65 | name.setFont(Font.font("Verdana", FontWeight.BOLD, 30)); 66 | GridPane.setHalignment(name, HPos.RIGHT); 67 | grid.add(name, 0, 1); 68 | 69 | Label phone = new Label(); 70 | phone.setFont(Font.font("Verdana", FontWeight.NORMAL, 15)); 71 | GridPane.setHalignment(phone, HPos.RIGHT); 72 | grid.add(phone, 0, 2); 73 | 74 | Label addressLabel = new Label(); 75 | addressLabel.setFont(Font.font("Verdana", FontWeight.BOLD, 12)); 76 | GridPane.setHalignment(addressLabel, HPos.RIGHT); 77 | grid.add(addressLabel, 0, 3); 78 | 79 | Label street = new Label(); 80 | GridPane.setHalignment(street, HPos.RIGHT); 81 | grid.add(street, 0, 4); 82 | 83 | Label city = new Label(); 84 | GridPane.setHalignment(city, HPos.RIGHT); 85 | grid.add(city, 0, 5); 86 | 87 | Label state = new Label(); 88 | GridPane.setHalignment(state, HPos.RIGHT); 89 | grid.add(state, 0, 6); 90 | 91 | Label country = new Label(); 92 | GridPane.setHalignment(country, HPos.RIGHT); 93 | grid.add(country, 0, 7); 94 | 95 | 96 | 97 | final List finalContactList = contacts; 98 | // Create a new JavaFX ListView 99 | ListView list = new ListView(); 100 | // Collect a String list of Contact names in lastName, firstName format 101 | List listContactNames = contacts.stream().map(c -> c.getLastName() + ", " + c.getFirstName()) 102 | .collect(Collectors.toList()); 103 | // Build an ObservableList from the list of names 104 | ObservableList obsContactNames = FXCollections.observableList(listContactNames); 105 | // Pass that to ListView to have them displayed in a list 106 | list.setItems(obsContactNames); 107 | // Add listener to handle click events 108 | list.getSelectionModel().selectedItemProperty().addListener((obs, oldVal, newVal) -> { 109 | // Get the selected index in the ListView 110 | int selectedIndex = list.getSelectionModel().getSelectedIndex(); 111 | name.setText(newVal); 112 | // Get the Contact instance which was clicked 113 | Contact contact = finalContactList.get(selectedIndex); 114 | // Set the values to the labels on the right 115 | phone.setText("Phone: " + contact.getPhone()); 116 | addressLabel.setText("Address"); 117 | street.setText(contact.getAddress().getStreet()); 118 | city.setText(contact.getAddress().getCity()); 119 | state.setText(contact.getAddress().getState()); 120 | country.setText(contact.getAddress().getCountry()); 121 | 122 | }); 123 | 124 | list.setPrefWidth(300); 125 | list.setPrefHeight(650); 126 | root.setLeft(list); 127 | root.setRight(grid); 128 | 129 | 130 | 131 | 132 | 133 | primaryStage.setScene(new Scene(root, 700, 550)); 134 | primaryStage.show(); 135 | 136 | } 137 | 138 | public HBox generateTitleHBox() { 139 | HBox hbox = new HBox(); 140 | hbox.setPadding(new Insets(15, 12, 15, 12)); 141 | hbox.setSpacing(10); 142 | hbox.setStyle("-fx-background-color: #336699;"); 143 | 144 | Label appTitle = new Label("Addressbook Reader"); 145 | appTitle.setTextFill(Color.web("#FFFFFF")); 146 | appTitle.setFont(Font.font("Verdana", FontWeight.BOLD, 20)); 147 | hbox.getChildren().add(appTitle); 148 | 149 | return hbox; 150 | } 151 | 152 | } 153 | -------------------------------------------------------------------------------- /07-services/src/packt.addressbook/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.addressbook { 2 | 3 | requires java.logging; 4 | requires packt.addressbook.lib; 5 | uses packt.util.SortUtil; 6 | 7 | } -------------------------------------------------------------------------------- /07-services/src/packt.addressbook/packt/addressbook/Main.java: -------------------------------------------------------------------------------- 1 | package packt.addressbook; 2 | 3 | import java.util.List; 4 | import java.util.Date; 5 | import java.util.ArrayList; 6 | import java.util.logging.Logger; 7 | import java.util.ServiceLoader; 8 | 9 | 10 | import packt.util.SortUtil; 11 | import packt.contact.model.Contact; 12 | import packt.contact.util.ContactLoader; 13 | import packt.contact.util.ContactLoadException; 14 | 15 | 16 | public class Main { 17 | 18 | private static final Logger logger = 19 | Logger.getLogger(Main.class.getName()); 20 | 21 | public static void main(String[] args) { 22 | 23 | logger.info("Address book viewer application: Started"); 24 | List contacts = new ArrayList<>(); 25 | ContactLoader contactLoader = new ContactLoader(); 26 | 27 | try { 28 | contacts = contactLoader.parseXml("/Users/kkothagal/code/java9/input.xml"); 29 | } catch (ContactLoadException e) { 30 | logger.severe(e.getMessage()); 31 | System.exit(0); 32 | } 33 | 34 | SortUtil sortUtil = SortUtil.getProviderInstance(contacts.size()); 35 | if (sortUtil != null) { 36 | sortUtil.sortList(contacts); 37 | } 38 | System.out.println(contacts); 39 | logger.info("Address book viewer application: Completed"); 40 | } 41 | } -------------------------------------------------------------------------------- /07-services/src/packt.contact/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.contact { 2 | requires java.xml; 3 | exports packt.contact.model; 4 | exports packt.contact.util; 5 | } -------------------------------------------------------------------------------- /07-services/src/packt.contact/packt/contact/internal/XmlUtil.java: -------------------------------------------------------------------------------- 1 | package packt.contact.internal; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import javax.xml.parsers.DocumentBuilder; 7 | import javax.xml.parsers.DocumentBuilderFactory; 8 | import javax.xml.parsers.ParserConfigurationException; 9 | 10 | import org.w3c.dom.Document; 11 | import org.w3c.dom.Element; 12 | import org.w3c.dom.Node; 13 | import org.xml.sax.SAXException; 14 | 15 | public class XmlUtil { 16 | 17 | 18 | public Document loadXmlFile(String fileName) throws ParserConfigurationException, SAXException, IOException { 19 | File inputFile = new File(fileName); 20 | DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); 21 | DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); 22 | Document doc = dBuilder.parse(inputFile); 23 | doc.getDocumentElement().normalize(); 24 | return doc; 25 | } 26 | 27 | public String getElement(Node nNode, String tagName) { 28 | if (nNode.getNodeType() == Node.ELEMENT_NODE) { 29 | Element eElement = (Element) nNode; 30 | return eElement.getElementsByTagName(tagName).item(0).getTextContent(); 31 | } 32 | return ""; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /07-services/src/packt.contact/packt/contact/model/Address.java: -------------------------------------------------------------------------------- 1 | package packt.contact.model; 2 | 3 | public class Address { 4 | 5 | private String street; 6 | private String city; 7 | private String state; 8 | private String country; 9 | 10 | public String getStreet() { 11 | return street; 12 | } 13 | public void setStreet(String street) { 14 | this.street = street; 15 | } 16 | public String getCity() { 17 | return city; 18 | } 19 | public void setCity(String city) { 20 | this.city = city; 21 | } 22 | public String getState() { 23 | return state; 24 | } 25 | public void setState(String state) { 26 | this.state = state; 27 | } 28 | public String getCountry() { 29 | return country; 30 | } 31 | public void setCountry(String country) { 32 | this.country = country; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /07-services/src/packt.contact/packt/contact/model/Contact.java: -------------------------------------------------------------------------------- 1 | package packt.contact.model; 2 | 3 | public class Contact implements Comparable{ 4 | 5 | private String id; 6 | private String firstName; 7 | private String lastName; 8 | private String phone; 9 | private Address address; 10 | 11 | public Contact() {} 12 | 13 | public Contact(String id, String firstName, String lastName) { 14 | this.id = id; 15 | this.firstName = firstName; 16 | this.lastName = lastName; 17 | } 18 | 19 | public String getId() { 20 | return id; 21 | } 22 | 23 | 24 | 25 | public void setId(String id) { 26 | this.id = id; 27 | } 28 | 29 | 30 | 31 | public String getFirstName() { 32 | return firstName; 33 | } 34 | 35 | 36 | 37 | public void setFirstName(String firstName) { 38 | this.firstName = firstName; 39 | } 40 | 41 | 42 | 43 | public String getLastName() { 44 | return lastName; 45 | } 46 | 47 | 48 | 49 | public void setLastName(String lastName) { 50 | this.lastName = lastName; 51 | } 52 | 53 | 54 | 55 | public Address getAddress() { 56 | return address; 57 | } 58 | 59 | 60 | 61 | public void setAddress(Address address) { 62 | this.address = address; 63 | } 64 | 65 | 66 | 67 | public String getPhone() { 68 | return phone; 69 | } 70 | 71 | public void setPhone(String phone) { 72 | this.phone = phone; 73 | } 74 | 75 | public String toString() { 76 | return this.firstName + " " + this.lastName; 77 | } 78 | 79 | public int compareTo(Object other) { 80 | Contact otherContact = (Contact)other; 81 | return this.lastName.compareTo(otherContact.lastName); 82 | } 83 | 84 | 85 | } -------------------------------------------------------------------------------- /07-services/src/packt.contact/packt/contact/util/ContactLoadException.java: -------------------------------------------------------------------------------- 1 | package packt.contact.util; 2 | 3 | public class ContactLoadException extends Exception { 4 | 5 | private static final long serialVersionUID = 1900827267795855111L; 6 | 7 | public ContactLoadException() { 8 | super(); 9 | } 10 | 11 | public ContactLoadException(String message) { 12 | super(message); 13 | // TODO Auto-generated constructor stub 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /07-services/src/packt.contact/packt/contact/util/ContactLoader.java: -------------------------------------------------------------------------------- 1 | package packt.contact.util; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.ParserConfigurationException; 8 | 9 | import org.w3c.dom.Document; 10 | import org.w3c.dom.Element; 11 | import org.w3c.dom.Node; 12 | import org.w3c.dom.NodeList; 13 | import org.xml.sax.SAXException; 14 | 15 | import packt.contact.internal.XmlUtil; 16 | import packt.contact.model.Address; 17 | import packt.contact.model.Contact; 18 | 19 | public class ContactLoader { 20 | 21 | 22 | public List parseXml(String fileName) throws ContactLoadException { 23 | 24 | List contacts = new ArrayList<>(); 25 | XmlUtil xmlUtil = new XmlUtil(); 26 | 27 | 28 | Document doc; 29 | try { 30 | doc = xmlUtil.loadXmlFile(fileName); 31 | } catch (ParserConfigurationException | SAXException | IOException e) { 32 | throw new ContactLoadException("Unable to load Contact file"); 33 | } 34 | NodeList nList = doc.getElementsByTagName("contact"); 35 | for (int temp = 0; temp < nList.getLength(); temp++) { 36 | Node contactNode = nList.item(temp); 37 | if (contactNode.getNodeType() == Node.ELEMENT_NODE) { 38 | Element eElement = (Element) contactNode; 39 | 40 | Contact contact = new Contact(); 41 | contact.setFirstName(xmlUtil.getElement(contactNode, "firstname")); 42 | contact.setLastName(xmlUtil.getElement(contactNode, "lastname")); 43 | contact.setPhone(xmlUtil.getElement(contactNode, "phone")); 44 | Node addressNode = eElement.getElementsByTagName("address").item(0); 45 | 46 | Address address = new Address(); 47 | address.setStreet(xmlUtil.getElement(addressNode, "street")); 48 | address.setCity(xmlUtil.getElement(addressNode, "city")); 49 | address.setState(xmlUtil.getElement(addressNode, "state")); 50 | address.setCountry(xmlUtil.getElement(addressNode, "country")); 51 | contact.setAddress(address); 52 | 53 | contacts.add(contact); 54 | } 55 | } 56 | return contacts; 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /07-services/src/packt.sort.bubblesort/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.sort.bubblesort { 2 | 3 | requires packt.sortutil; 4 | provides packt.util.SortUtil with packt.util.impl.bubblesort.BubbleSortUtilImpl; 5 | } -------------------------------------------------------------------------------- /07-services/src/packt.sort.bubblesort/packt/util/impl/bubblesort/BubbleSortUtilImpl.java: -------------------------------------------------------------------------------- 1 | package packt.util.impl.bubblesort; 2 | 3 | import java.util.List; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | import packt.util.SortUtil; 7 | 8 | public class BubbleSortUtilImpl implements SortUtil { 9 | 10 | public int getIdealMaxInputLength() { 11 | return 4; 12 | } 13 | 14 | public List sortList(List list) { 15 | for (int outer = 0; outer < list.size() - 1; outer++) { 16 | for (int inner = 0; inner < list.size()-outer-1; inner++) { 17 | if (list.get(inner).compareTo(list.get(inner + 1)) > 0) { 18 | swap(list, inner); 19 | } 20 | } 21 | } 22 | return list; 23 | } 24 | 25 | private void swap(Listlist, int inner) { 26 | T temp = list.get(inner); 27 | list.set(inner, list.get(inner + 1)); 28 | list.set(inner + 1, temp); 29 | } 30 | 31 | 32 | 33 | } -------------------------------------------------------------------------------- /07-services/src/packt.sort.javasort/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.sort.javasort { 2 | 3 | requires packt.sortutil; 4 | provides packt.util.SortUtil with packt.util.impl.javasort.JavaSortUtilImpl; 5 | } -------------------------------------------------------------------------------- /07-services/src/packt.sort.javasort/packt/util/impl/javasort/JavaSortUtilImpl.java: -------------------------------------------------------------------------------- 1 | package packt.util.impl.javasort; 2 | 3 | import java.util.List; 4 | import java.util.ArrayList; 5 | import java.util.Collections; 6 | import java.util.Arrays; 7 | import packt.util.SortUtil; 8 | 9 | public class JavaSortUtilImpl implements SortUtil { 10 | 11 | public int getIdealMaxInputLength() { 12 | return Integer.MAX_VALUE; 13 | } 14 | 15 | public List sortList(List list) { 16 | 17 | Collections.sort(list); 18 | return list; 19 | } 20 | 21 | 22 | 23 | 24 | } -------------------------------------------------------------------------------- /07-services/src/packt.sortutil/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.sortutil { 2 | exports packt.util; 3 | uses packt.util.SortUtil; 4 | } -------------------------------------------------------------------------------- /07-services/src/packt.sortutil/packt/util/SortUtil.java: -------------------------------------------------------------------------------- 1 | package packt.util; 2 | 3 | import java.util.List; 4 | import java.util.Comparator; 5 | 6 | 7 | import java.util.ServiceLoader; 8 | import java.util.ServiceLoader.Provider; 9 | import java.util.ArrayList; 10 | import java.util.Arrays; 11 | import java.util.stream.Stream; 12 | 13 | public interface SortUtil { 14 | 15 | public List sortList(List list); 16 | 17 | public int getIdealMaxInputLength(); 18 | 19 | public static Iterable getAllProviders() { 20 | return ServiceLoader.load(SortUtil.class); 21 | } 22 | 23 | public static SortUtil getProviderInstance(int listSize) { 24 | Iterable sortUtils = ServiceLoader.load(SortUtil.class); 25 | for (SortUtil sortUtil : sortUtils) { 26 | if (listSize < sortUtil.getIdealMaxInputLength()) { 27 | return sortUtil; 28 | } 29 | } 30 | return null; 31 | } 32 | 33 | 34 | public static SortUtil getProviderInstanceLazy() { 35 | Stream> providers = ServiceLoader.load(SortUtil.class) 36 | .stream() 37 | .sorted(Comparator.comparing(p -> p.type().getName())); 38 | 39 | SortUtil util = providers.map(Provider::get) 40 | .findAny() 41 | .orElse(null); 42 | return util; 43 | } 44 | 45 | 46 | 47 | 48 | } -------------------------------------------------------------------------------- /09-module-patterns/01-seperate-interface-impl/src/consumer/app/Main.java: -------------------------------------------------------------------------------- 1 | package app; 2 | 3 | import pattern.one.external.Factory; 4 | import pattern.one.external.PublicInterface; 5 | 6 | public class Main { 7 | 8 | public static void main(String[] args) { 9 | Factory factory = new Factory(); 10 | PublicInterface obj = factory.getApiInstance(false); 11 | obj.publicApi(); 12 | 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /09-module-patterns/01-seperate-interface-impl/src/consumer/module-info.java: -------------------------------------------------------------------------------- 1 | module consumer { 2 | requires pattern.one; 3 | } -------------------------------------------------------------------------------- /09-module-patterns/01-seperate-interface-impl/src/pattern.one/module-info.java: -------------------------------------------------------------------------------- 1 | module pattern.one { 2 | exports pattern.one.external; 3 | } -------------------------------------------------------------------------------- /09-module-patterns/01-seperate-interface-impl/src/pattern.one/pattern/one/external/Factory.java: -------------------------------------------------------------------------------- 1 | package pattern.one.external; 2 | 3 | import pattern.one.internal.PrivateImplA; 4 | import pattern.one.internal.PrivateImplB; 5 | 6 | public class Factory { 7 | 8 | public PublicInterface getApiInstance(boolean selector) { 9 | if (selector) { 10 | return new PrivateImplA(); 11 | } 12 | return new PrivateImplB(); 13 | } 14 | 15 | 16 | 17 | 18 | } -------------------------------------------------------------------------------- /09-module-patterns/01-seperate-interface-impl/src/pattern.one/pattern/one/external/PublicInterface.java: -------------------------------------------------------------------------------- 1 | package pattern.one.external; 2 | 3 | public interface PublicInterface { 4 | 5 | public void publicApi(); 6 | 7 | 8 | } -------------------------------------------------------------------------------- /09-module-patterns/01-seperate-interface-impl/src/pattern.one/pattern/one/internal/PrivateImplA.java: -------------------------------------------------------------------------------- 1 | package pattern.one.internal; 2 | 3 | import pattern.one.external.PublicInterface; 4 | 5 | 6 | public class PrivateImplA implements PublicInterface { 7 | 8 | public void publicApi() { 9 | System.out.println("Called implementation in PrivateImplA"); 10 | } 11 | 12 | 13 | } -------------------------------------------------------------------------------- /09-module-patterns/01-seperate-interface-impl/src/pattern.one/pattern/one/internal/PrivateImplB.java: -------------------------------------------------------------------------------- 1 | package pattern.one.internal; 2 | 3 | import pattern.one.external.PublicInterface; 4 | 5 | 6 | public class PrivateImplB implements PublicInterface { 7 | 8 | public void publicApi() { 9 | System.out.println("Called implementation in PrivateImplB"); 10 | } 11 | 12 | 13 | } -------------------------------------------------------------------------------- /09-module-patterns/02-services/src/consumer/app/Main.java: -------------------------------------------------------------------------------- 1 | package app; 2 | 3 | import pattern.two.external.PublicInterface; 4 | 5 | import java.util.ServiceLoader; 6 | import java.util.ServiceLoader.Provider; 7 | 8 | 9 | public class Main { 10 | 11 | public static void main(String[] args) { 12 | Iterable impls = ServiceLoader.load(PublicInterface.class); 13 | for (PublicInterface i : impls) { 14 | i.publicApi(); 15 | } 16 | 17 | 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /09-module-patterns/02-services/src/consumer/module-info.java: -------------------------------------------------------------------------------- 1 | module consumer { 2 | requires pattern.two.service; 3 | uses pattern.two.external.PublicInterface; 4 | } -------------------------------------------------------------------------------- /09-module-patterns/02-services/src/pattern.two.implA/module-info.java: -------------------------------------------------------------------------------- 1 | module pattern.two.implA { 2 | requires pattern.two.service; 3 | provides pattern.two.external.PublicInterface with pattern.two.implA.ImplA; 4 | } -------------------------------------------------------------------------------- /09-module-patterns/02-services/src/pattern.two.implA/pattern/two/implA/ImplA.java: -------------------------------------------------------------------------------- 1 | package pattern.two.implA; 2 | 3 | import pattern.two.external.PublicInterface; 4 | 5 | 6 | public class ImplA implements PublicInterface { 7 | 8 | public void publicApi() { 9 | System.out.println("Called implementation in PrivateImplA"); 10 | } 11 | 12 | 13 | } -------------------------------------------------------------------------------- /09-module-patterns/02-services/src/pattern.two.implB/module-info.java: -------------------------------------------------------------------------------- 1 | module pattern.two.implB { 2 | requires pattern.two.service; 3 | provides pattern.two.external.PublicInterface with pattern.two.implB.ImplB; 4 | } -------------------------------------------------------------------------------- /09-module-patterns/02-services/src/pattern.two.implB/pattern/two/implB/ImplB.java: -------------------------------------------------------------------------------- 1 | package pattern.two.implB; 2 | 3 | import pattern.two.external.PublicInterface; 4 | 5 | 6 | public class ImplB implements PublicInterface { 7 | 8 | public void publicApi() { 9 | System.out.println("Called implementation in PrivateImplB"); 10 | } 11 | 12 | 13 | } -------------------------------------------------------------------------------- /09-module-patterns/02-services/src/pattern.two.service/module-info.java: -------------------------------------------------------------------------------- 1 | module pattern.two.service { 2 | exports pattern.two.external; 3 | } -------------------------------------------------------------------------------- /09-module-patterns/02-services/src/pattern.two.service/pattern/two/external/PublicInterface.java: -------------------------------------------------------------------------------- 1 | package pattern.two.external; 2 | 3 | public interface PublicInterface { 4 | 5 | public void publicApi(); 6 | 7 | 8 | } -------------------------------------------------------------------------------- /09-module-patterns/03-optional-dependencies/src/consumer/app/Main.java: -------------------------------------------------------------------------------- 1 | package app; 2 | 3 | import pattern.three.external.Util; 4 | public class Main { 5 | 6 | public static void main(String[] args) { 7 | Util util = new Util(); 8 | util.utilMethod(); 9 | } 10 | } -------------------------------------------------------------------------------- /09-module-patterns/03-optional-dependencies/src/consumer/module-info.java: -------------------------------------------------------------------------------- 1 | module consumer { 2 | requires pattern.three; 3 | } -------------------------------------------------------------------------------- /09-module-patterns/03-optional-dependencies/src/pattern.three.optlib/module-info.java: -------------------------------------------------------------------------------- 1 | module pattern.three.optlib { 2 | exports pattern.three.lib; 3 | 4 | } -------------------------------------------------------------------------------- /09-module-patterns/03-optional-dependencies/src/pattern.three.optlib/pattern/three/lib/LibImpl.java: -------------------------------------------------------------------------------- 1 | package pattern.three.lib; 2 | 3 | 4 | 5 | public class LibImpl { 6 | 7 | public void publicApi() { 8 | System.out.println("Called API method in LibImpl"); 9 | } 10 | 11 | 12 | } -------------------------------------------------------------------------------- /09-module-patterns/03-optional-dependencies/src/pattern.three/module-info.java: -------------------------------------------------------------------------------- 1 | module pattern.three { 2 | requires static pattern.three.optlib; 3 | exports pattern.three.external; 4 | } -------------------------------------------------------------------------------- /09-module-patterns/03-optional-dependencies/src/pattern.three/pattern/three/external/Util.java: -------------------------------------------------------------------------------- 1 | package pattern.three.external; 2 | 3 | import pattern.three.lib.LibImpl; 4 | 5 | public class Util { 6 | 7 | public void utilMethod() { 8 | 9 | try { 10 | Class clazz = Class.forName("pattern.three.lib.LibImpl"); 11 | LibImpl impl = 12 | (LibImpl) clazz.getConstructor().newInstance(); 13 | impl.publicApi(); 14 | 15 | } catch (ReflectiveOperationException e) { 16 | System.out.println("Did not find the Impl class module"); 17 | } 18 | } 19 | 20 | 21 | } -------------------------------------------------------------------------------- /09-module-patterns/03-optional-dependencies/src/pattern.two.implB/module-info.java: -------------------------------------------------------------------------------- 1 | module pattern.two.implB { 2 | requires pattern.two.service; 3 | provides pattern.two.external.PublicInterface with pattern.two.implB.ImplB; 4 | } -------------------------------------------------------------------------------- /09-module-patterns/03-optional-dependencies/src/pattern.two.implB/pattern/two/implB/ImplB.java: -------------------------------------------------------------------------------- 1 | package pattern.two.implB; 2 | 3 | import pattern.two.external.PublicInterface; 4 | 5 | 6 | public class ImplB implements PublicInterface { 7 | 8 | public void publicApi() { 9 | System.out.println("Called implementation in PrivateImplB"); 10 | } 11 | 12 | 13 | } -------------------------------------------------------------------------------- /09-module-patterns/04-optional-dependencies-with-services/src/consumer/app/Main.java: -------------------------------------------------------------------------------- 1 | package app; 2 | 3 | import pattern.four.external.Util; 4 | public class Main { 5 | 6 | public static void main(String[] args) { 7 | Util util = new Util(); 8 | util.utilMethod(); 9 | } 10 | } -------------------------------------------------------------------------------- /09-module-patterns/04-optional-dependencies-with-services/src/consumer/module-info.java: -------------------------------------------------------------------------------- 1 | module consumer { 2 | requires pattern.four; 3 | } -------------------------------------------------------------------------------- /09-module-patterns/04-optional-dependencies-with-services/src/pattern.four.optlib/module-info.java: -------------------------------------------------------------------------------- 1 | module pattern.four.optlib { 2 | requires pattern.four; 3 | provides pattern.four.external.LibInterface 4 | with pattern.four.lib.LibImpl; 5 | } -------------------------------------------------------------------------------- /09-module-patterns/04-optional-dependencies-with-services/src/pattern.four.optlib/pattern/four/lib/LibImpl.java: -------------------------------------------------------------------------------- 1 | package pattern.four.lib; 2 | 3 | import pattern.four.external.LibInterface; 4 | 5 | public class LibImpl implements LibInterface { 6 | 7 | public void publicApi() { 8 | System.out.println("Called API method in Service"); 9 | } 10 | } -------------------------------------------------------------------------------- /09-module-patterns/04-optional-dependencies-with-services/src/pattern.four/module-info.java: -------------------------------------------------------------------------------- 1 | module pattern.four { 2 | exports pattern.four.external; 3 | uses pattern.four.external.LibInterface; 4 | } -------------------------------------------------------------------------------- /09-module-patterns/04-optional-dependencies-with-services/src/pattern.four/pattern/four/external/LibInterface.java: -------------------------------------------------------------------------------- 1 | package pattern.four.external; 2 | 3 | public interface LibInterface { 4 | 5 | void publicApi(); 6 | 7 | } -------------------------------------------------------------------------------- /09-module-patterns/04-optional-dependencies-with-services/src/pattern.four/pattern/four/external/Util.java: -------------------------------------------------------------------------------- 1 | package pattern.four.external; 2 | 3 | import pattern.four.internal.LibInterface; 4 | 5 | public class Util { 6 | 7 | public void utilMethod() { 8 | Iterable libInstances = ServiceLoader.load(LibInterface.class); 9 | for (LibInterface libInstance : libInstances) { 10 | libInstance.publicApi(); 11 | } 12 | 13 | 14 | } 15 | 16 | 17 | } -------------------------------------------------------------------------------- /09-module-patterns/06-open-modules/src/consumer/app/Main.java: -------------------------------------------------------------------------------- 1 | package app; 2 | 3 | import java.lang.reflect.Constructor; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | try { 9 | Class clazz = Class.forName("pattern.six.internal.Contact"); 10 | Constructor ctor = clazz.getConstructor(); 11 | Object object = ctor.newInstance(new Object[] { }); 12 | System.out.println("Successfully created object using reflection"); 13 | } catch (ReflectiveOperationException e) { 14 | System.out.println("Did not find the Impl class module"); 15 | } 16 | 17 | } 18 | } -------------------------------------------------------------------------------- /09-module-patterns/06-open-modules/src/consumer/module-info.java: -------------------------------------------------------------------------------- 1 | module consumer { 2 | requires pattern.six; 3 | } -------------------------------------------------------------------------------- /09-module-patterns/06-open-modules/src/pattern.six/module-info.java: -------------------------------------------------------------------------------- 1 | open module pattern.six { 2 | 3 | } -------------------------------------------------------------------------------- /09-module-patterns/06-open-modules/src/pattern.six/pattern/six/internal/Contact.java: -------------------------------------------------------------------------------- 1 | package pattern.six.internal; 2 | 3 | 4 | public class Contact { 5 | 6 | private String id; 7 | private String firstName; 8 | private String lastName; 9 | private String phone; 10 | 11 | public Contact() {} 12 | 13 | public Contact(String id, String firstName, String lastName) { 14 | this.id = id; 15 | this.firstName = firstName; 16 | this.lastName = lastName; 17 | } 18 | 19 | public String getId() { 20 | return id; 21 | } 22 | 23 | public void setId(String id) { 24 | this.id = id; 25 | } 26 | 27 | public String getFirstName() { 28 | return firstName; 29 | } 30 | 31 | public void setFirstName(String firstName) { 32 | this.firstName = firstName; 33 | } 34 | 35 | public String getLastName() { 36 | return lastName; 37 | } 38 | 39 | public void setLastName(String lastName) { 40 | this.lastName = lastName; 41 | } 42 | 43 | public String getPhone() { 44 | return phone; 45 | } 46 | 47 | public void setPhone(String phone) { 48 | this.phone = phone; 49 | } 50 | 51 | public String toString() { 52 | return this.firstName + " " + this.lastName; 53 | } 54 | 55 | 56 | 57 | } -------------------------------------------------------------------------------- /09-module-patterns/07-maven-integration/util/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | util 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /09-module-patterns/07-maven-integration/util/bin/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | util 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /09-module-patterns/09-aggregator-and-facade-modules/src/consumer/app/Main.java: -------------------------------------------------------------------------------- 1 | package app; 2 | 3 | import pattern.nine.external.FacadeApi; 4 | import module.two.external.ApiTwo; 5 | 6 | public class Main { 7 | 8 | public static void main(String[] args) { 9 | FacadeApi facade = new FacadeApi(); 10 | ApiTwo apiTwo = new ApiTwo(); 11 | 12 | facade.facadeMethod("one"); // Calling the API through the facade 13 | apiTwo.apiMethod(); // Calling the other API directly 14 | 15 | 16 | } 17 | } -------------------------------------------------------------------------------- /09-module-patterns/09-aggregator-and-facade-modules/src/consumer/module-info.java: -------------------------------------------------------------------------------- 1 | module consumer { 2 | requires pattern.nine.facade; 3 | } -------------------------------------------------------------------------------- /09-module-patterns/09-aggregator-and-facade-modules/src/module.one/module-info.java: -------------------------------------------------------------------------------- 1 | module module.one { 2 | exports module.one.external; 3 | } -------------------------------------------------------------------------------- /09-module-patterns/09-aggregator-and-facade-modules/src/module.one/module/one/external/ApiOne.java: -------------------------------------------------------------------------------- 1 | package module.one.external; 2 | 3 | 4 | public class ApiOne { 5 | 6 | public void apiMethod() { 7 | System.out.println("Module one API called"); 8 | } 9 | } -------------------------------------------------------------------------------- /09-module-patterns/09-aggregator-and-facade-modules/src/module.two/module-info.java: -------------------------------------------------------------------------------- 1 | module module.two { 2 | exports module.two.external; 3 | } -------------------------------------------------------------------------------- /09-module-patterns/09-aggregator-and-facade-modules/src/module.two/module/two/external/ApiTwo.java: -------------------------------------------------------------------------------- 1 | package module.two.external; 2 | 3 | 4 | public class ApiTwo { 5 | 6 | public void apiMethod() { 7 | System.out.println("Module two API called"); 8 | } 9 | } -------------------------------------------------------------------------------- /09-module-patterns/09-aggregator-and-facade-modules/src/pattern.nine.facade/module-info.java: -------------------------------------------------------------------------------- 1 | module pattern.nine.facade { 2 | requires transitive module.one; 3 | requires transitive module.two; 4 | exports pattern.nine.external; 5 | } -------------------------------------------------------------------------------- /09-module-patterns/09-aggregator-and-facade-modules/src/pattern.nine.facade/pattern/nine/external/FacadeApi.java: -------------------------------------------------------------------------------- 1 | package pattern.nine.external; 2 | 3 | import module.one.external.ApiOne; 4 | import module.two.external.ApiTwo; 5 | public class FacadeApi { 6 | 7 | ApiOne apiOne = new ApiOne(); 8 | ApiTwo apiTwo = new ApiTwo(); 9 | 10 | 11 | public void facadeMethod(String apiChoice) { 12 | 13 | if ("one".equals(apiChoice)) { 14 | apiOne.apiMethod(); 15 | } 16 | else if ("two".equals(apiChoice)) { 17 | apiTwo.apiMethod(); 18 | } 19 | 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /10-migrating-application/01-app-migration/lib/commons-collections4-4.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koushikkothagal/Modular-Programming-in-Java-9/153ff1ef2b64497aca4a5cc883b7ca4c2a2bf815/10-migrating-application/01-app-migration/lib/commons-collections4-4.1.jar -------------------------------------------------------------------------------- /10-migrating-application/01-app-migration/src/com/packt/sortstrings/app/App.java: -------------------------------------------------------------------------------- 1 | package com.packt.sortstrings.app; 2 | 3 | import java.util.logging.Logger; 4 | 5 | import com.packt.sortstrings.data.ShoppingBag; 6 | import com.packt.sortstrings.input.UserInputUtil; 7 | 8 | public class App { 9 | 10 | private static final Logger logger = 11 | Logger.getLogger(App.class.getName()); 12 | 13 | public static void main(String[] args) { 14 | 15 | logger.info("Shopping Bag application: Started"); 16 | 17 | ShoppingBag shoppingBag = new ShoppingBag(); 18 | UserInputUtil userInputUtil = new UserInputUtil(); 19 | String itemName; 20 | do { 21 | 22 | itemName = userInputUtil.getUserInput("Enter item (Type '" + ShoppingBag.END_TOKEN + "' when done): "); 23 | shoppingBag.addToBag(itemName); 24 | 25 | } while (!ShoppingBag.END_TOKEN.equals(itemName)); 26 | userInputUtil.close(); 27 | shoppingBag.prettyPrintBag(); 28 | logger.info("Shopping Bag application: Completed"); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /10-migrating-application/01-app-migration/src/com/packt/sortstrings/data/ShoppingBag.java: -------------------------------------------------------------------------------- 1 | package com.packt.sortstrings.data; 2 | 3 | import org.apache.commons.collections4.Bag; 4 | import org.apache.commons.collections4.bag.HashBag; 5 | 6 | public class ShoppingBag { 7 | 8 | public static String END_TOKEN = "end"; 9 | private Bag bag = new HashBag<>(); 10 | 11 | public boolean addToBag(String itemName) { 12 | return (END_TOKEN.equals(itemName)) || this.bag.add(itemName); 13 | } 14 | 15 | public void prettyPrintBag() { 16 | System.out.println(); 17 | System.out.println("Shopping Bag Contents"); 18 | System.out.println("------------------------"); 19 | this.bag.uniqueSet() 20 | .forEach(item -> { 21 | System.out.println(item + " " + bag.getCount(item)); 22 | System.out.println("------------------------"); 23 | }); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /10-migrating-application/01-app-migration/src/com/packt/sortstrings/input/UserInputUtil.java: -------------------------------------------------------------------------------- 1 | package com.packt.sortstrings.input; 2 | 3 | import java.util.Scanner; 4 | 5 | public class UserInputUtil { 6 | Scanner scanner = new Scanner(System.in); 7 | 8 | public String getUserInput(String prompt) { 9 | System.out.print(prompt); 10 | return scanner.nextLine(); 11 | } 12 | 13 | public void close() { 14 | scanner.close(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /10-migrating-application/02-non-standard-api/src/packt/app/App.java: -------------------------------------------------------------------------------- 1 | package com.packt.app; 2 | 3 | 4 | import sun.misc.BASE64Encoder; 5 | import sun.util.calendar.CalendarUtils; 6 | 7 | public class App { 8 | 9 | public static void main(String[] args) { 10 | BASE64Encoder enc = new BASE64Encoder(); 11 | CalendarUtils.isGregorianLeapYear(2018); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /10-migrating-application/02-non-standard-api/src/packt/app/AppFixed.java: -------------------------------------------------------------------------------- 1 | package com.packt.app; 2 | 3 | 4 | import java.util.Base64; 5 | import java.util.Base64.Encoder; 6 | import sun.util.calendar.CalendarUtils; 7 | 8 | public class AppFixed { 9 | 10 | public static void main(String[] args) { 11 | Encoder enc = Base64.getEncoder(); 12 | CalendarUtils.isGregorianLeapYear(2018); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /11-migrating-application/01-legacy-app/lib/commons-collections4-4.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koushikkothagal/Modular-Programming-in-Java-9/153ff1ef2b64497aca4a5cc883b7ca4c2a2bf815/11-migrating-application/01-legacy-app/lib/commons-collections4-4.1.jar -------------------------------------------------------------------------------- /11-migrating-application/01-legacy-app/src/com/packt/shoppingbag/app/App.java: -------------------------------------------------------------------------------- 1 | package com.packt.shoppingbag.app; 2 | 3 | import java.util.logging.Logger; 4 | 5 | import com.packt.shoppingbag.data.ShoppingBag; 6 | import com.packt.shoppingbag.input.UserInputUtil; 7 | 8 | public class App { 9 | 10 | private static final Logger logger = 11 | Logger.getLogger(App.class.getName()); 12 | 13 | public static void main(String[] args) { 14 | 15 | logger.info("Shopping Bag application: Started"); 16 | 17 | ShoppingBag shoppingBag = new ShoppingBag(); 18 | UserInputUtil userInputUtil = new UserInputUtil(); 19 | String itemName; 20 | do { 21 | 22 | itemName = userInputUtil.getUserInput("Enter item (Type '" + ShoppingBag.END_TOKEN + "' when done): "); 23 | shoppingBag.addToBag(itemName); 24 | 25 | } while (!ShoppingBag.END_TOKEN.equals(itemName)); 26 | userInputUtil.close(); 27 | shoppingBag.prettyPrintBag(); 28 | logger.info("Shopping Bag application: Completed"); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /11-migrating-application/01-legacy-app/src/com/packt/shoppingbag/data/ShoppingBag.java: -------------------------------------------------------------------------------- 1 | package com.packt.shoppingbag.data; 2 | 3 | import org.apache.commons.collections4.Bag; 4 | import org.apache.commons.collections4.bag.HashBag; 5 | 6 | public class ShoppingBag { 7 | 8 | public static String END_TOKEN = "end"; 9 | private Bag bag = new HashBag<>(); 10 | 11 | public boolean addToBag(String itemName) { 12 | return (END_TOKEN.equals(itemName)) || this.bag.add(itemName); 13 | } 14 | 15 | public void prettyPrintBag() { 16 | System.out.println(); 17 | System.out.println("Shopping Bag Contents"); 18 | System.out.println("------------------------"); 19 | this.bag.uniqueSet() 20 | .forEach(item -> { 21 | System.out.println(item + " " + bag.getCount(item)); 22 | System.out.println("------------------------"); 23 | }); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /11-migrating-application/01-legacy-app/src/com/packt/shoppingbag/input/UserInputUtil.java: -------------------------------------------------------------------------------- 1 | package com.packt.shoppingbag.input; 2 | 3 | import java.util.Scanner; 4 | 5 | public class UserInputUtil { 6 | Scanner scanner = new Scanner(System.in); 7 | 8 | public String getUserInput(String prompt) { 9 | System.out.print(prompt); 10 | return scanner.nextLine(); 11 | } 12 | 13 | public void close() { 14 | scanner.close(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /11-migrating-application/02-migrating-to-one-module/lib/commons-collections4-4.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koushikkothagal/Modular-Programming-in-Java-9/153ff1ef2b64497aca4a5cc883b7ca4c2a2bf815/11-migrating-application/02-migrating-to-one-module/lib/commons-collections4-4.1.jar -------------------------------------------------------------------------------- /11-migrating-application/02-migrating-to-one-module/src/packt.shoppingbag/com/packt/shoppingbag/app/App.java: -------------------------------------------------------------------------------- 1 | package com.packt.shoppingbag.app; 2 | 3 | import java.util.logging.Logger; 4 | 5 | import com.packt.shoppingbag.data.ShoppingBag; 6 | import com.packt.shoppingbag.input.UserInputUtil; 7 | 8 | public class App { 9 | 10 | private static final Logger logger = 11 | Logger.getLogger(App.class.getName()); 12 | 13 | public static void main(String[] args) { 14 | 15 | logger.info("Shopping Bag application: Started"); 16 | 17 | ShoppingBag shoppingBag = new ShoppingBag(); 18 | UserInputUtil userInputUtil = new UserInputUtil(); 19 | String itemName; 20 | do { 21 | 22 | itemName = userInputUtil.getUserInput("Enter item (Type '" + ShoppingBag.END_TOKEN + "' when done): "); 23 | shoppingBag.addToBag(itemName); 24 | 25 | } while (!ShoppingBag.END_TOKEN.equals(itemName)); 26 | userInputUtil.close(); 27 | shoppingBag.prettyPrintBag(); 28 | logger.info("Shopping Bag application: Completed"); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /11-migrating-application/02-migrating-to-one-module/src/packt.shoppingbag/com/packt/shoppingbag/data/ShoppingBag.java: -------------------------------------------------------------------------------- 1 | package com.packt.shoppingbag.data; 2 | 3 | import org.apache.commons.collections4.Bag; 4 | import org.apache.commons.collections4.bag.HashBag; 5 | 6 | public class ShoppingBag { 7 | 8 | public static String END_TOKEN = "end"; 9 | private Bag bag = new HashBag<>(); 10 | 11 | public boolean addToBag(String itemName) { 12 | return (END_TOKEN.equals(itemName)) || this.bag.add(itemName); 13 | } 14 | 15 | public void prettyPrintBag() { 16 | System.out.println(); 17 | System.out.println("Shopping Bag Contents"); 18 | System.out.println("------------------------"); 19 | this.bag.uniqueSet() 20 | .forEach(item -> { 21 | System.out.println(item + " " + bag.getCount(item)); 22 | System.out.println("------------------------"); 23 | }); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /11-migrating-application/02-migrating-to-one-module/src/packt.shoppingbag/com/packt/shoppingbag/input/UserInputUtil.java: -------------------------------------------------------------------------------- 1 | package com.packt.shoppingbag.input; 2 | 3 | import java.util.Scanner; 4 | 5 | public class UserInputUtil { 6 | Scanner scanner = new Scanner(System.in); 7 | 8 | public String getUserInput(String prompt) { 9 | System.out.print(prompt); 10 | return scanner.nextLine(); 11 | } 12 | 13 | public void close() { 14 | scanner.close(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /11-migrating-application/02-migrating-to-one-module/src/packt.shoppingbag/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.shoppingbag { 2 | requires java.logging; 3 | requires commons.collections4; 4 | } -------------------------------------------------------------------------------- /11-migrating-application/03-splitting-modules/lib/commons-collections4-4.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koushikkothagal/Modular-Programming-in-Java-9/153ff1ef2b64497aca4a5cc883b7ca4c2a2bf815/11-migrating-application/03-splitting-modules/lib/commons-collections4-4.1.jar -------------------------------------------------------------------------------- /11-migrating-application/03-splitting-modules/src/packt.app/com/packt/app/App.java: -------------------------------------------------------------------------------- 1 | package com.packt.app; 2 | 3 | import java.util.logging.Logger; 4 | 5 | import com.packt.shoppingbag.ShoppingBag; 6 | import com.packt.userinput.UserInputUtil; 7 | 8 | public class App { 9 | 10 | private static final Logger logger = 11 | Logger.getLogger(App.class.getName()); 12 | 13 | public static void main(String[] args) { 14 | 15 | logger.info("Shopping Bag application: Started"); 16 | 17 | ShoppingBag shoppingBag = new ShoppingBag(); 18 | UserInputUtil userInputUtil = new UserInputUtil(); 19 | String itemName; 20 | do { 21 | 22 | itemName = userInputUtil.getUserInput("Enter item (Type '" + ShoppingBag.END_TOKEN + "' when done): "); 23 | shoppingBag.addToBag(itemName); 24 | 25 | } while (!ShoppingBag.END_TOKEN.equals(itemName)); 26 | userInputUtil.close(); 27 | shoppingBag.prettyPrintBag(); 28 | logger.info("Shopping Bag application: Completed"); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /11-migrating-application/03-splitting-modules/src/packt.app/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.app { 2 | requires java.logging; 3 | requires packt.shoppingbag; 4 | requires packt.userinput; 5 | } -------------------------------------------------------------------------------- /11-migrating-application/03-splitting-modules/src/packt.shoppingbag/com/packt/shoppingbag/ShoppingBag.java: -------------------------------------------------------------------------------- 1 | package com.packt.shoppingbag; 2 | 3 | import org.apache.commons.collections4.Bag; 4 | import org.apache.commons.collections4.bag.HashBag; 5 | 6 | public class ShoppingBag { 7 | 8 | public static String END_TOKEN = "end"; 9 | private Bag bag = new HashBag<>(); 10 | 11 | public boolean addToBag(String itemName) { 12 | return (END_TOKEN.equals(itemName)) || this.bag.add(itemName); 13 | } 14 | 15 | public void prettyPrintBag() { 16 | System.out.println(); 17 | System.out.println("Shopping Bag Contents"); 18 | System.out.println("------------------------"); 19 | this.bag.uniqueSet() 20 | .forEach(item -> { 21 | System.out.println(item + " " + bag.getCount(item)); 22 | System.out.println("------------------------"); 23 | }); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /11-migrating-application/03-splitting-modules/src/packt.shoppingbag/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.shoppingbag { 2 | requires commons.collections4; 3 | exports com.packt.shoppingbag; 4 | } -------------------------------------------------------------------------------- /11-migrating-application/03-splitting-modules/src/packt.userinput/com/packt/userinput/UserInputUtil.java: -------------------------------------------------------------------------------- 1 | package com.packt.userinput; 2 | 3 | import java.util.Scanner; 4 | 5 | public class UserInputUtil { 6 | Scanner scanner = new Scanner(System.in); 7 | 8 | public String getUserInput(String prompt) { 9 | System.out.print(prompt); 10 | return scanner.nextLine(); 11 | } 12 | 13 | public void close() { 14 | scanner.close(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /11-migrating-application/03-splitting-modules/src/packt.userinput/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.userinput { 2 | exports com.packt.userinput; 3 | } -------------------------------------------------------------------------------- /11-migrating-application/04-multirelease-jars/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Multi-Release: true -------------------------------------------------------------------------------- /11-migrating-application/04-multirelease-jars/base/src/packt/mylib/PrintList.java: -------------------------------------------------------------------------------- 1 | package packt.mylib; 2 | 3 | import java.util.List; 4 | 5 | public class PrintList { 6 | 7 | 8 | public void print(List list) { 9 | for (int i = 0; i < list.size(); i++) { 10 | System.out.println(list.get(i)); 11 | } 12 | } 13 | 14 | 15 | } -------------------------------------------------------------------------------- /11-migrating-application/04-multirelease-jars/java9/src/packt.mylib/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.mylib { 2 | exports packt.mylib; 3 | } -------------------------------------------------------------------------------- /11-migrating-application/04-multirelease-jars/java9/src/packt.mylib/packt/mylib/PrintList.java: -------------------------------------------------------------------------------- 1 | package packt.mylib; 2 | 3 | import java.util.List; 4 | 5 | public class PrintList { 6 | 7 | 8 | public void print(List list) { 9 | list.forEach(System.out::println); 10 | } 11 | 12 | 13 | } -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | root 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/lib/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/lib/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | lib 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/lib/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=9 3 | org.eclipse.jdt.core.compiler.compliance=9 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=9 6 | -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/lib/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/lib/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.packt 7 | root 8 | 1.0-SNAPSHOT 9 | 10 | com.packt 11 | lib 12 | 1.0-SNAPSHOT 13 | lib 14 | http://maven.apache.org 15 | 16 | 17 | -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/lib/src/main/java/com/packt/lib/Lib.java: -------------------------------------------------------------------------------- 1 | package com.packt.lib; 2 | 3 | 4 | public class Lib 5 | { 6 | public void sampleMethod() 7 | { 8 | System.out.println( "Library method called!" ); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/lib/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.lib { 2 | exports com.packt.lib; 3 | } -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/lib/target/classes/com/packt/lib/Lib.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koushikkothagal/Modular-Programming-in-Java-9/153ff1ef2b64497aca4a5cc883b7ca4c2a2bf815/12-build-tools-and-testing/01-maven-integration/root/lib/target/classes/com/packt/lib/Lib.class -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/main/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/main/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | main 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/main/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=9 3 | org.eclipse.jdt.core.compiler.compliance=9 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=9 6 | -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/main/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/main/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.packt 7 | root 8 | 1.0-SNAPSHOT 9 | 10 | com.packt 11 | main 12 | 1.0-SNAPSHOT 13 | main 14 | 15 | 16 | com.packt 17 | lib 18 | 1.0-SNAPSHOT 19 | 20 | 21 | 22 | 23 | 24 | org.codehaus.mojo 25 | exec-maven-plugin 26 | 1.6.0 27 | 28 | 29 | 30 | exec 31 | 32 | 33 | 34 | 35 | ${JAVA_HOME}/bin/java 36 | 37 | --module-path 38 | 39 | --module 40 | packt.main/com.packt.App 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/main/src/main/java/com/packt/App.java: -------------------------------------------------------------------------------- 1 | package com.packt; 2 | 3 | import com.packt.lib.Lib; 4 | 5 | /** 6 | * Hello world! 7 | * 8 | */ 9 | public class App 10 | { 11 | public static void main( String[] args ) 12 | { 13 | Lib lib = new Lib(); 14 | lib.sampleMethod(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/main/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.main { 2 | requires packt.lib; 3 | } -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/main/target/classes/com/packt/App.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koushikkothagal/Modular-Programming-in-Java-9/153ff1ef2b64497aca4a5cc883b7ca4c2a2bf815/12-build-tools-and-testing/01-maven-integration/root/main/target/classes/com/packt/App.class -------------------------------------------------------------------------------- /12-build-tools-and-testing/01-maven-integration/root/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.packt 5 | root 6 | pom 7 | 1.0-SNAPSHOT 8 | root 9 | http://maven.apache.org 10 | 11 | 12 | main 13 | lib 14 | 15 | 16 | 17 | 18 | 19 | 20 | org.apache.maven.plugins 21 | maven-compiler-plugin 22 | 3.6.2 23 | 24 | 9 25 | 26 | 27 | 28 | org.codehaus.mojo 29 | exec-maven-plugin 30 | 1.6.0 31 | 32 | 33 | 34 | exec 35 | 36 | 37 | 38 | 39 | ${JAVA_HOME}/bin/java 40 | 41 | --module-path 42 | 43 | --module 44 | packt.main/com.packt.App 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /12-build-tools-and-testing/02-testing/lib/hamcrest-core-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koushikkothagal/Modular-Programming-in-Java-9/153ff1ef2b64497aca4a5cc883b7ca4c2a2bf815/12-build-tools-and-testing/02-testing/lib/hamcrest-core-1.3.jar -------------------------------------------------------------------------------- /12-build-tools-and-testing/02-testing/lib/junit-4.12.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koushikkothagal/Modular-Programming-in-Java-9/153ff1ef2b64497aca4a5cc883b7ca4c2a2bf815/12-build-tools-and-testing/02-testing/lib/junit-4.12.jar -------------------------------------------------------------------------------- /12-build-tools-and-testing/02-testing/packt.util.test.SortUtilTest: -------------------------------------------------------------------------------- 1 | JUnit version 4.12 2 | 3 | Time: 0.001 4 | 5 | OK (0 tests) 6 | 7 | -------------------------------------------------------------------------------- /12-build-tools-and-testing/02-testing/src/packt.sortutil.test/module-info.java: -------------------------------------------------------------------------------- 1 | open module packt.sortutil.test { 2 | requires packt.sortutil; 3 | requires junit; 4 | } -------------------------------------------------------------------------------- /12-build-tools-and-testing/02-testing/src/packt.sortutil.test/packt/util/test/SortUtilTest.java: -------------------------------------------------------------------------------- 1 | package packt.util.test; 2 | 3 | import java.util.List; 4 | 5 | 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | import org.junit.Test; 9 | import org.junit.Before; 10 | 11 | import packt.util.SortUtil; 12 | 13 | public class SortUtilTest { 14 | 15 | private SortUtil sortUtil; 16 | @Before public void setUp() { 17 | sortUtil = new SortUtil(); 18 | 19 | } 20 | 21 | @Test 22 | public void testReturnsSameSize() { 23 | List out = sortUtil.sortList(Arrays.asList("b", "a", "c")); 24 | SortUtil sortUtil = new SortUtil(); 25 | assert out.size() == 3; 26 | } 27 | 28 | @Test 29 | public void sortsList() { 30 | List out = sortUtil.sortList(Arrays.asList("b", "a", "c")); 31 | assert "a".equals(out.get(0)); 32 | assert "b".equals(out.get(1)); 33 | assert "c".equals(out.get(2)); 34 | } 35 | 36 | 37 | } -------------------------------------------------------------------------------- /12-build-tools-and-testing/02-testing/src/packt.sortutil.test/packt/util/test/SortUtilTestMain.java: -------------------------------------------------------------------------------- 1 | package packt.util.test; 2 | 3 | import java.util.List; 4 | 5 | 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | 9 | import packt.util.SortUtil; 10 | 11 | public class SortUtilTestMain { 12 | public static void main(String[] args) { 13 | SortUtil sortUtil = new SortUtil(); 14 | List out = sortUtil.sortList(Arrays.asList("b", "a", "c")); 15 | assert out.size() == 3; 16 | assert "a".equals(out.get(0)); 17 | assert "b".equals(out.get(1)); 18 | assert "c".equals(out.get(2)); 19 | } 20 | } -------------------------------------------------------------------------------- /12-build-tools-and-testing/02-testing/src/packt.sortutil/module-info.java: -------------------------------------------------------------------------------- 1 | module packt.sortutil { 2 | exports packt.util; 3 | } -------------------------------------------------------------------------------- /12-build-tools-and-testing/02-testing/src/packt.sortutil/packt/util/SortUtil.java: -------------------------------------------------------------------------------- 1 | package packt.util; 2 | 3 | import java.util.List; 4 | 5 | import packt.util.impl.BubbleSortUtilImpl; 6 | 7 | 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | 11 | public class SortUtil { 12 | 13 | private BubbleSortUtilImpl sortImpl = new BubbleSortUtilImpl(); 14 | 15 | public List sortList(List list) { 16 | return this.sortImpl.sortList(list); 17 | } 18 | 19 | 20 | 21 | 22 | } -------------------------------------------------------------------------------- /12-build-tools-and-testing/02-testing/src/packt.sortutil/packt/util/impl/BubbleSortUtilImpl.java: -------------------------------------------------------------------------------- 1 | package packt.util.impl; 2 | 3 | import java.util.List; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | 7 | public class BubbleSortUtilImpl { 8 | 9 | @SuppressWarnings("unchecked") 10 | public List sortList(List list) { 11 | for (int outer = 0; outer < list.size() - 1; outer++) { 12 | for (int inner = 0; inner < list.size()-outer-1; inner++) { 13 | if (list.get(inner).compareTo(list.get(inner + 1)) > 0) { 14 | swap(list, inner); 15 | } 16 | } 17 | } 18 | return list; 19 | } 20 | 21 | private void swap(Listlist, int inner) { 22 | T temp = list.get(inner); 23 | list.set(inner, list.get(inner + 1)); 24 | list.set(inner + 1, temp); 25 | } 26 | 27 | 28 | 29 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Modular-Programming-in-Java-9 -------------------------------------------------------------------------------- /input.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Edsger 5 | Dijkstra 6 |
7 | 5612 8 | AZ 9 | Eindhoven 10 | Netherlands 11 |
12 | 345-678-9012 13 |
14 | 15 | Alan 16 | Turing 17 |
18 | Oxford Rd 19 | M13 9PL 20 | Manchester 21 | England 22 |
23 | 456-789-0123 24 |
25 | 26 | Ada 27 | Lovelace 28 |
29 | Marylebone St 30 | Marylebone 31 | London 32 | England 33 |
34 | 234-567-8901 35 |
36 | 37 | Charles 38 | Babbage 39 |
40 | Trinity Street 41 | Cambridge 42 | London 43 | England 44 |
45 | 123-456-7890 46 |
47 | 48 | Tim 49 | Berners-Lee 50 |
51 | High Street 52 | OX1 4AS 53 | Oxford 54 | England 55 |
56 | 57 |
58 |
--------------------------------------------------------------------------------