Created
September 15, 2020 13:18
-
-
Save Lanse505/7625cd8c9f738fef6981b998f7359f41 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.playhrzn.wce.test; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.util.Arrays; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.logging.Logger; | |
public class University { | |
private static final Logger logger = Logger.getLogger("universityProject"); | |
private String locationName; | |
private double[][] locationCoordinates; | |
private final long registrationNumber; | |
private URL url; | |
private final Map<AcademicCategories, List<Person>> academicLevelMap; | |
private final Map<JobPositions, List<Person>> employeeMap; | |
public University(String locationName, long registrationNumber, String url) { | |
this.locationName = locationName; | |
this.registrationNumber = registrationNumber; | |
try { | |
this.url = new URL(url); | |
} catch (MalformedURLException exception) { | |
logger.fine(exception.getLocalizedMessage()); | |
} | |
this.academicLevelMap = new HashMap<>(); | |
this.employeeMap = new HashMap<>(); | |
} | |
public static Logger getLogger() { | |
return logger; | |
} | |
public void addPerson(Person person) { | |
this.academicLevelMap.computeIfPresent(person.getAcademicCategory(), (academicCategories, people) -> { | |
people.add(person); | |
return people; | |
}); | |
this.employeeMap.computeIfPresent(person.getJob(), (jobs, people) -> { | |
people.add(person); | |
return people; | |
}); | |
} | |
public void removePerson(Person person) { | |
this.academicLevelMap.computeIfPresent(person.getAcademicCategory(), (academicCategories, people) -> { | |
people.remove(person); | |
return people; | |
}); | |
this.employeeMap.computeIfPresent(person.getJob(), (jobs, people) -> { | |
people.remove(person); | |
return people; | |
}); | |
} | |
public double[][] getLocationCoordinates() { | |
return locationCoordinates; | |
} | |
public void setLocationCoordinates(double[][] locationCoordinates) { | |
this.locationCoordinates = locationCoordinates; | |
} | |
public String getLocationName() { | |
return locationName; | |
} | |
public void setLocationName(String locationName) { | |
this.locationName = locationName; | |
} | |
public long getRegistrationNumber() { | |
return registrationNumber; | |
} | |
// Storage Enums | |
public enum EducationLevel { | |
BACHELOR, | |
MASTERS, | |
PHD | |
} | |
public enum AcademicCategories { | |
ACADEMIC(JobPositions.PROFESSOR, JobPositions.LECTURER, JobPositions.ASSISTANT_LECTURER, JobPositions.PHD_STUDENT), | |
NON_ACADEMIC(JobPositions.HR, JobPositions.ACCOUNTING, JobPositions.LIBRARIAN, JobPositions.TECHNICAL_SUPPORT); | |
private final List<JobPositions> applicableJobs; | |
AcademicCategories(JobPositions... applicablePositions) { | |
this.applicableJobs = Arrays.asList(applicablePositions); | |
} | |
public List<JobPositions> getApplicableJobs() { | |
return applicableJobs; | |
} | |
} | |
public enum JobPositions { | |
PROFESSOR(true), | |
LECTURER(true), | |
ASSISTANT_LECTURER(true), | |
PHD_STUDENT(true), | |
HR(false), | |
ACCOUNTING(false), | |
LIBRARIAN(false), | |
TECHNICAL_SUPPORT(false); | |
private final boolean isAcademic; | |
JobPositions(boolean isAcademic) { | |
this.isAcademic = isAcademic; | |
} | |
public boolean isAcademic() { | |
return isAcademic; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.playhrzn.wce.test; | |
import com.playhrzn.wce.test.University.AcademicCategories; | |
import com.playhrzn.wce.test.University.EducationLevel; | |
import com.playhrzn.wce.test.University.JobPositions; | |
public class Person { | |
private final String name; | |
private final long socialSecurityNumber; | |
private JobPositions job; | |
private EducationLevel educationLevel; | |
public Person (String name, long socialSecurityNumber, JobPositions job, EducationLevel educationLevel) { | |
this.name = name; | |
this.socialSecurityNumber = socialSecurityNumber; | |
this.job = job; | |
this.educationLevel = educationLevel; | |
} | |
public String getName() { | |
return name; | |
} | |
public long getSocialSecurityNumber() { | |
return socialSecurityNumber; | |
} | |
public JobPositions getJob() { | |
return job; | |
} | |
public void setJob(JobPositions job) { | |
this.job = job; | |
} | |
public AcademicCategories getAcademicCategory() { | |
return job.isAcademic() ? AcademicCategories.ACADEMIC : AcademicCategories.NON_ACADEMIC; | |
} | |
public void setEducationLevel(EducationLevel educationLevel) { | |
this.educationLevel = educationLevel; | |
} | |
public EducationLevel getEducationLevel() { | |
return educationLevel; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment