From d19aaa43ccb39257fc68fafe37c8b28772a34ae8 Mon Sep 17 00:00:00 2001 From: Brady James Garvin <bgarvin@cse.unl.edu> Date: Fri, 22 Feb 2019 11:24:05 -0600 Subject: [PATCH] Added refactorings from class. --- .../both_dry_violations/AgeCohort.java | 16 +++++++++ .../both_dry_violations/Cohort.java | 19 +++++++++++ .../both_dry_violations/Patient.java | 25 ++++++++++++++ .../both_dry_violations/RegionalCohort.java | 14 ++++++++ .../dry_violation_in_caller/Bradycardia.java | 12 +++++++ .../dry_violation_in_caller/Condition.java | 5 +++ .../dry_violation_in_caller/Patient.java | 30 +++++++++++++++++ .../dry_violation_in_caller/Tachycardia.java | 12 +++++++ .../dry_violation_in_method_body/Alert.java | 33 +++++++++++++++++++ .../SIRSAlert.java | 17 ++++++++++ 10 files changed, 183 insertions(+) create mode 100644 src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/AgeCohort.java create mode 100644 src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/Cohort.java create mode 100644 src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/Patient.java create mode 100644 src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/RegionalCohort.java create mode 100644 src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Bradycardia.java create mode 100644 src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Condition.java create mode 100644 src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Patient.java create mode 100644 src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Tachycardia.java create mode 100644 src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_method_body/Alert.java create mode 100644 src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_method_body/SIRSAlert.java diff --git a/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/AgeCohort.java b/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/AgeCohort.java new file mode 100644 index 0000000..34ece7f --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/AgeCohort.java @@ -0,0 +1,16 @@ +package edu.unl.cse.soft161.refactored.both_dry_violations; + +public class AgeCohort extends Cohort { + private int minimum; + private int maximum; + + public AgeCohort(int minimum, int maximum) { + this.minimum = minimum; + this.maximum = maximum; + } + + @Override + protected boolean includes(Patient patient) { + return minimum <= patient.getAge() && patient.getAge() <= maximum; + } +} diff --git a/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/Cohort.java b/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/Cohort.java new file mode 100644 index 0000000..acd09b5 --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/Cohort.java @@ -0,0 +1,19 @@ +package edu.unl.cse.soft161.refactored.both_dry_violations; + +import java.util.ArrayList; +import java.util.List; + +public abstract class Cohort { + protected abstract boolean includes(Patient patient); + + public List<Patient> filter(List<Patient> patients) { + List<Patient> results = new ArrayList<Patient>(); + for (Patient patient : patients) { + if (includes(patient)) { + results.add(patient); + } + } + return results; + } + +} \ No newline at end of file diff --git a/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/Patient.java b/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/Patient.java new file mode 100644 index 0000000..049775b --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/Patient.java @@ -0,0 +1,25 @@ +package edu.unl.cse.soft161.refactored.both_dry_violations; + +public class Patient { + private String name; + private String region; + private int age; + + public Patient(String name, String region, int age) { + this.name = name; + this.region = region; + this.age = age; + } + + public String getName() { + return name; + } + + public String getRegion() { + return region; + } + + public int getAge() { + return age; + } +} diff --git a/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/RegionalCohort.java b/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/RegionalCohort.java new file mode 100644 index 0000000..9ab068e --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/RegionalCohort.java @@ -0,0 +1,14 @@ +package edu.unl.cse.soft161.refactored.both_dry_violations; + +public class RegionalCohort extends Cohort { + private String region; + + public RegionalCohort(String region) { + this.region = region; + } + + @Override + protected boolean includes(Patient patient) { + return patient.getRegion().equals(region); + } +} diff --git a/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Bradycardia.java b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Bradycardia.java new file mode 100644 index 0000000..c9a53af --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Bradycardia.java @@ -0,0 +1,12 @@ +package edu.unl.cse.soft161.refactored.dry_violation_in_caller; + +public class Bradycardia implements Condition { + @Override + public boolean affects(Patient patient) { + return patient.getObservation("HR") < 60.0; + } + + public String toString() { + return "bradycardia"; + } +} diff --git a/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Condition.java b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Condition.java new file mode 100644 index 0000000..ee64658 --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Condition.java @@ -0,0 +1,5 @@ +package edu.unl.cse.soft161.refactored.dry_violation_in_caller; + +public interface Condition { + boolean affects(Patient patient); +} \ No newline at end of file diff --git a/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Patient.java b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Patient.java new file mode 100644 index 0000000..ce446ef --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Patient.java @@ -0,0 +1,30 @@ +package edu.unl.cse.soft161.refactored.dry_violation_in_caller; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Patient { + private String name; + private Map<String, Double>observations; + private List<Condition> monitoredConditions; + + public Patient(String name, List<Condition>monitoredConditions) { + this.name = name; + observations = new HashMap<String, Double>(); + this.monitoredConditions = monitoredConditions; + } + + public Double getObservation(String concept) { + return observations.get(concept); + } + + public void setObservation(String concept, Double value) { + observations.put(concept, value); + for (Condition condition : monitoredConditions) { + if (condition != null && condition.affects(this)) { + System.out.println("Warning: " + name + " has " + condition + "."); + } + } + } +} diff --git a/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Tachycardia.java b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Tachycardia.java new file mode 100644 index 0000000..dc5f78d --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Tachycardia.java @@ -0,0 +1,12 @@ +package edu.unl.cse.soft161.refactored.dry_violation_in_caller; + +public class Tachycardia implements Condition { + @Override + public boolean affects(Patient patient) { + return patient.getObservation("HR") > 100.0; + } + + public String toString() { + return "tachycardia"; + } +} diff --git a/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_method_body/Alert.java b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_method_body/Alert.java new file mode 100644 index 0000000..50fd67f --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_method_body/Alert.java @@ -0,0 +1,33 @@ +package edu.unl.cse.soft161.refactored.dry_violation_in_method_body; + +import java.time.ZonedDateTime; + +public class Alert { + private String type; + private String patient; + private ZonedDateTime timestamp; + private String message; + + public Alert(String type, String patient, ZonedDateTime timestamp, String message) { + this.type = type; + this.patient = patient; + this.timestamp = timestamp; + this.message = message; + } + + public String getType() { + return type; + } + + public String getPatient() { + return patient; + } + + public ZonedDateTime getTimestamp() { + return timestamp; + } + + public String getMessage() { + return message; + } +} diff --git a/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_method_body/SIRSAlert.java b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_method_body/SIRSAlert.java new file mode 100644 index 0000000..b194503 --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_method_body/SIRSAlert.java @@ -0,0 +1,17 @@ +package edu.unl.cse.soft161.refactored.dry_violation_in_method_body; + +import java.time.ZonedDateTime; +import java.util.List; + +public class SIRSAlert extends Alert { + private List<String> evidence; + + public SIRSAlert(String type, String patient, ZonedDateTime timestamp, String message, List<String> evidence) { + super(type, patient, timestamp, message); + this.evidence = evidence; + } + + public List<String> getEvidence() { + return evidence; + } +} -- GitLab