-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptionsParser.java
More file actions
28 lines (25 loc) · 1.03 KB
/
OptionsParser.java
File metadata and controls
28 lines (25 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package agh.ics.oop;
import agh.ics.oop.model.MoveDirection;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class OptionsParser {
public static List<MoveDirection> Parser(String[] args) {
MoveDirection[] moveDirection = new MoveDirection[args.length];
List<MoveDirection> MoveDirectionList = new ArrayList<>();
for(int i = 0; i < args.length; i++){
if (Objects.equals(args[i], "f")) {
MoveDirectionList.add(MoveDirection.FORWARD);
} else if (Objects.equals(args[i], "b")) {
MoveDirectionList.add(MoveDirection.BACKWARD);
} else if (Objects.equals(args[i], "l")) {
MoveDirectionList.add(MoveDirection.LEFT);
} else if (Objects.equals(args[i], "r")) {
MoveDirectionList.add(MoveDirection.RIGHT);
} else {
throw new IllegalArgumentException(args[i] + " " + "is not legal move");
}
}
return MoveDirectionList;
}
}