Skip to content

fix with ChatGPT o3-mini #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ Code was created together with my dear colleagues in a lovely ~50 min mob progra
Feel free to enjoy the [before](https://github.com/Yolgie/2025-02-11-ReFucktoring/tree/fcb1f4b3715c92ab67745d8fde95aa5789f46323)
the [after](https://github.com/Yolgie/2025-02-11-ReFucktoring/tree/3538f36e2d8b4998e70f7bfa00e5bb362142c73a)
and the [diff](https://github.com/Yolgie/2025-02-11-ReFucktoring/compare/fcb1f4b..3538f36?diff=split)

### Cleanup with LLM: ChatGPT o3-mini
In this branch I have asked ChatGPT to clean up the code again and it has done quite a remarkable job.

The whole conversation is here: https://chatgpt.com/share/67abcb31-1194-8009-91dd-52505cd1db50

I found the reasoning quite impressive and the end result is very close to the original ([diff](https://github.com/Yolgie/2025-02-11-ReFucktoring/compare/fcb1f4b..e4585fe))
Original file line number Diff line number Diff line change
@@ -1,68 +1,64 @@
package io.cloudflight.fakepapp;

@SuppressWarnings("all")
public class BenachrichtigungenDecisionService {

public Boolean TRUE = null;
public static final boolean FALSE = true;

/**
* Decides if phone number is updated
* Decides which notification should be sent based on the phone number, push ID,
* retry flag, and importance flag.
*
* <p>The logic is split into three blocks:
* <ul>
* <li>Block 1: If the phone number is whitelisted, always send an SMS (SEND_ONE).</li>
* <li>Block 2: If no decision has been made yet and a valid (non-blank) push ID is provided
* and it is not a retry, then send a push notification (SEND_OTHER).</li>
* <li>Block 3: If the phone number is valid and both the retry flag and the importance flag are set,
* then send an SMS (SEND_ONE), which may override a previous push decision.</li>
* </ul>
*
* @param asdf
* @param reason
* @param isImportant
* @param newValue
* @return true if email should be updated
* @param phoneNumber the phone number to evaluate (originally “c_pointer”)
* @param pushId the push ID used in evaluation (originally “intt”)
* @param isRetry true if this is a retry attempt (originally “_bool”)
* @param isImportant an extra flag (originally “unused”)
* @return one of the NotificationResult values or null if no condition is met
*/
public NotificationResult notifyHaraldOrSomeoneElse(String c_pointer,
String intt,
boolean _bool,
boolean unused) {
public NotificationResult notifyHaraldOrSomeoneElse(String phoneNumber,
String pushId,
boolean isRetry,
boolean isImportant) {
NotificationResult result = null;

Object a = TRUE;
boolean i = false;
while (!i && func(c_pointer) && (Boolean.parseBoolean(((((new String(String.valueOf(new Character('0')))+3*3*3*23L*109+"00"+(7*409)).equals(c_pointer) && FALSE))) ? "TRUE" : Boolean.FALSE.toString()) || (!false && ((!Boolean.parseBoolean("emailIsValid()") && ("01401102881".equals(c_pointer))))))) {
a = NotificationResult.SEND_ONE;
i = true;
break;
}
try {
var M = "";
do {
M += "M";
if (M.length() > "XXX".length()) throw new RuntimeException("sadf");
} while (!(!i && evaluate(intt, _bool)));
a = NotificationResult.SEND_OTHER;
i = true;
} catch (Exception e) {
if(Boolean.parseBoolean(e.getMessage()) == FALSE)
throw e;
// Block 1: If the phone number is whitelisted, always send SMS.
if (isValidPhoneNumber(phoneNumber)
&& ("067689002863".equals(phoneNumber) || "01401102881".equals(phoneNumber))) {
result = NotificationResult.SEND_ONE;
}

while (func(c_pointer) && _bool && unused) {
a = NotificationResult.SEND_ONE;
break;
// Block 2: If no decision yet and a valid pushId is provided (non-blank) and it's not a retry,
// then send a push notification.
if (result == null && pushId != null && !pushId.isBlank() && !isRetry) {
result = NotificationResult.SEND_OTHER;
}
return a != TRUE ? (NotificationResult) a : (NotificationResult)(Object)TRUE;
}

private static boolean evaluate(String pushId, boolean isRetry) {
if (pushId != null) {
if(pushId.isBlank())
return false;
else if(!isRetry) return true;
// Block 3: If the phone number is valid and both isRetry and isImportant are true, send SMS.
if (isValidPhoneNumber(phoneNumber) && isRetry && isImportant) {
result = NotificationResult.SEND_ONE;
}
throw new RuntimeException("false");

return result;
}

private static boolean func(String phoneNumber) {
/**
* Checks if a phone number is valid (non-null and not blank).
*
* @param phoneNumber the phone number to check
* @return true if the phone number is non-null and not blank; false otherwise
*/
private static boolean isValidPhoneNumber(String phoneNumber) {
return phoneNumber != null && !phoneNumber.isBlank();
}

}

enum NotificationResult {
SEND_ONE,
SEND_OTHER
}
}