Skip to content

Commit

Permalink
OP-1157 use pattern matching for instanceof (JDK 17) (informatici#1444)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbmalkovsky authored Nov 8, 2024
1 parent aaa864c commit e5c6447
Show file tree
Hide file tree
Showing 22 changed files with 50 additions and 89 deletions.
5 changes: 2 additions & 3 deletions src/main/java/org/isf/accounting/model/BillItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,10 @@ public boolean equals(Object obj) {
return true;
}

if (!(obj instanceof BillItems)) {
if (!(obj instanceof BillItems billItem)) {
return false;
}

BillItems billItem = (BillItems)obj;

return (id == billItem.getId());
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/isf/accounting/model/BillPayments.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,10 @@ public boolean equals(Object obj) {
return true;
}

if (!(obj instanceof BillPayments)) {
if (!(obj instanceof BillPayments billPayment)) {
return false;
}

BillPayments billPayment = (BillPayments)obj;

return (id == billPayment.getId());
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/isf/admission/model/Admission.java
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,10 @@ public boolean equals(Object obj) {
return true;
}

if (!(obj instanceof Admission)) {
if (!(obj instanceof Admission admission)) {
return false;
}

Admission admission = (Admission) obj;
return (this.getId() == admission.getId());
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/isf/admtype/model/AdmissionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,10 @@ public boolean equals(Object obj) {
return true;
}

if (!(obj instanceof AdmissionType)) {
if (!(obj instanceof AdmissionType admissionType)) {
return false;
}

AdmissionType admissionType = (AdmissionType)obj;

return this.getCode().equals(admissionType.getCode());
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/isf/dicom/model/FileDicom.java
Original file line number Diff line number Diff line change
Expand Up @@ -714,11 +714,10 @@ public boolean equals(Object obj) {
return true;
}

if (!(obj instanceof FileDicom)) {
if (!(obj instanceof FileDicom dicom)) {
return false;
}

FileDicom dicom = (FileDicom)obj;

return (idFile == dicom.getIdFile());
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/isf/disctype/model/DischargeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ public boolean equals(Object obj) {
return true;
}

if (!(obj instanceof DischargeType)) {
if (!(obj instanceof DischargeType dischargeType)) {
return false;
}

DischargeType dischargeType = (DischargeType)obj;

return (this.getCode().equals(dischargeType.getCode()));
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/isf/lab/model/Laboratory.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,10 @@ public void setStatus(String status) {

@Override
public boolean equals(Object obj) {
if (!(obj instanceof Laboratory)) {
if (!(obj instanceof Laboratory laboratory)) {
return false;
}

Laboratory laboratory = (Laboratory) obj;
return (this.getCode().equals(laboratory.getCode()));

}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/isf/lab/model/LaboratoryRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,10 @@ public boolean equals(Object obj) {
return true;
}

if (!(obj instanceof LaboratoryRow)) {
if (!(obj instanceof LaboratoryRow laboratoryRow)) {
return false;
}

LaboratoryRow laboratoryRow = (LaboratoryRow)obj;

if (this.getCode() != null && laboratoryRow.getCode() != null) {
return (this.getCode().equals(laboratoryRow.getCode()) );
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/isf/medicalstock/model/Movement.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,10 @@ public boolean equals(Object obj) {
return true;
}

if (!(obj instanceof Movement)) {
if (!(obj instanceof Movement movement)) {
return false;
}

Movement movement = (Movement) obj;
return (this.getCode() == movement.getCode());
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/isf/medicalstockward/model/MedicalWard.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,10 @@ public boolean equals(Object obj) {
return true;
}

if (!(obj instanceof MedicalWard)) {
if (!(obj instanceof MedicalWard ward)) {
return false;
}

MedicalWard ward = (MedicalWard)obj;

return (this.id.getMedical() == ward.id.getMedical());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,9 @@ public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof MedicalWardId)) {
if (!(obj instanceof MedicalWardId other)) {
return false;
}
MedicalWardId other = (MedicalWardId) obj;
if (medical != other.medical) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,9 @@ public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof MovementWard)) {
if (!(obj instanceof MovementWard movement)) {
return false;
}
MovementWard movement = (MovementWard) obj;
return (this.getCode() == movement.getCode());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,10 @@ public boolean equals(Object obj) {
return true;
}

if (!(obj instanceof MovementType)) {
if (!(obj instanceof MovementType movementType)) {
return false;
}

MovementType movementType = (MovementType) obj;
return (this.getCode().equals(movementType.getCode()));
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/isf/opd/model/Opd.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,10 @@ public boolean equals(Object obj) {
return true;
}

if (!(obj instanceof Opd)) {
if (!(obj instanceof Opd opd)) {
return false;
}

Opd opd = (Opd)obj;

return (code == opd.getCode());
}
}
5 changes: 2 additions & 3 deletions src/main/java/org/isf/operation/model/OperationRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,11 @@ public boolean equals(Object anObject) {
return true;
}

if (!(anObject instanceof OperationRow)) {
if (!(anObject instanceof OperationRow operationRow)) {
return false;
}

OperationRow operationRow = (OperationRow) anObject;
return (this.getOperation().equals(operationRow.getOperation())
return (this.getOperation().equals(operationRow.getOperation())
&& this.getPrescriber().equals(operationRow.getPrescriber()))
&& operationRow.getTransUnit().equals(this.getTransUnit())
&& this.getAdmission().equals(operationRow.getAdmission())
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/isf/opetype/model/OperationType.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ public boolean equals(Object anObject) {
return true;
}

if (!(anObject instanceof OperationType)) {
if (!(anObject instanceof OperationType operationType)) {
return false;
}

OperationType operationType = (OperationType)anObject;

return (this.getCode().equals(operationType.getCode()) &&
this.getDescription().equalsIgnoreCase(operationType.getDescription()));
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/isf/patient/model/Patient.java
Original file line number Diff line number Diff line change
Expand Up @@ -561,11 +561,10 @@ public boolean equals(Object obj) {
return true;
}

if (!(obj instanceof Patient)) {
if (!(obj instanceof Patient patient)) {
return false;
}

Patient patient = (Patient)obj;
return (this.getCode().equals(patient.getCode()));
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/isf/patvac/model/PatientVaccine.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,9 @@ public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof PatientVaccine)) {
if (!(obj instanceof PatientVaccine other)) {
return false;
}
PatientVaccine other = (PatientVaccine) obj;
if (code != other.code) {
return false;
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/isf/sms/model/Sms.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,10 @@ public boolean equals(Object obj) {
return true;
}

if (!(obj instanceof Sms)) {
if (!(obj instanceof Sms sms)) {
return false;
}

Sms sms = (Sms) obj;
return (this.getSmsId() == sms.getSmsId());
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/isf/stat/manager/JasperReportsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -991,8 +991,7 @@ private void addSubReportsBundleParameters(String jasperFileFolder, String jaspe
List<JRChild> elements = band.getChildren(); // Get all children
for (JRChild child : elements) {
int index = 1;
if (child instanceof JRBaseSubreport) { // This is a subreport
JRBaseSubreport subreport = (JRBaseSubreport) child;
if (child instanceof JRBaseSubreport subreport) { // This is a subreport
String expression = ""; // Lets find out the expression used
JRExpressionChunk[] chunks = subreport.getExpression().getChunks();
for (JRExpressionChunk c : chunks) {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/isf/therapy/model/TherapyRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,10 @@ public boolean equals(Object obj) {
return true;
}

if (!(obj instanceof TherapyRow)) {
if (!(obj instanceof TherapyRow therapy)) {
return false;
}

TherapyRow therapy = (TherapyRow)obj;

return (therapyID == therapy.getTherapyID());
}

Expand Down
Loading

0 comments on commit e5c6447

Please sign in to comment.