Interface UnmodSortedMap<K,​V>

    • Method Detail

      • entrySet

        @NotNull
        default @NotNull UnmodSortedSet<Map.Entry<K,​V>> entrySet()
        Returns a view of the mappings contained in this map. The set should actually contain UnmodMap.Entry items, but that return signature is illegal in Java, so you'll just have to remember.
        Specified by:
        entrySet in interface Map<K,​V>
        Specified by:
        entrySet in interface SortedMap<K,​V>
        Specified by:
        entrySet in interface UnmodMap<K,​V>
      • values

        @NotNull
        default @NotNull UnmodSortedCollection<V> values()
        This method is deprecated on UnmodMap because equals() and hashCode() cannot be implemented on the resulting collection, but the guaranteed order of the result in a SortedMap makes this able to return a List. It's still an unnecessary convenience method and you should use this map as an Iterable instead for consistency in dealing with all maps.
        mySortedMap.map((UnEntry<K,V> entry) -> entry.getValue())
                     .toImList();
        This method has been deprecated because it is impossible to implement equals() or hashCode() on the resulting collection, and calling this method is probably at least a missed opportunity, if not an outright error. Use an UnmodMap as an UnmodIterable<UnmodMap.UnEntry> instead. If you don't care about eliminating duplicate values, and want a compatible return type call:
        myMap.map((UnEntry<K,V> entry) -> entry.getValue())
                     .toImSet();
        If you want to keep a count of duplicates, try something like this, but it has a different signature:
        ImMap<V,Integer> valueCounts = myMap.fold(PersistentHashMap.empty(),
                             (ImMap<V,Integer> accum, UnEntry<K,V> origEntry) -> {
                                     V inVal = origEntry.getValue();
                                     return accum.assoc(inVal,
                                                        accum.getOrElse(inVal, 0) + 1);
                                 });
        You really shouldn't turn values() into a List, because a List has order and an unsorted Map is unordered by key, and especially unordered by value. On a SortedMap, List is the proper return type. java.util.HashMap.values() returns an instance of java.util.HashMap.Values which does *not* have equals() or hashCode() defined. This is because List.equals() and Set.equals() return not-equal when compared to a Collection. There is no good way to implement a reflexive equals with both of those because they are just too different. Ultimately, Collection just isn't specific enough to instantiate, but we do it anyway here for backward compatibility. We don't implement equals() or hashCode() either because the result could have duplicates. If the Map isn't sorted, the result could have random ordering.
        Specified by:
        values in interface Map<K,​V>
        Specified by:
        values in interface SortedMap<K,​V>
        Specified by:
        values in interface UnmodMap<K,​V>