Ugly Java data structure
I created the following structure that maps unique double values to one or more pairs of integers:
@SuppressWarnings("@R_758_2419@ing") private static final HashMap<Double,Integer[][]> rules = new HashMap<Double,Integer[][]>() { private static final long serialVersionUID = 1L; { put(-0.6,new Integer[][] { { 1,3 } }); put(-0.3,new Integer[][] { { 2,2 } }); put(0.0,4 },{ 3,3 },{ 4,2 } }); put(0.3,new Integer[][] { { 4,4 } }); put(0.6,new Integer[][] { { 5,3 } }); } };
I can rewrite this simpler - that is, you don't have to deal with warnings (serial version uid, boxing), is it so lengthy?
Solution
The integer corresponding to the use class should be the first Or is it a coincidence that all arrays contain a stack, right?
The second point is that these initialization data can be read from the configuration file
Editor: when I looked at this code again, I realized that doubles was a bit risky as a key in the map If doubles are generated due to mathematical operations, it is not clear whether they are equal to computers (even if they are mathematically equal) Floating point numbers are expressed as approximations in the computer You probably want to associate the value with the interval (example 0.0-0.3) rather than the value itself If you always use the same constant as the key in the array, you can avoid trouble But in this case, you can also use enumeration. If it uses the calculated double precision as the key in the map, no new programmer will have trouble