To solve a problem, I'm pre-populating a Map and then trying to pull the answer out of the map later when needed.
The map is populated like this:
var cycles = {
[0, 0, 0, 0, 0, 0, 0, 0] : [[0, 1, 1, 1, 1, 1, 1, 0], [0, 0, 1, 1, 1, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0], [0, 1, 0, 0, 0, 0, 1, 0], [0, 1, 0, 1, 1, 0, 1, 0], [0, 1, 1, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 0], [0, 0, 1, 1, 1, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0], [0, 1, 0, 0, 0, 0, 1, 0], [0, 1, 0, 1, 1, 0, 1, 0], [0, 1, 1, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0]],
[0, 0, 0, 0, 0, 0, 0, 1] : [[0, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0], [0, 1, 0, 1, 0, 0, 1, 0], [0, 1, 1, 1, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0, 1, 0], [0, 0, 1, 0, 1, 0, 1, 0], [0, 0, 1, 1, 1, 1, 1, 0], [0, 0, 0, 1, 1, 1, 0, 0], [0, 1, 0, 0, 1, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [0, 1, 0, 0, 1, 1, 1, 0], [0, 1, 0, 0, 0, 1, 0, 0], [0, 1, 0, 1, 0, 1, 0, 0]],
...
};
Later, a function is called like this:
print(pullAnswerFromMap([1,0,0,1,0,0,1,0], 1000000000));
Where the pullAnswerFromMap function is defined as:
return cycles[cells][N % 14 == 0 ? 14 : N % 14];
The cycles map will have every possible key - all 256 lists of 8 bits.
But when running the code with an example to test, I get the following:
Unhandled exception:
NoSuchMethodError: The method '[]' was called on null.
Receiver: null
So, before the return statement, I added print(cycles); - The map prints just fine. All data is there.
Then I added print(cycles[[1,0,0,1,0,0,1,0]]); which prints null, even though I can see that it exists in the map in the output from the previous print statement.
So it seems as though the key isn't based on the equality of the lists, but somehow on the specific instance (memory address?) of the list. A new list with the same elements in the same order will return null when trying to retrieve the value from the map.
My question is: How can I fix this so that cycles[[1,0,0,1,0,0,1,0]] doesn't return null and instead returns the List<List<int>> that it is associated with?