I don’t really know how to describe my issue, so I’ll just show a code example:
int[][][] mat;
int n;
int specificValue;
for (int i = 0; i < n; i++) {
if(mat[i][n-i][3] != specificValue) {
doStuff();
}
}
I’m looking up Integer values in a 3d-array. For each field I have to use one of these:
- a counter running from zero to n
- a counter running from n to zero
- a fixed value
So i’ve tried to build a Method that would save me from writing this for loop about 20 times, but i failed, so that’s where i need help. My idea was something like this:
search(Loop.UP, Loop.DOWN, Loop.FIXED);
where “Loop” would be an enum representing one of my possibilities, but I don’t know how to implement it or if this is even possible in Java without hardcoding every possible combination.
Hope you can help 🙂
OK, more specific… with my setup i’m drawing a vector through this 3d-array, a diagonal to be specific and i want to know what values are on this vector and only on this vector.
And because there is more than one possibility to draw such a vector, i’d like to have a more general method to get to the values. My search could just be as simple as
search(Loop.UP, Loop.FIXED, Loop.FIXED); // one plane
which would be a simple for-loop with one counter, but also
search(Loop.DOWN, Loop.UP, Loop.UP); // through all three planes
where
I didn’t use an Enum because
Downdepends onnandFixedon some value.