Instead of implementing
isSame
implementequals
andhashCode
. After that you could use aHashSet
(orLinkedHashSet
if the order of elements is important). Set is a collection that contains no duplicate elements and inserting/searching is much faster than searching in a list.Set<GameState> opened = new LinkedHashSet<GameState>(); public void addEverything() { List<GameState> list = current.neighbours; for (GameState state : list) { opened.add(state); } }
If you need a list, you can convert it back after the loop:
List<GameState> openedList = new ArrayList<GameState>(opened);
See also: Overriding equals and hashCode in Java Overriding equals and hashCode in Java
- According to the Java Code Conventions, class names in Java usually starts with uppercase letters.
Instead of implementing
isSame
implementequals
andhashCode
. After that you could use aHashSet
(orLinkedHashSet
if the order of elements is important). Set is a collection that contains no duplicate elements and inserting/searching is much faster than searching in a list.Set<GameState> opened = new LinkedHashSet<GameState>(); public void addEverything() { List<GameState> list = current.neighbours; for (GameState state : list) { opened.add(state); } }
If you need a list, you can convert it back after the loop:
List<GameState> openedList = new ArrayList<GameState>(opened);
See also: Overriding equals and hashCode in Java
- According to the Java Code Conventions, class names in Java usually starts with uppercase letters.
Instead of implementing
isSame
implementequals
andhashCode
. After that you could use aHashSet
(orLinkedHashSet
if the order of elements is important). Set is a collection that contains no duplicate elements and inserting/searching is much faster than searching in a list.Set<GameState> opened = new LinkedHashSet<GameState>(); public void addEverything() { List<GameState> list = current.neighbours; for (GameState state : list) { opened.add(state); } }
If you need a list, you can convert it back after the loop:
List<GameState> openedList = new ArrayList<GameState>(opened);
See also: Overriding equals and hashCode in Java
- According to the Java Code Conventions, class names in Java usually starts with uppercase letters.
Instead of implementing
isSame
implementequals
andhashCode
. After that you could use aHashSet
(orLinkedHashSet
if the order of elements is important). Set is a collection that contains no duplicate elements and inserting/searching is much faster than searching in a list.Set<GameState> opened = new LinkedHashSet<GameState>(); public void addEverything() { List<GameState> list = current.neighbours; for (GameState state : list) { opened.add(state); } }
If you need a list, you can convert it back after the loop:
List<GameState> openedList = new ArrayList<GameState>(opened);
See also: Overriding equals and hashCode in Java
- According to the Java Code Conventions, class names in Java usually starts with uppercase letters.
Instead of implementing
isSame
implementequals
andhashCode
. After that you could use aHashSet
(orLinkedHashSet
if the order of elements is important). Set is a collection that contains no duplicate elements and inserting/searching is much faster than searching in a list.Set<GameState> opened = new LinkedHashSet<GameState>(); public void addEverything() { List<GameState> list = current.neighbours; for (GameState state : list) { opened.add(state); } }
See also: Overriding equals and hashCode in Java
- According to the Java Code Conventions, class names in Java usually starts with uppercase letters.
Instead of implementing
isSame
implementequals
andhashCode
. After that you could use aHashSet
(orLinkedHashSet
if the order of elements is important). Set is a collection that contains no duplicate elements and inserting/searching is much faster than searching in a list.Set<GameState> opened = new LinkedHashSet<GameState>(); public void addEverything() { List<GameState> list = current.neighbours; for (GameState state : list) { opened.add(state); } }
If you need a list, you can convert it back after the loop:
List<GameState> openedList = new ArrayList<GameState>(opened);
See also: Overriding equals and hashCode in Java
- According to the Java Code Conventions, class names in Java usually starts with uppercase letters.
Instead of implementing
isSame
implementequals
andhashCode
. After that you could use aHashSet
(orLinkedHashSet
if the order of elements is important). Set is a collection that contains no duplicate elements and inserting/searching is much faster than searching in a list.Set<GameState> opened = new LinkedHashSet<GameState>(); public void addEverything() { List<GameState> list = current.neighbours; for (GameState state : list) { opened.add(state); } }
See also: Overriding equals and hashCode in Java
- According to the Java Code Conventions, class names in Java usually starts with uppercase letters.