diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..5dea8e9 --- /dev/null +++ b/.classpath @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/.gradle/9.3.1/executionHistory/executionHistory.bin b/.gradle/9.3.1/executionHistory/executionHistory.bin index 401fdd6..22f042b 100755 Binary files a/.gradle/9.3.1/executionHistory/executionHistory.bin and b/.gradle/9.3.1/executionHistory/executionHistory.bin differ diff --git a/.gradle/9.3.1/executionHistory/executionHistory.lock b/.gradle/9.3.1/executionHistory/executionHistory.lock index 6e8ec09..6d9f647 100755 Binary files a/.gradle/9.3.1/executionHistory/executionHistory.lock and b/.gradle/9.3.1/executionHistory/executionHistory.lock differ diff --git a/.gradle/9.3.1/fileHashes/fileHashes.bin b/.gradle/9.3.1/fileHashes/fileHashes.bin index e39a583..761bfc0 100755 Binary files a/.gradle/9.3.1/fileHashes/fileHashes.bin and b/.gradle/9.3.1/fileHashes/fileHashes.bin differ diff --git a/.gradle/9.3.1/fileHashes/fileHashes.lock b/.gradle/9.3.1/fileHashes/fileHashes.lock index 1329746..260adc6 100755 Binary files a/.gradle/9.3.1/fileHashes/fileHashes.lock and b/.gradle/9.3.1/fileHashes/fileHashes.lock differ diff --git a/.gradle/9.3.1/fileHashes/resourceHashesCache.bin b/.gradle/9.3.1/fileHashes/resourceHashesCache.bin index 8b95779..0755d68 100755 Binary files a/.gradle/9.3.1/fileHashes/resourceHashesCache.bin and b/.gradle/9.3.1/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 9ba83f1..bae36ae 100755 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index 0274d08..0058cb9 100755 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/.project b/.project index 9e1bc38..82c52ab 100644 --- a/.project +++ b/.project @@ -20,4 +20,15 @@ org.eclipse.jdt.core.javanature org.eclipse.buildship.core.gradleprojectnature + + + 1771249637326 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..9f6d62b --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore +org.eclipse.jdt.core.compiler.codegen.targetPlatform=25 +org.eclipse.jdt.core.compiler.compliance=25 +org.eclipse.jdt.core.compiler.source=25 diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..17eab94 --- /dev/null +++ b/readme.txt @@ -0,0 +1,68 @@ +Project is build as gradle root and child projects. +Gradle handles build and run of program using AspectJ Java runtime. + +Build Environment: +JDK25, +Eclipse 4.38 with Gradle Buildship or VSCode with Extension Pack for Java; vscjava.vscode-java-pack( 0.30.5 ) +AspectJ 1.9.25+ +OpenJFX (** https://gluonhq.com/products/javafx/ **) + This java UI sdk requires you download windows/linux/Mac JMODs libs to your workspace on your host. + refer to the launch.json file, and add the directory location for the jmods you downloaded. + +In Eclipse import project as an Gradle Project. + +Tests with ASPECTJ: + on windows: + gradlew.bat run + / or on linux: + sh ./gradlew edu.addressbook.view:run + AspectJ Referee component will call the Game plays. + + +schema + +CREATE TABLE contact ( +contact_id NUMBER PRIMARY KEY, +first_name TEXT, +last_name TEXT +); + +CREATE TABLE phone ( +contact_id NUMBER FOREIGN KEY, +phone_no TEXT +); + +CREATE TABLE emailaddress ( +contact_id NUMBER FOREIGN KEY, +email TEXT +); + +CREATE TABLE address ( +contact_id NUMBER FOREIGN KEY, +street TEXT, +city TEXT, +state TEXT, +zip TEXT +); + +CREATE TABLE note ( +contact_id NUMBER FOREIGN KEY, +note TEXT +); + +CREATE TABLE activity ( +activity_id NUMBER FOREIGN KEY, +activity_type TEXT, +activity_note TEXT +); + +CREATE TABLE contact_activity ( +activity_id NUMBER FOREIGN KEY, +contact_id NUMBER FOREIGN KEY +); + +CREATE TABLE friends ( +contact_id NUMBER FOREIGN KEY, +friend_contact_id NUMBER FORIEGN KEY +); + diff --git a/src/main/java/edu/bookocontacts/TableViewController.java b/src/main/java/edu/bookocontacts/ViewController.java similarity index 81% rename from src/main/java/edu/bookocontacts/TableViewController.java rename to src/main/java/edu/bookocontacts/ViewController.java index 3392899..bb37565 100755 --- a/src/main/java/edu/bookocontacts/TableViewController.java +++ b/src/main/java/edu/bookocontacts/ViewController.java @@ -4,9 +4,14 @@ */ package edu.bookocontacts; +import java.util.logging.Level; +import java.util.logging.Logger; + +import edu.bookocontacts.model.Person; +import edu.bookocontacts.model.PersonFactory; + import java.net.URL; import java.util.Collections; -import java.util.List; import java.util.Comparator; import java.util.ResourceBundle; import javafx.beans.value.ChangeListener; @@ -29,7 +34,9 @@ import javafx.scene.image.ImageView; * FXML Controller class * */ -public class TableViewController implements Initializable { +public class ViewController implements Initializable { + + Logger logger = Logger.getLogger(getClass().getName()); @FXML private TableView personView = new TableView<>(); @@ -53,30 +60,38 @@ public class TableViewController implements Initializable { private ImageView upImg = new ImageView(new Image("/media/up.png")); private ImageView downImg = new ImageView(new Image("/media/down.png")); - List rawPersons = PersonFactory.getAllPersons(); - ObservableList persons = FXCollections.observableArrayList(rawPersons); - int pageCount = 5; - int itemsPerPage = 4; - int currentPageIndex = 0; - boolean order = true; + + private ObservableList persons = null; + + private int pageCount = 5; + private int itemsPerPage = 4; + private int currentPageIndex = 0; + private boolean order = true; + + private void log(String message){ + logger.log(Level.FINE, message); + } /** * Initializes the controller class. */ @Override public void initialize(URL url, ResourceBundle rb) { - System.out.println("initialize"); + log("initialize"); + persons = FXCollections.observableArrayList(PersonFactory.getAllPersons()); + log(String.format("Person size: %d" , persons.size())); + sort(); initializeTable(); pageCount = getPageCount(persons.size(), itemsPerPage); - System.out.println("pageCount=" + pageCount); + log("pageCount=" + pageCount); pagination.setPageCount(pageCount); pagination.currentPageIndexProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observable, Number oldValue, Number newValue) { - System.out.println("Pagination Changed from " + oldValue + " , to " + newValue); + log("Pagination Changed from " + oldValue + " , to " + newValue); currentPageIndex = newValue.intValue(); updatePersonView(); } @@ -101,28 +116,27 @@ public class TableViewController implements Initializable { if (order) { Collections.reverse(persons); } - System.out.println(" order = " + order + "; data = " + persons); + log(" order = " + order + "; data = " + persons); order = !order; id.setGraphic((order) ? upImg : downImg); updatePersonView(); - System.out.println(" comparator called"); + log(" comparator called"); } }); } private void sort() { - //persons.sort((Person p1, Person p2) -> p1.id.compareTo(p2.id)); Collections.sort(persons, new Comparator() { @Override public int compare(Person t, Person t1) { - System.out.println(" comparator called"); + log(" comparator called"); return t.getId().compareTo(t1.getId()); } }); } public void updatePersonView() { - System.out.println("updatePersonView"); + log("updatePersonView"); personView.getItems().setAll(persons.subList(currentPageIndex * itemsPerPage, ((currentPageIndex * itemsPerPage + itemsPerPage <= persons.size()) ? currentPageIndex * itemsPerPage + itemsPerPage : persons.size()))); } @@ -135,7 +149,7 @@ public class TableViewController implements Initializable { personViewNameCol.sortTypeProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue paramObservableValue, SortType paramT1, SortType paramT2) { - System.out.println("NAME Clicked -- sortType = " + paramT1 + ", SortType=" + paramT2); + log("NAME Clicked -- sortType = " + paramT1 + ", SortType=" + paramT2); id.setGraphic(null); } }); @@ -164,7 +178,7 @@ public class TableViewController implements Initializable { private int getPageCount(int totalCount, int itemsPerPage) { float floatCount = Float.valueOf(totalCount) / Float.valueOf(itemsPerPage); int intCount = totalCount / itemsPerPage; - System.out.println("floatCount=" + floatCount + ", intCount=" + intCount); + log("floatCount=" + floatCount + ", intCount=" + intCount); return ((floatCount > intCount) ? ++intCount : intCount); } } diff --git a/src/main/java/edu/bookocontacts/model/Address.java b/src/main/java/edu/bookocontacts/model/Address.java new file mode 100644 index 0000000..8d7e86c --- /dev/null +++ b/src/main/java/edu/bookocontacts/model/Address.java @@ -0,0 +1,106 @@ +package edu.bookocontacts.model; + +public final class Address{ + + String street; + String city; + String state; + String zip; + + public Address() { + } + + public Address(String street, String city, String state, String zip) { + this.street = street; + this.city = city; + this.state = state; + this.zip = zip; + } + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public String getZip() { + return zip; + } + + public void setZip(String zip) { + this.zip = zip; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((street == null) ? 0 : street.hashCode()); + result = prime * result + ((city == null) ? 0 : city.hashCode()); + result = prime * result + ((state == null) ? 0 : state.hashCode()); + result = prime * result + ((zip == null) ? 0 : zip.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Address other = (Address) obj; + if (street == null) { + if (other.street != null) + return false; + } else if (!street.equals(other.street)) + return false; + if (city == null) { + if (other.city != null) + return false; + } else if (!city.equals(other.city)) + return false; + if (state == null) { + if (other.state != null) + return false; + } else if (!state.equals(other.state)) + return false; + if (zip == null) { + if (other.zip != null) + return false; + } else if (!zip.equals(other.zip)) + return false; + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("{ \"Address\":{"); + sb.append("\"street\": \"" + street + "\","); + sb.append("\"city\": \"" + city + "\","); + sb.append("\"state\": \"" + state + "\","); + sb.append("\"zip\": \"" + zip + "\""); + sb.append("}}"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/edu/bookocontacts/model/Contact.java b/src/main/java/edu/bookocontacts/model/Contact.java new file mode 100644 index 0000000..f0254bd --- /dev/null +++ b/src/main/java/edu/bookocontacts/model/Contact.java @@ -0,0 +1,131 @@ +package edu.bookocontacts.model; + +import java.io.IOException; + +/** + * Concrete account data class for account json storage record. + * Collects account attributes, and hash instance to enforce uniqueness. + */ +public class Contact { + private Integer contact_id = null; + private String phone_number; + private Address mailing_address; + private EmailAddress email_address; + + public Contact() { + + } + + public Contact( + String phone_number, + Address mailing_address, + EmailAddress email_address) throws IllegalArgumentException { + this.phone_number = phone_number; + this.mailing_address = mailing_address; + this.email_address = email_address; + + if (phone_number == null) { + throw new IllegalArgumentException(String.format("%s %s", "Account: requires phone number", + mailing_address.toString())); + } + if (mailing_address == null) { + throw new IllegalArgumentException(String.format("%s %s", "Account: requires mailing address", + phone_number.substring(phone_number.length() - 4))); + } + if (email_address == null) { + throw new IllegalArgumentException(String.format("%s %s", "Account: requires phone number", + mailing_address.toString())); + } + + this.phone_number = phone_number; + this.mailing_address = mailing_address; + this.email_address = email_address; + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("{ \"Account\":{"); + sb.append("\"account_number\": \"").append(contact_id).append("\","); + sb.append("\"phone_number\": \"").append(phone_number).append("\","); + sb.append("\"mailing_address\": ").append(mailing_address).append(","); + sb.append("\"email_address\": ").append(email_address).append(","); + sb.append("}}"); + return sb.toString(); + } + + public static void Write(Contact acct) throws IOException { + } + + public String getPhone_number() { + return phone_number; + } + + public void setPhone_number(String phone_number) { + this.phone_number = phone_number; + } + + public Address getMailing_address() { + return mailing_address; + } + + public void setMailing_address(Address mailing_address) { + this.mailing_address = mailing_address; + } + + public EmailAddress getEmail_address() { + return email_address; + } + + public void setEmail_address(EmailAddress email_address) { + this.email_address = email_address; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((contact_id == null) ? 0 : contact_id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Contact other = (Contact) obj; + if (contact_id == null) { + if (other.contact_id != null) + return false; + } else if (!contact_id.equals(other.contact_id)) + return false; + return true; + } + + public boolean checkValid() throws IllegalArgumentException { + if (email_address == null) { + throw new IllegalArgumentException( + String.format("not valid, email_address %s", this.contact_id)); + } + if (phone_number == null) { + throw new IllegalArgumentException( + String.format("not valid, phone_number: %s", this.contact_id)); + } + if (getMailing_address() == null) { + throw new IllegalArgumentException( + String.format("not valid, mailing_address: %s", this.contact_id)); + } + return true; + } + + public void update(Contact acct) { + this.setEmail_address(acct.email_address); + this.setPhone_number(acct.phone_number); + this.setMailing_address(acct.mailing_address); + } +} \ No newline at end of file diff --git a/src/main/java/edu/bookocontacts/model/EmailAddress.java b/src/main/java/edu/bookocontacts/model/EmailAddress.java new file mode 100644 index 0000000..1c8cc16 --- /dev/null +++ b/src/main/java/edu/bookocontacts/model/EmailAddress.java @@ -0,0 +1,52 @@ +package edu.bookocontacts.model; + +public class EmailAddress{ + String email_address; + + public EmailAddress(String email_address) { + this.email_address = email_address; + } + + public String getEmail_address() { + return email_address; + } + + public void setEmail_address(String email_address) { + this.email_address = email_address; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((email_address == null) ? 0 : email_address.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + EmailAddress other = (EmailAddress) obj; + if (email_address == null) { + if (other.email_address != null) + return false; + } else if (!email_address.equals(other.email_address)) + return false; + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("{ \"EmailAddress\":{"); + sb.append("\"email\": \"" + email_address + "\""); + sb.append("}}"); + return sb.toString(); + } + +} diff --git a/src/main/java/edu/bookocontacts/Person.java b/src/main/java/edu/bookocontacts/model/Person.java similarity index 90% rename from src/main/java/edu/bookocontacts/Person.java rename to src/main/java/edu/bookocontacts/model/Person.java index 1597108..c7fa868 100755 --- a/src/main/java/edu/bookocontacts/Person.java +++ b/src/main/java/edu/bookocontacts/model/Person.java @@ -2,10 +2,7 @@ * To change this template, choose Tools | Templates * and open the template in the editor. */ -package edu.bookocontacts; - -import java.util.ArrayList; -import java.util.List; +package edu.bookocontacts.model; /** * diff --git a/src/main/java/edu/bookocontacts/PersonFactory.java b/src/main/java/edu/bookocontacts/model/PersonFactory.java similarity index 89% rename from src/main/java/edu/bookocontacts/PersonFactory.java rename to src/main/java/edu/bookocontacts/model/PersonFactory.java index 943c5ae..6339ecf 100755 --- a/src/main/java/edu/bookocontacts/PersonFactory.java +++ b/src/main/java/edu/bookocontacts/model/PersonFactory.java @@ -2,7 +2,7 @@ * To change this template, choose Tools | Templates * and open the template in the editor. */ -package edu.bookocontacts; +package edu.bookocontacts.model; import java.util.ArrayList; import java.util.List; @@ -12,7 +12,8 @@ import java.util.List; */ public class PersonFactory { static int id=0; - static List getAllPersons() { + + public static List getAllPersons() { ArrayList list = new ArrayList<>(); list.add(createPerson("John", 40)); list.add(createPerson("Daisy", 21)); @@ -28,7 +29,6 @@ public class PersonFactory { list.add(createPerson("John", 52)); list.add(createPerson("Daisy", 29)); list.add(createPerson("Martha Has a very Long Name", 18)); - System.out.println("Returning person size: " + list.size()); return list; } diff --git a/src/main/java/edu/bookocontacts/model/PhoneNumber.java b/src/main/java/edu/bookocontacts/model/PhoneNumber.java new file mode 100644 index 0000000..4e846b4 --- /dev/null +++ b/src/main/java/edu/bookocontacts/model/PhoneNumber.java @@ -0,0 +1,51 @@ +package edu.bookocontacts.model; + +public class PhoneNumber { + String phone_number; + + public PhoneNumber(String phone_number) { + this.phone_number = phone_number; + } + + public String getphone_number() { + return phone_number; + } + + public void setphone_number(String phone_number) { + this.phone_number = phone_number; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((phone_number == null) ? 0 : phone_number.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PhoneNumber other = (PhoneNumber) obj; + if (phone_number == null) { + if (other.phone_number != null) + return false; + } else if (!phone_number.equals(other.getphone_number())) + return false; + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("{ \"PhoneNumber\":{"); + sb.append("\"phone\": \"" + phone_number + "\""); + sb.append("}}"); + return sb.toString(); + } +} diff --git a/src/main/resources/media/TableView.fxml b/src/main/resources/media/TableView.fxml index 18979dd..c1746e5 100755 --- a/src/main/resources/media/TableView.fxml +++ b/src/main/resources/media/TableView.fxml @@ -9,7 +9,7 @@ - +