Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
  1. Instead of implementing isSame implement equals and hashCode. After that you could use a HashSet (or LinkedHashSet 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

  1. According to the Java Code Conventions, class names in Java usually starts with uppercase letters.
  1. Instead of implementing isSame implement equals and hashCode. After that you could use a HashSet (or LinkedHashSet 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

  1. According to the Java Code Conventions, class names in Java usually starts with uppercase letters.
  1. Instead of implementing isSame implement equals and hashCode. After that you could use a HashSet (or LinkedHashSet 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

  1. According to the Java Code Conventions, class names in Java usually starts with uppercase letters.
added 138 characters in body
Source Link
palacsint
  • 30.3k
  • 9
  • 82
  • 157
  1. Instead of implementing isSame implement equals and hashCode. After that you could use a HashSet (or LinkedHashSet 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

  1. According to the Java Code Conventions, class names in Java usually starts with uppercase letters.
  1. Instead of implementing isSame implement equals and hashCode. After that you could use a HashSet (or LinkedHashSet 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

  1. According to the Java Code Conventions, class names in Java usually starts with uppercase letters.
  1. Instead of implementing isSame implement equals and hashCode. After that you could use a HashSet (or LinkedHashSet 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

  1. According to the Java Code Conventions, class names in Java usually starts with uppercase letters.
Source Link
palacsint
  • 30.3k
  • 9
  • 82
  • 157
  1. Instead of implementing isSame implement equals and hashCode. After that you could use a HashSet (or LinkedHashSet 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

  1. According to the Java Code Conventions, class names in Java usually starts with uppercase letters.
lang-java

AltStyle によって変換されたページ (->オリジナル) /