Skip to content

Commit

Permalink
OP-1157 use pattern matching for instanceof (JDK 16)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbmalkovsky committed Nov 8, 2024
1 parent b9faed4 commit 8b0d775
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 48 deletions.
9 changes: 3 additions & 6 deletions src/main/java/org/isf/admission/gui/PatientFolderBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,19 +452,16 @@ public void mouseClicked(MouseEvent mouseEvent) {
}
}

if (selectedObject instanceof Admission) {
if (selectedObject instanceof Admission ad) {

Admission ad = (Admission) selectedObject;
startDate = ad.getAdmDate();
endDate = ad.getDisDate();

} else if (selectedObject instanceof Opd) {
} else if (selectedObject instanceof Opd opd) {

Opd opd = (Opd) selectedObject;
startDate = opd.getDate();

} else if (selectedObject instanceof PatientExamination) {
PatientExamination exam = (PatientExamination) selectedObject;
} else if (selectedObject instanceof PatientExamination exam) {
startDate = exam.getPex_date();
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/isf/opd/gui/OpdEditExtended.java
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,7 @@ private void setAttendance() {
return;
}
Object selectedObject = diseaseBox1.getSelectedItem();
if (selectedObject instanceof Disease) {
Disease disease = (Disease) selectedObject;
if (selectedObject instanceof Disease disease) {
if (lastOPDDisease1 != null && disease.getCode().equals(lastOPDDisease1.getCode())) {
rePatientButton.setSelected(true);
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/isf/session/LoginEventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public class LoginEventListener implements LoginListener {

@Override
public void loginInserted(AWTEvent e) {
if (e.getSource() instanceof User) {
User myUser = (User) e.getSource();
if (e.getSource() instanceof User myUser) {
RestartUserSession.setUser(myUser);
RestartUserSession.getTimer().startTimer();
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/isf/therapy/gui/TherapyEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -1142,14 +1142,12 @@ public void mouseClicked(MouseEvent e) {
model = list.getModel();
for (int i = 0; i < model.getSize(); i++) {
Object iteratedItem = model.getElementAt(i);
if (iteratedItem instanceof Therapy) {
Therapy aTherapy = (Therapy) iteratedItem;
if (iteratedItem instanceof Therapy aTherapy) {
if (therapyID != 0 && aTherapy.getTherapyID() == therapyID) {
list.setSelectedIndex(i);
}
}
if (iteratedItem instanceof Visit) {
Visit aVisit = (Visit) iteratedItem;
if (iteratedItem instanceof Visit aVisit) {
if (visitID != 0 && aVisit.getVisitID() == visitID) {
list.setSelectedIndex(i);
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/isf/utils/jobjects/OhTableDrugsModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ public Object getValueAt(int rowIndex, int columnIndex) {
String value = "";
if (rowIndex >= 0 && rowIndex < this.filteredList.size()) {
T obj = this.filteredList.get(rowIndex);
if (obj instanceof MovementWard) {
MovementWard drugObj = (MovementWard) obj;
if (obj instanceof MovementWard drugObj) {
switch (columnIndex) {
case 0:
String dt;
Expand Down
24 changes: 8 additions & 16 deletions src/main/java/org/isf/utils/jobjects/OhTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public T filter(String searchQuery) throws OHException {

for (T t : this.dataList) {
Object object = t;
if (object instanceof Price) {
Price price = (Price) object;
if (object instanceof Price price) {
String strItem = price.getItem() + price.getDesc();
if (allowSearchByCode && searchQuery.equalsIgnoreCase(price.getItem())) {
T resPbj = (T) object;
Expand All @@ -83,8 +82,7 @@ public T filter(String searchQuery) throws OHException {
}
}

if (object instanceof MedicalWard) {
MedicalWard mdw = (MedicalWard) object;
if (object instanceof MedicalWard mdw) {
String strItem = mdw.getMedical().getProdCode() + mdw.getMedical().getDescription();

if (allowSearchByCode && searchQuery.equalsIgnoreCase(mdw.getMedical().getProdCode())) {
Expand All @@ -101,8 +99,7 @@ public T filter(String searchQuery) throws OHException {
}
}

if (object instanceof PricesOthers) {
PricesOthers priceO = (PricesOthers) object;
if (object instanceof PricesOthers priceO) {
String strItem = priceO.getCode() + priceO.getDescription();

if (allowSearchByCode && searchQuery.equalsIgnoreCase(priceO.getCode())) {
Expand All @@ -119,8 +116,7 @@ public T filter(String searchQuery) throws OHException {
}
}

if (object instanceof BillItems) {
BillItems priceO = (BillItems) object;
if (object instanceof BillItems priceO) {
String strItem = priceO.getItemDisplayCode() + priceO.getItemDescription();

if (allowSearchByCode && searchQuery.equalsIgnoreCase(priceO.getItemDisplayCode())) {
Expand Down Expand Up @@ -188,33 +184,29 @@ public Object getValueAt(int rowIndex, int columnIndex) {
String value = "";
if (rowIndex >= 0 && rowIndex < this.filteredList.size()) {
T obj = this.filteredList.get(rowIndex);
if (obj instanceof Price) {
Price priceObj = (Price) obj;
if (obj instanceof Price priceObj) {
if (columnIndex == 0) {
value = priceObj.getItem() != null ? priceObj.getItem() : String.valueOf(priceObj.getId());
} else {
value = priceObj.getDesc();
}
}
if (obj instanceof MedicalWard) {
MedicalWard mdwObj = (MedicalWard) obj;
if (obj instanceof MedicalWard mdwObj) {
if (columnIndex == 0) {
value = mdwObj.getMedical().getProdCode() != null ? mdwObj.getMedical().getProdCode() : String.valueOf(mdwObj.getMedical().getCode());
} else {
value = mdwObj.getMedical().getDescription();
}
}
if (obj instanceof PricesOthers) {
PricesOthers mdwObj = (PricesOthers) obj;
if (obj instanceof PricesOthers mdwObj) {
if (columnIndex == 0) {
value = mdwObj.getCode() != null ? mdwObj.getCode() : String.valueOf(mdwObj.getId());
} else {
value = mdwObj.getDescription();
}
}

if (obj instanceof BillItems) {
BillItems mdwObj = (BillItems) obj;
if (obj instanceof BillItems mdwObj) {
if (columnIndex == 0) {
value = mdwObj.getItemDisplayCode() != null ? mdwObj.getItemDisplayCode() : String.valueOf(mdwObj.getId());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public int filter(String searchQuery) {

for (T t : this.dataList) {
Object object = t;
if (object instanceof OperationRow) {
OperationRow price = (OperationRow) object;
if (object instanceof OperationRow price) {
String strItem = price.getOperation().getCode() + price.getOpResult();
strItem = strItem.toLowerCase();
searchQuery = searchQuery.toLowerCase();
Expand Down Expand Up @@ -126,8 +125,7 @@ public Object getValueAt(int rowIndex, int columnIndex) {
String value = "";
if (rowIndex >= 0 && rowIndex < this.filteredList.size()) {
T obj = this.filteredList.get(rowIndex);
if (obj instanceof OperationRow) {
OperationRow opdObj = (OperationRow) obj;
if (obj instanceof OperationRow opdObj) {
switch (columnIndex) {
case -1:
return opdObj;
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/org/isf/video/PhotoboothTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,14 @@ public static void main(final String[] args) {
final PhotoboothPanelPresentationModel presentationModel = new PhotoboothPanelPresentationModel();
presentationModel.addBeanPropertyChangeListener(PhotoboothPanelModel.PROPERTY_IMAGE, propertyChangeEvent -> {
final Object newValue = propertyChangeEvent.getNewValue();
if (newValue instanceof BufferedImage) {
final BufferedImage bufferedImage = (BufferedImage) newValue;
LOGGER.info("New image is being set {}x{}", bufferedImage.getWidth(), bufferedImage.getHeight());
if (newValue instanceof BufferedImage bufferedImage) {
LOGGER.info("New image is being set {}x{}", bufferedImage.getWidth(), bufferedImage.getHeight());
}
});
presentationModel.addBeanPropertyChangeListener(PhotoboothPanelModel.PROPERTY_RESOLUTION, propertyChangeEvent -> {
Object newValue = propertyChangeEvent.getNewValue();
if (newValue instanceof Dimension) {
final Dimension newDimension = (Dimension) newValue;
LOGGER.info("New dimension is {}x{}", newDimension.getWidth(), newDimension.getHeight());
if (newValue instanceof Dimension newDimension) {
LOGGER.info("New dimension is {}x{}", newDimension.getWidth(), newDimension.getHeight());
}
});

Expand Down
10 changes: 4 additions & 6 deletions src/main/java/org/isf/video/gui/PhotoboothComponentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ public Component getListCellRendererComponent(final JList list,
final boolean isSelected,
final boolean cellHasFocus) {
final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof Dimension) {
final Dimension valueAsDimension = (Dimension) value;
setText(String.format("%d x %d", (int) valueAsDimension.getWidth(), (int) valueAsDimension.getHeight()));
if (value instanceof Dimension valueAsDimension) {
setText(String.format("%d x %d", (int) valueAsDimension.getWidth(), (int) valueAsDimension.getHeight()));
}
return component;
}
Expand All @@ -73,9 +72,8 @@ public Component getListCellRendererComponent(final JList list,
final boolean isSelected,
final boolean cellHasFocus) {
final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof Webcam) {
final Webcam webcam = (Webcam) value;
setText(webcam.getName());
if (value instanceof Webcam webcam) {
setText(webcam.getName());
}
return component;
}
Expand Down

0 comments on commit 8b0d775

Please sign in to comment.