/src/lib/storage/collection/dictionary_key_traverser.e

http://github.com/tybor/Liberty · Specman e · 97 lines · 57 code · 15 blank · 25 comment · 0 complexity · 10b7810a6ec56c9632526dd060765348 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class DICTIONARY_KEY_TRAVERSER[V_, K_]
  5. -- This class allows you to view a MAP[V_, K_] as a TRAVERSABLE[K_]. Note that there is no need for
  6. -- a DICTIONARY_ITEM_TRAVERSER because MAP[V_, K_] is already a TRAVERSABLE[V_].
  7. inherit
  8. TRAVERSABLE[K_]
  9. create {ANY}
  10. from_dictionary
  11. create {MAP}
  12. from_map
  13. feature {}
  14. from_map (map_: like map)
  15. do
  16. map := map_
  17. end
  18. feature {ANY}
  19. from_dictionary (map_: like map)
  20. obsolete "Use MAP#`keys' instead."
  21. do
  22. from_map(map)
  23. end
  24. feature {ANY}
  25. lower: INTEGER
  26. do
  27. Result := map.lower
  28. end
  29. upper: INTEGER
  30. do
  31. Result := map.upper
  32. end
  33. feature {ANY}
  34. count: INTEGER
  35. do
  36. Result := map.count
  37. end
  38. is_empty: BOOLEAN
  39. do
  40. Result := map.is_empty
  41. end
  42. feature {ANY}
  43. item (i: INTEGER): K_
  44. do
  45. Result := map.key(i)
  46. end
  47. first: like item
  48. do
  49. Result := item(lower)
  50. end
  51. last: like item
  52. do
  53. Result := item(upper)
  54. end
  55. feature {ANY}
  56. new_iterator: ITERATOR[K_]
  57. do
  58. Result := map.new_iterator_on_keys
  59. end
  60. feature {}
  61. map: MAP[V_, K_]
  62. end -- class DICTIONARY_KEY_TRAVERSER
  63. --
  64. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  65. --
  66. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  67. -- of this software and associated documentation files (the "Software"), to deal
  68. -- in the Software without restriction, including without limitation the rights
  69. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  70. -- copies of the Software, and to permit persons to whom the Software is
  71. -- furnished to do so, subject to the following conditions:
  72. --
  73. -- The above copyright notice and this permission notice shall be included in
  74. -- all copies or substantial portions of the Software.
  75. --
  76. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  77. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  78. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  79. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  80. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  81. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  82. -- THE SOFTWARE.