Skip to content

Commit

Permalink
Refactored copyAll method to reduce NPath complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
fulminazzo committed Dec 24, 2024
1 parent 1d267ad commit c1d5cc9
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions gui/base/src/main/java/it/fulminazzo/yagl/guis/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -1342,31 +1342,36 @@ default int southEast() {
if (other.size() != size())
throw new IllegalArgumentException(String.format("Cannot copy from GUI with different size %s != %s",
size(), other.size()));
if (other.getTitle() == null || replace) other.setTitle(getTitle());
copyAll((Metadatable) other, replace);
for (int i = 0; i < size(); i++) {
final @NotNull List<GUIContent> contents = getContents(i);
if (contents.isEmpty()) continue;
if (other.getContents(i).isEmpty() || replace)
other.setContents(i, contents.toArray(new GUIContent[0]));
else {
if (other.getTitle() == null || replace) other.setTitle(getTitle());

copyAll((Metadatable) other, replace);

for (int i = 0; i < size(); i++) {
final @NotNull List<GUIContent> contents = getContents(i);
if (!contents.isEmpty() && (other.getContents(i).isEmpty() || replace))
other.setContents(i, contents.toArray(new GUIContent[0]));
}

openGUIAction().ifPresent(a -> {
@NotNull Optional<GUIAction> open = other.openGUIAction();
if (!open.isPresent() || replace) other.onOpenGUI(a);
});
closeGUIAction().ifPresent(a -> {
@NotNull Optional<GUIAction> close = other.closeGUIAction();
if (!close.isPresent() || replace) other.onCloseGUI(a);
});
changeGUIAction().ifPresent(a -> {
@NotNull Optional<BiGUIAction> change = other.changeGUIAction();
if (!change.isPresent() || replace) other.onChangeGUI(a);
});
clickOutsideAction().ifPresent(a -> {
@NotNull Optional<GUIAction> clickOutside = other.clickOutsideAction();
if (!clickOutside.isPresent() || replace) other.onClickOutside(a);
});

return this;
}
openGUIAction().ifPresent(a -> {
@NotNull Optional<GUIAction> open = other.openGUIAction();
if (!open.isPresent() || replace) other.onOpenGUI(a);
});
closeGUIAction().ifPresent(a -> {
@NotNull Optional<GUIAction> close = other.closeGUIAction();
if (!close.isPresent() || replace) other.onCloseGUI(a);
});
changeGUIAction().ifPresent(a -> {
@NotNull Optional<BiGUIAction> change = other.changeGUIAction();
if (!change.isPresent() || replace) other.onChangeGUI(a);
});
clickOutsideAction().ifPresent(a -> {
@NotNull Optional<GUIAction> clickOutside = other.clickOutsideAction();
if (!clickOutside.isPresent() || replace) other.onClickOutside(a);
});
return this;
}

/**
Expand Down

0 comments on commit c1d5cc9

Please sign in to comment.