algorithm - Java Map with keys of 3 columns -


I need a map in which my key should be based on 3 columns, say C1, C2, C3 . C1 is the highest priority in C2 and C3 in C2 is less than.

How can I make a key in the map if someone asks for information on C1 , then I should be able to give all the values ​​that have C1 if I have C1 & amp; I should be able to return all values ​​even if I have been asked for it. C2

You can use the same strategy as a multicol index in the database If your key column

is an example with an integer column:

can be ordered (i.e., in java, they should be comparable ) And can easily define maximum and minimum values. / P>

  Key Comparative for the Public Class & lt; Key & gt; {Int c1, c2, c3; Private static final full c2_min = integer MIN_VALUE; Private Static Finals Inc. c2_max = integer.mx_avn; Private constant final integer c3_min = integer. Mn_vrn; Private Static Final Inc. c3_max = Integer.MAX_VALUE; Compare override public int (key o) {if (C1! = OC1) returns the integer compass (C1, OC1); If (C2! = OC2) returns the integer compass (C2, OC2); Return Integer.compare (c3, o.c3); } // constructor, equals, ...}   

and then you can get some values ​​like k1 in c1 It is:

  map.subMap (new key (k1, key.c2_min, 0), new key (k1, key.c2_max, 0));   

Similarly, using the first two columns:

  map.subMap (new key (k1, k2, key.c3_min), new key ( K1, K2, Key.c3_max));    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -