diff options
author | Pacien TRAN-GIRARD | 2015-11-24 15:18:13 +0100 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2015-11-24 15:18:13 +0100 |
commit | 4175fa6eece8e5e557710d2cf810695705bb5968 (patch) | |
tree | 8f11d9d194c458dc59fda41160ccf96a372a0562 /src/ch/epfl/maze/physical/Daedalus.java | |
parent | bda6db0eb45b4fb10d9644d9b7bf2699e17a0e5d (diff) | |
download | maze-solver-4175fa6eece8e5e557710d2cf810695705bb5968.tar.gz |
Use Set instead of List for Animals
Diffstat (limited to 'src/ch/epfl/maze/physical/Daedalus.java')
-rw-r--r-- | src/ch/epfl/maze/physical/Daedalus.java | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/src/ch/epfl/maze/physical/Daedalus.java b/src/ch/epfl/maze/physical/Daedalus.java index 4670064..0179156 100644 --- a/src/ch/epfl/maze/physical/Daedalus.java +++ b/src/ch/epfl/maze/physical/Daedalus.java | |||
@@ -1,7 +1,9 @@ | |||
1 | package ch.epfl.maze.physical; | 1 | package ch.epfl.maze.physical; |
2 | 2 | ||
3 | import java.util.ArrayList; | 3 | import java.util.ArrayList; |
4 | import java.util.HashSet; | ||
4 | import java.util.List; | 5 | import java.util.List; |
6 | import java.util.Set; | ||
5 | import java.util.stream.Collectors; | 7 | import java.util.stream.Collectors; |
6 | import java.util.stream.Stream; | 8 | import java.util.stream.Stream; |
7 | 9 | ||
@@ -14,11 +16,11 @@ import java.util.stream.Stream; | |||
14 | */ | 16 | */ |
15 | public final class Daedalus extends World { | 17 | public final class Daedalus extends World { |
16 | 18 | ||
17 | private final List<Predator> predators; | 19 | private final Set<Predator> predators; |
18 | private final List<Predator> predatorHistory; | 20 | private final Set<Predator> predatorHistory; |
19 | 21 | ||
20 | private final List<Prey> preys; | 22 | private final Set<Prey> preys; |
21 | private final List<Prey> preyHistory; | 23 | private final Set<Prey> preyHistory; |
22 | 24 | ||
23 | /** | 25 | /** |
24 | * Constructs a Daedalus with a labyrinth structure | 26 | * Constructs a Daedalus with a labyrinth structure |
@@ -28,11 +30,11 @@ public final class Daedalus extends World { | |||
28 | public Daedalus(int[][] labyrinth) { | 30 | public Daedalus(int[][] labyrinth) { |
29 | super(labyrinth); | 31 | super(labyrinth); |
30 | 32 | ||
31 | this.predators = new ArrayList<>(); | 33 | this.predators = new HashSet<>(); |
32 | this.predatorHistory = new ArrayList<>(); | 34 | this.predatorHistory = new HashSet<>(); |
33 | 35 | ||
34 | this.preys = new ArrayList<>(); | 36 | this.preys = new HashSet<>(); |
35 | this.preyHistory = new ArrayList<>(); | 37 | this.preyHistory = new HashSet<>(); |
36 | } | 38 | } |
37 | 39 | ||
38 | @Override | 40 | @Override |
@@ -79,28 +81,48 @@ public final class Daedalus extends World { | |||
79 | } | 81 | } |
80 | 82 | ||
81 | @Override | 83 | @Override |
82 | public List<Animal> getAnimals() { | 84 | public Set<Animal> getAnimalSet() { |
83 | return Stream | 85 | return Stream |
84 | .concat(this.predators.stream(), this.preys.stream()) | 86 | .concat(this.predators.stream(), this.preys.stream()) |
85 | .collect(Collectors.toList()); | 87 | .collect(Collectors.toSet()); |
88 | } | ||
89 | |||
90 | /** | ||
91 | * Returns a copy of the set of all current predators in the daedalus. | ||
92 | * | ||
93 | * @return A set of all predators in the daedalus | ||
94 | */ | ||
95 | public Set<Predator> getPredatorSet() { | ||
96 | return new HashSet<>(this.predators); | ||
86 | } | 97 | } |
87 | 98 | ||
88 | /** | 99 | /** |
89 | * Returns a copy of the list of all current predators in the daedalus. | 100 | * Returns a copy of the list of all current predators in the daedalus. |
90 | * | 101 | * |
91 | * @return A list of all predators in the daedalus | 102 | * @return A list of all predators in the daedalus |
103 | * @deprecated Use @code{Set<Predator> getPredatorSet()} instead | ||
92 | */ | 104 | */ |
93 | public List<Predator> getPredators() { | 105 | public List<Predator> getPredators() { |
94 | return this.predators; | 106 | return new ArrayList<>(this.getPredatorSet()); |
107 | } | ||
108 | |||
109 | /** | ||
110 | * Returns a copy of the set of all current preys in the daedalus. | ||
111 | * | ||
112 | * @return A set of all preys in the daedalus | ||
113 | */ | ||
114 | public Set<Prey> getPreySet() { | ||
115 | return new HashSet<>(this.preys); | ||
95 | } | 116 | } |
96 | 117 | ||
97 | /** | 118 | /** |
98 | * Returns a copy of the list of all current preys in the daedalus. | 119 | * Returns a copy of the list of all current preys in the daedalus. |
99 | * | 120 | * |
100 | * @return A list of all preys in the daedalus | 121 | * @return A list of all preys in the daedalus |
122 | * @deprecated Use @code{Set<Prey> getPreySet()} instead | ||
101 | */ | 123 | */ |
102 | public List<Prey> getPreys() { | 124 | public List<Prey> getPreys() { |
103 | return this.preys; | 125 | return new ArrayList<>(this.getPreySet()); |
104 | } | 126 | } |
105 | 127 | ||
106 | /** | 128 | /** |