-
Notifications
You must be signed in to change notification settings - Fork 0
Create OrderProcessor.java #10
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,38 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.HashMap;Add commentMore actions | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Map; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| public class OrderProcessor { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static final String MODE_NEW = "NEW"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static final String MODE_LEGACY = "LEGACY"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Simulate different servers with different code versions | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static final Map<String, String> serverModes = new HashMap<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| static { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Server A runs new code | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| serverModes.put("ServerA", MODE_NEW); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Server B accidentally runs legacy code | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| serverModes.put("ServerB", MODE_LEGACY); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static void main(String[] args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| processOrder("ServerA", 100, "BUY"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| processOrder("ServerB", 100, "BUY"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static void processOrder(String server, int qty, String side) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| String mode = serverModes.get(server); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (MODE_NEW.equals(mode)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| placeOrder(qty, side); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (MODE_LEGACY.equals(mode)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (int i = 0; i < 1000; i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| placeOrder(qty, side); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+24
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for unknown servers and consider the legacy behavior impact. The method has two significant concerns:
public static void processOrder(String server, int qty, String side) {
String mode = serverModes.get(server);
+ if (mode == null) {
+ throw new IllegalArgumentException("Unknown server: " + server);
+ }
+
if (MODE_NEW.equals(mode)) {
placeOrder(qty, side);
} else if (MODE_LEGACY.equals(mode)) {
+ System.out.println("WARNING: Legacy mode will place order 1000 times");
for (int i = 0; i < 1000; i++) {
placeOrder(qty, side);
}
}
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static void placeOrder(int qty, String side) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("Placed order: " + side + " " + qty + " shares"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the UI artifact from the import statement.
There appears to be a UI artifact "Add commentMore actions" appended to the import statement that should be removed.
📝 Committable suggestion
🤖 Prompt for AI Agents