Skip to content

Commit ac7084f

Browse files
Update VirtualMachine.java
Change code Style of Switch
1 parent 8bd3175 commit ac7084f

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

bytecode/src/main/java/com/iluwatar/bytecode/VirtualMachine.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,59 +67,60 @@ public void execute(int[] bytecode) {
6767
for (var i = 0; i < bytecode.length; i++) {
6868
Instruction instruction = Instruction.getInstruction(bytecode[i]);
6969
switch (instruction) {
70-
case LITERAL:
70+
case LITERAL -> {
7171
// Read the next byte from the bytecode.
7272
int value = bytecode[++i];
7373
// Push the next value to stack
7474
stack.push(value);
75-
break;
76-
case SET_AGILITY:
75+
}
76+
case SET_AGILITY -> {
7777
var amount = stack.pop();
7878
var wizard = stack.pop();
7979
setAgility(wizard, amount);
80-
break;
81-
case SET_WISDOM:
80+
}
81+
case SET_WISDOM -> {
8282
amount = stack.pop();
8383
wizard = stack.pop();
8484
setWisdom(wizard, amount);
85-
break;
86-
case SET_HEALTH:
85+
}
86+
case SET_HEALTH -> {
8787
amount = stack.pop();
8888
wizard = stack.pop();
8989
setHealth(wizard, amount);
90-
break;
91-
case GET_HEALTH:
90+
}
91+
case GET_HEALTH -> {
9292
wizard = stack.pop();
9393
stack.push(getHealth(wizard));
94-
break;
95-
case GET_AGILITY:
94+
}
95+
case GET_AGILITY -> {
9696
wizard = stack.pop();
9797
stack.push(getAgility(wizard));
98-
break;
99-
case GET_WISDOM:
98+
}
99+
case GET_WISDOM -> {
100100
wizard = stack.pop();
101101
stack.push(getWisdom(wizard));
102-
break;
103-
case ADD:
102+
}
103+
case ADD -> {
104104
var a = stack.pop();
105105
var b = stack.pop();
106106
stack.push(a + b);
107-
break;
108-
case DIVIDE:
107+
}
108+
case DIVIDE -> {
109109
a = stack.pop();
110110
b = stack.pop();
111111
stack.push(b / a);
112-
break;
113-
case PLAY_SOUND:
112+
}
113+
case PLAY_SOUND -> {
114114
wizard = stack.pop();
115115
getWizards()[wizard].playSound();
116-
break;
117-
case SPAWN_PARTICLES:
116+
}
117+
case SPAWN_PARTICLES -> {
118118
wizard = stack.pop();
119119
getWizards()[wizard].spawnParticles();
120-
break;
121-
default:
120+
}
121+
default -> {
122122
throw new IllegalArgumentException("Invalid instruction value");
123+
}
123124
}
124125
LOGGER.info("Executed " + instruction.name() + ", Stack contains " + getStack());
125126
}

0 commit comments

Comments
 (0)