Skip to content

Instantly share code, notes, and snippets.

@kdabir
Last active March 1, 2016 10:49
Show Gist options
  • Save kdabir/3a3e128533a8fb662771 to your computer and use it in GitHub Desktop.
Save kdabir/3a3e128533a8fb662771 to your computer and use it in GitHub Desktop.
Wroking with NavigableMap in groovy
class X { int a}
def m2 = new TreeMap( [(new X(a:1)): 2, (new X(a:2)): 4] )
// this should throw execetion as Key (X) is not comparable
def map = [ 90: 'A',
75: 'B',
60: 'C',
50: 'D',
35: 'E',
0: 'F'
] as TreeMap
println map.keySet()
println map.descendingKeySet()
println map.firstEntry()
println map.lastEntry()
println map.floorEntry(22)
println map.ceilingEntry(22)
println map.floorEntry(60)
println map.ceilingEntry(60)
println map.floorEntry(92)
println map.ceilingEntry(92)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment