-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added hashCode override in State and tested semi-fully
- Loading branch information
Showing
50 changed files
with
2,382 additions
and
1,562 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
19 changes: 19 additions & 0 deletions
19
.metadata/.plugins/org.eclipse.core.resources/.history/1d/203b20fb388700151ace8a9637c977f8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
State s1 = new State("q1", "1"); | ||
State s2 = new State("q2", "2"); | ||
State s3 = new State("q1", "1"); | ||
|
||
Map<State, Integer> map = new HashMap<>(); | ||
map.put(s1, 1); | ||
map.put(s2, 2); | ||
|
||
System.out.println("contains: " + map.containsKey(s3)); | ||
System.out.println("get: " + map.get(s3)); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
.metadata/.plugins/org.eclipse.core.resources/.history/25/90b7d16a3a8700151ace8a9637c977f8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
State s1 = new State("q1", "1"); | ||
State s2 = new State("q2", "2"); | ||
State s3 = new State("q1", "1"); | ||
State s4 = new State("q1", "1"); | ||
State s5 = new State("q1", "1"); | ||
State s6 = new State("q1", "1"); | ||
|
||
Map<State, Integer> map = new HashMap<>(); | ||
map.put(s1, 1); | ||
map.put(s2, 2); | ||
|
||
System.out.println("s1 hash: " + s1.hashCode()); | ||
System.out.println("s3 hash: " + s3.hashCode()); | ||
|
||
System.out.println("contains: " + map.containsKey(s3)); | ||
System.out.println("get: " + map.get(s3)); | ||
|
||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
.metadata/.plugins/org.eclipse.core.resources/.history/26/a07d3d80388700151ace8a9637c977f8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
State s1 = new State("q1", "1"); | ||
State s2 = new State("q2", "1"); | ||
State s3 = new State("q1", "1"); | ||
|
||
Map<State, Integer> map = new HashMap<>(); | ||
map.put(s1, 1); | ||
map.put(s2, 2); | ||
|
||
System.out.println(map.getKey(s3)); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
.metadata/.plugins/org.eclipse.core.resources/.history/2d/90ac37cb388700151ace8a9637c977f8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
State s1 = new State("q1", "1"); | ||
State s2 = new State("q2", "2"); | ||
State s3 = new State("q1", "1"); | ||
|
||
Map<State, Integer> map = new HashMap<>(); | ||
map.put(s1, 1); | ||
map.put(s2, 2); | ||
|
||
System.out.println("contains " + map.containsKey(s3)); | ||
System.out.println("get " + map.get(s3)); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
.metadata/.plugins/org.eclipse.core.resources/.history/2f/20059651398700151ace8a9637c977f8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
State s1 = new State("q1", "1"); | ||
State s2 = new State("q2", "2"); | ||
State s3 = new State("q1", "1"); | ||
State s4 = new State("q1", "1"); | ||
State s5 = new State("q1", "1"); | ||
State s6 = new State("q1", "1"); | ||
|
||
Map<State, Integer> map = new HashMap<>(); | ||
map.put(s1, 1); | ||
map.put(s2, 2); | ||
|
||
System.out.println("contains: " + map.containsKey(s3)); | ||
System.out.println("get: " + map.get(s3)); | ||
|
||
System.out.println("contains 4: " + map.containsKey(s4)); | ||
System.out.println("get 4: " + map.get(s4)); | ||
System.out.println("contains 5: " + map.containsKey(s5)); | ||
System.out.println("get: " + map.get(s5)); | ||
System.out.println("contains 6: " + map.containsKey(s6)); | ||
System.out.println("get: " + map.get(s6)); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
.metadata/.plugins/org.eclipse.core.resources/.history/34/10cdeb103a8700151ace8a9637c977f8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
public class State { | ||
private String q; | ||
private String input; | ||
|
||
public State(String q, String input){ | ||
this.q = q; | ||
this.input = input; | ||
} | ||
|
||
public String getState(){ | ||
return q; | ||
} | ||
|
||
public String getInput(){ | ||
return input; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o){ | ||
if( o instanceof State){ | ||
return(this.q.equals(((State) o).getState()) && this.input.equals(((State) o).getInput())); | ||
} | ||
return false; | ||
} | ||
|
||
@Override public int hashCode() { | ||
return (41 * (41 + getState().length()) + getInput().length()); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
.metadata/.plugins/org.eclipse.core.resources/.history/4d/a08c4cba3a8700151ace8a9637c977f8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
State s1 = new State("q1", '1'); | ||
State s2 = new State("q2", '2'); | ||
State s3 = new State("q1", '1'); | ||
State s4 = new State("q1", '1'); | ||
State s5 = new State("q3", '1'); | ||
State s6 = new State("q1", '1'); | ||
|
||
Map<State, Integer> map = new HashMap<>(); | ||
map.put(s1, 1); | ||
map.put(s2, 2); | ||
map.put(s4, 3); | ||
|
||
System.out.println("s1 hash: " + s1.hashCode()); | ||
System.out.println("s3 hash: " + s3.hashCode()); | ||
|
||
System.out.println("s4 hash: " + s4.hashCode()); | ||
System.out.println("s5 hash: " + s5.hashCode()); | ||
|
||
System.out.println("contains: " + map.containsKey(s3)); | ||
System.out.println("get: " + map.get(s3)); | ||
|
||
System.out.println("contains: " + map.containsKey(s5)); | ||
System.out.println("get: " + map.get(s5)); | ||
|
||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
.metadata/.plugins/org.eclipse.core.resources/.history/55/102747293a8700151ace8a9637c977f8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
public class State { | ||
private String q; | ||
private String input; | ||
|
||
public State(String q, String input){ | ||
this.q = q; | ||
this.input = input; | ||
} | ||
|
||
public String getState(){ | ||
return q; | ||
} | ||
|
||
public String getInput(){ | ||
return input; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o){ | ||
if( o instanceof State){ | ||
return(this.q.equals(((State) o).getState()) && this.input.equals(((State) o).getInput())); | ||
} | ||
return false; | ||
} | ||
|
||
@Override public int hashCode() { | ||
return (41 * (41 + getState().length()) + 7 * getInput().length()); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
.metadata/.plugins/org.eclipse.core.resources/.history/57/101d1675388700151ace8a9637c977f8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
.metadata/.plugins/org.eclipse.core.resources/.history/6/905a54f43a8700151ace8a9637c977f8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class HashTest { | ||
|
||
public static void main(String[] args) { | ||
State s1 = new State("q1", '1'); | ||
State s2 = new State("q2", '2'); | ||
State s3 = new State("q1", '1'); | ||
State s4 = new State("q1", '1'); | ||
State s5 = new State("q3", '1'); | ||
State s6 = new State("q1", '1'); | ||
|
||
Map<State, Integer> map = new HashMap<>(); | ||
map.put(s1, 1); | ||
map.put(s2, 2); | ||
map.put(s4, 3); | ||
|
||
System.out.println("s1 hash: " + s1.hashCode()); | ||
System.out.println("s3 hash: " + s3.hashCode()); | ||
|
||
System.out.println("s4 hash: " + s4.hashCode()); | ||
System.out.println("s5 hash: " + s5.hashCode()); | ||
|
||
System.out.println("contains: " + map.containsKey(s3)); | ||
System.out.println("get: " + map.get(s3)); | ||
|
||
System.out.println("contains: " + map.containsKey(s5)); | ||
System.out.println("get: " + map.get(s5)); | ||
|
||
/* | ||
* s1 = s4 | ||
*/ | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
.metadata/.plugins/org.eclipse.core.resources/.history/72/104f6fc6388700151ace8a9637c977f8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
State s1 = new State("q1", "1"); | ||
State s2 = new State("q2", "1"); | ||
State s3 = new State("q1", "1"); | ||
|
||
Map<State, Integer> map = new HashMap<>(); | ||
map.put(s1, 1); | ||
map.put(s2, 2); | ||
|
||
System.out.println(map.get(s3)); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
.metadata/.plugins/org.eclipse.core.resources/.history/72/10f984133b8700151ace8a9637c977f8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class HashTest { | ||
|
||
public static void main(String[] args) { | ||
State s1 = new State("q1", '1'); | ||
State s2 = new State("q2", '2'); | ||
State s3 = new State("q1", '1'); | ||
State s4 = new State("q1", '2'); | ||
State s5 = new State("q1", '2'); | ||
State s6 = new State("q1", '1'); | ||
|
||
Map<State, Integer> map = new HashMap<>(); | ||
map.put(s1, 1); | ||
map.put(s2, 2); | ||
map.put(s4, 3); | ||
|
||
System.out.println("s1 hash: " + s1.hashCode()); | ||
System.out.println("s3 hash: " + s3.hashCode()); | ||
|
||
System.out.println("s4 hash: " + s4.hashCode()); | ||
System.out.println("s5 hash: " + s5.hashCode()); | ||
|
||
System.out.println("contains: " + map.containsKey(s3)); | ||
System.out.println("get: " + map.get(s3)); | ||
|
||
System.out.println("contains: " + map.containsKey(s5)); | ||
System.out.println("get: " + map.get(s5)); | ||
|
||
/* | ||
* s1 = s4 = (q1, 1), s5 = (q3, 1) | ||
* s3 = true, 3, s5 = false | ||
* | ||
* s1 = (q1, 1), s4 = (q3, 1), s5 = (q3, 1) | ||
* s3 = true, 1, s5 = true, 3 | ||
*/ | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
.metadata/.plugins/org.eclipse.core.resources/.history/78/102906953a8700151ace8a9637c977f8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
State s1 = new State("q1", '1'); | ||
State s2 = new State("q2", '2'); | ||
State s3 = new State("q1", '1'); | ||
State s4 = new State("q1", '1'); | ||
State s5 = new State("q1", '1'); | ||
State s6 = new State("q1", '1'); | ||
|
||
Map<State, Integer> map = new HashMap<>(); | ||
map.put(s1, 1); | ||
map.put(s2, 2); | ||
map.put(s4, 3); | ||
|
||
System.out.println("s1 hash: " + s1.hashCode()); | ||
System.out.println("s3 hash: " + s3.hashCode()); | ||
|
||
System.out.println("s4 hash: " + s4.hashCode()); | ||
System.out.println("s5 hash: " + s5.hashCode()); | ||
|
||
System.out.println("contains: " + map.containsKey(s3)); | ||
System.out.println("get: " + map.get(s3)); | ||
|
||
System.out.println("contains: " + map.containsKey(s5)); | ||
System.out.println("get: " + map.get(s5)); | ||
|
||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
.metadata/.plugins/org.eclipse.core.resources/.history/80/a07c1775388700151ace8a9637c977f8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
public class State { | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
.metadata/.plugins/org.eclipse.core.resources/.history/9b/a0fd4eba3a8700151ace8a9637c977f8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class HashTest { | ||
|
||
public static void main(String[] args) { | ||
State s1 = new State("q1", '1'); | ||
State s2 = new State("q2", '2'); | ||
State s3 = new State("q1", '1'); | ||
State s4 = new State("q1", '1'); | ||
State s5 = new State("q3", '1'); | ||
State s6 = new State("q1", '1'); | ||
|
||
Map<State, Integer> map = new HashMap<>(); | ||
map.put(s1, 1); | ||
map.put(s2, 2); | ||
map.put(s4, 3); | ||
|
||
System.out.println("s1 hash: " + s1.hashCode()); | ||
System.out.println("s3 hash: " + s3.hashCode()); | ||
|
||
System.out.println("s4 hash: " + s4.hashCode()); | ||
System.out.println("s5 hash: " + s5.hashCode()); | ||
|
||
System.out.println("contains: " + map.containsKey(s3)); | ||
System.out.println("get: " + map.get(s3)); | ||
|
||
System.out.println("contains: " + map.containsKey(s5)); | ||
System.out.println("get: " + map.get(s5)); | ||
|
||
/* | ||
* | ||
*/ | ||
} | ||
|
||
} |
Oops, something went wrong.