Skip to content

Commit

Permalink
https://github.com/kousen/dataorientedprogramming
Browse files Browse the repository at this point in the history
remove cycles
  • Loading branch information
ak-git committed Jan 25, 2025
1 parent 32dd70a commit a483359
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
18 changes: 9 additions & 9 deletions hello/src/main/java/com/ak/builder/BloodPressure.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.function.IntUnaryOperator;

public sealed interface BloodPressure permits BloodPressureRecord {
public sealed interface BloodPressure {
int systolic();

int diastolic();
Expand Down Expand Up @@ -43,15 +43,15 @@ public BloodPressure build() {
return new BloodPressureRecord(systolic, diastolic);
}
}
}

record BloodPressureRecord(int systolic, int diastolic) implements BloodPressure {
BloodPressureRecord(int systolic, int diastolic) {
IntUnaryOperator pressureLimits = bp -> Math.clamp(bp, 10, 220);
int s = pressureLimits.applyAsInt(systolic);
int d = pressureLimits.applyAsInt(diastolic);
this.systolic = Math.clamp(Math.max(s, d), 50, 220);
this.diastolic = Math.clamp(Math.min(s, d), 10, 130);
record BloodPressureRecord(int systolic, int diastolic) implements BloodPressure {
public BloodPressureRecord(int systolic, int diastolic) {
IntUnaryOperator pressureLimits = bp -> Math.clamp(bp, 10, 220);
int s = pressureLimits.applyAsInt(systolic);
int d = pressureLimits.applyAsInt(diastolic);
this.systolic = Math.clamp(Math.max(s, d), 50, 220);
this.diastolic = Math.clamp(Math.min(s, d), 10, 130);
}
}
}

Expand Down
19 changes: 9 additions & 10 deletions hello/src/main/java/com/ak/builder/Patient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Objects;
import java.util.function.Function;

public sealed interface Patient permits PatientRecord {
public sealed interface Patient {
int age();

Anthropomorphic anthropomorphic();
Expand Down Expand Up @@ -74,16 +74,15 @@ public Patient build() {
);
}
}
}

record PatientRecord(int age, Anthropomorphic anthropomorphic, BloodPressure bloodPressure,
Rates rates) implements Patient {
PatientRecord(int age, Anthropomorphic anthropomorphic, BloodPressure bloodPressure, Rates rates) {
this.age = Math.clamp(age, 12, 100);
this.anthropomorphic = anthropomorphic;
this.bloodPressure = bloodPressure;
this.rates = rates;
record PatientRecord(int age, Anthropomorphic anthropomorphic, BloodPressure bloodPressure,
Rates rates) implements Patient {
public PatientRecord(int age, Anthropomorphic anthropomorphic, BloodPressure bloodPressure, Rates rates) {
this.age = Math.clamp(age, 12, 100);
this.anthropomorphic = anthropomorphic;
this.bloodPressure = bloodPressure;
this.rates = rates;
}
}
}


23 changes: 11 additions & 12 deletions hello/src/main/java/com/ak/builder/Rates.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.ak.builder;

public sealed interface Rates permits RatesRecord {
public sealed interface Rates {
int heart();

int respiratory();
Expand Down Expand Up @@ -41,20 +41,19 @@ public Rates build() {
return new RatesRecord(heart, respiratory);
}
}
}

record RatesRecord(int heart, int respiratory) implements Rates {
RatesRecord(int heart, int respiratory) {
this.heart = Math.clamp(heart, 40, 140);
int rr = Math.clamp(respiratory, 4, 900);
if (rr > 99) {
this.respiratory = Math.clamp(respiratory, 100, 900);
}
else {
this.respiratory = Math.clamp(respiratory, 4, 28);
record RatesRecord(int heart, int respiratory) implements Rates {
public RatesRecord(int heart, int respiratory) {
this.heart = Math.clamp(heart, 40, 140);
int rr = Math.clamp(respiratory, 4, 900);
if (rr > 99) {
this.respiratory = Math.clamp(respiratory, 100, 900);
}
else {
this.respiratory = Math.clamp(respiratory, 4, 28);
}
}
}
}



0 comments on commit a483359

Please sign in to comment.