Class DefaultConsistentTreeMap<V>

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addListener​(MapEventListener<java.lang.String,​V> listener, java.util.concurrent.Executor executor)
      Registers the specified listener to be notified whenever the map is updated.
      java.util.Map<java.lang.String,​V> asJavaMap()
      Returns a java.util.Map instance backed by this ConsistentMap.
      java.util.Map.Entry<java.lang.String,​Versioned<V>> ceilingEntry​(java.lang.String key)
      Returns the entry associated with the least key greater than or equal to the key.
      java.lang.String ceilingKey​(java.lang.String key)
      Returns the lowest key greater than or equal to key.
      void clear()
      Removes all of the mappings from this map (optional operation).
      Versioned<V> compute​(java.lang.String key, java.util.function.BiFunction<? super java.lang.String,​? super V,​? extends V> remappingFunction)
      Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).
      Versioned<V> computeIf​(java.lang.String key, java.util.function.Predicate<? super V> condition, java.util.function.BiFunction<? super java.lang.String,​? super V,​? extends V> remappingFunction)
      If the value for the specified key satisfies a condition, attempts to compute a new mapping given the key and its current mapped value.
      Versioned<V> computeIfAbsent​(java.lang.String key, java.util.function.Function<? super java.lang.String,​? extends V> mappingFunction)
      If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null.
      Versioned<V> computeIfPresent​(java.lang.String key, java.util.function.BiFunction<? super java.lang.String,​? super V,​? extends V> remappingFunction)
      If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value.
      boolean containsKey​(java.lang.String key)
      Returns true if this map contains a mapping for the specified key.
      boolean containsValue​(V value)
      Returns true if this map contains the specified value.
      java.util.Set<java.util.Map.Entry<java.lang.String,​Versioned<V>>> entrySet()
      Returns the set of entries contained in this map.
      java.util.Map.Entry<java.lang.String,​Versioned<V>> firstEntry()
      Returns the entry associated with the lowest key in the map.
      java.lang.String firstKey()
      Returns the lowest key in the map.
      java.util.Map.Entry<java.lang.String,​Versioned<V>> floorEntry​(java.lang.String key)
      Returns the entry associated with the greatest key less than or equal to key.
      java.lang.String floorKey​(java.lang.String key)
      Returns the entry associated with the highest key less than or equal to key.
      Versioned<V> get​(java.lang.String key)
      Returns the value (and version) to which the specified key is mapped, or null if this map contains no mapping for the key.
      Versioned<V> getOrDefault​(java.lang.String key, V defaultValue)
      Returns the value (and version) to which the specified key is mapped, or the provided default value if this map contains no mapping for the key.
      java.util.Map.Entry<java.lang.String,​Versioned<V>> higherEntry​(java.lang.String key)
      Returns the entry associated with the lest key greater than key.
      java.lang.String higherKey​(java.lang.String key)
      Returns the lowest key greater than key.
      boolean isEmpty()
      Returns true if the map is empty.
      java.util.Iterator<java.util.Map.Entry<java.lang.String,​Versioned<V>>> iterator()  
      java.util.Set<java.lang.String> keySet()
      Returns a Set view of the keys contained in this map.
      java.util.Map.Entry<java.lang.String,​Versioned<V>> lastEntry()
      Returns the entry associated with the highest key in the map.
      java.lang.String lastKey()
      Returns the highest key in the map.
      java.util.Map.Entry<java.lang.String,​Versioned<V>> lowerEntry​(java.lang.String key)
      Returns the entry associated with the largest key less than key.
      java.lang.String lowerKey​(java.lang.String key)
      Returns the entry associated with the greatest key less than key.
      java.util.NavigableSet<java.lang.String> navigableKeySet()
      Returns a navigable set of the keys in this map.
      java.util.Map.Entry<java.lang.String,​Versioned<V>> pollFirstEntry()
      Returns and removes the entry associated with the lowest key.
      java.util.Map.Entry<java.lang.String,​Versioned<V>> pollLastEntry()
      Returns and removes the entry associated with the highest key.
      Versioned<V> put​(java.lang.String key, V value)
      Associates the specified value with the specified key in this map (optional operation).
      Versioned<V> putAndGet​(java.lang.String key, V value)
      Associates the specified value with the specified key in this map (optional operation).
      Versioned<V> putIfAbsent​(java.lang.String key, V value)
      If the specified key is not already associated with a value associates it with the given value and returns null, else returns the current value.
      Versioned<V> remove​(java.lang.String key)
      Removes the mapping for a key from this map if it is present (optional operation).
      boolean remove​(java.lang.String key, long version)
      Removes the entry for the specified key only if its current version in the map is equal to the specified version.
      boolean remove​(java.lang.String key, V value)
      Removes the entry for the specified key only if it is currently mapped to the specified value.
      void removeListener​(MapEventListener<java.lang.String,​V> listener)
      Unregisters the specified listener such that it will no longer receive map change notifications.
      boolean replace​(java.lang.String key, long oldVersion, V newValue)
      Replaces the entry for the specified key only if it is currently mapped to the specified version.
      Versioned<V> replace​(java.lang.String key, V value)
      Replaces the entry for the specified key only if there is any value which associated with specified key.
      boolean replace​(java.lang.String key, V oldValue, V newValue)
      Replaces the entry for the specified key only if currently mapped to the specified value.
      int size()
      Returns the number of entries in the map.
      java.util.NavigableMap<java.lang.String,​V> subMap​(java.lang.String upperKey, java.lang.String lowerKey, boolean inclusiveUpper, boolean inclusiveLower)
      Returns a navigable map containing the entries from the original map which are larger than (or if specified equal to) lowerKey AND less than (or if specified equal to) upperKey.
      java.util.Collection<Versioned<V>> values()
      Returns the collection of values (and associated versions) contained in this map.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • DefaultConsistentTreeMap

        public DefaultConsistentTreeMap​(AsyncConsistentTreeMap<V> treeMap,
                                        long operationTimeoutMillis)
    • Method Detail

      • firstKey

        public java.lang.String firstKey()
        Description copied from interface: ConsistentTreeMap
        Returns the lowest key in the map.
        Specified by:
        firstKey in interface ConsistentTreeMap<V>
        Returns:
        the key or null if none exist
      • lastKey

        public java.lang.String lastKey()
        Description copied from interface: ConsistentTreeMap
        Returns the highest key in the map.
        Specified by:
        lastKey in interface ConsistentTreeMap<V>
        Returns:
        the key or null if none exist
      • ceilingEntry

        public java.util.Map.Entry<java.lang.String,​Versioned<V>> ceilingEntry​(java.lang.String key)
        Description copied from interface: ConsistentTreeMap
        Returns the entry associated with the least key greater than or equal to the key.
        Specified by:
        ceilingEntry in interface ConsistentTreeMap<V>
        Parameters:
        key - the key
        Returns:
        the entry or null
      • floorEntry

        public java.util.Map.Entry<java.lang.String,​Versioned<V>> floorEntry​(java.lang.String key)
        Description copied from interface: ConsistentTreeMap
        Returns the entry associated with the greatest key less than or equal to key.
        Specified by:
        floorEntry in interface ConsistentTreeMap<V>
        Parameters:
        key - the key
        Returns:
        the entry or null
      • higherEntry

        public java.util.Map.Entry<java.lang.String,​Versioned<V>> higherEntry​(java.lang.String key)
        Description copied from interface: ConsistentTreeMap
        Returns the entry associated with the lest key greater than key.
        Specified by:
        higherEntry in interface ConsistentTreeMap<V>
        Parameters:
        key - the key
        Returns:
        the entry or null
      • lowerEntry

        public java.util.Map.Entry<java.lang.String,​Versioned<V>> lowerEntry​(java.lang.String key)
        Description copied from interface: ConsistentTreeMap
        Returns the entry associated with the largest key less than key.
        Specified by:
        lowerEntry in interface ConsistentTreeMap<V>
        Parameters:
        key - the key
        Returns:
        the entry or null
      • firstEntry

        public java.util.Map.Entry<java.lang.String,​Versioned<V>> firstEntry()
        Description copied from interface: ConsistentTreeMap
        Returns the entry associated with the lowest key in the map.
        Specified by:
        firstEntry in interface ConsistentTreeMap<V>
        Returns:
        the entry or null
      • lastEntry

        public java.util.Map.Entry<java.lang.String,​Versioned<V>> lastEntry()
        Description copied from interface: ConsistentTreeMap
        Returns the entry associated with the highest key in the map.
        Specified by:
        lastEntry in interface ConsistentTreeMap<V>
        Returns:
        the entry or null
      • pollFirstEntry

        public java.util.Map.Entry<java.lang.String,​Versioned<V>> pollFirstEntry()
        Description copied from interface: ConsistentTreeMap
        Returns and removes the entry associated with the lowest key.
        Specified by:
        pollFirstEntry in interface ConsistentTreeMap<V>
        Returns:
        the entry or null
      • pollLastEntry

        public java.util.Map.Entry<java.lang.String,​Versioned<V>> pollLastEntry()
        Description copied from interface: ConsistentTreeMap
        Returns and removes the entry associated with the highest key.
        Specified by:
        pollLastEntry in interface ConsistentTreeMap<V>
        Returns:
        the entry or null
      • lowerKey

        public java.lang.String lowerKey​(java.lang.String key)
        Description copied from interface: ConsistentTreeMap
        Returns the entry associated with the greatest key less than key.
        Specified by:
        lowerKey in interface ConsistentTreeMap<V>
        Parameters:
        key - the key
        Returns:
        the entry or null
      • floorKey

        public java.lang.String floorKey​(java.lang.String key)
        Description copied from interface: ConsistentTreeMap
        Returns the entry associated with the highest key less than or equal to key.
        Specified by:
        floorKey in interface ConsistentTreeMap<V>
        Parameters:
        key - the key
        Returns:
        the entry or null
      • ceilingKey

        public java.lang.String ceilingKey​(java.lang.String key)
        Description copied from interface: ConsistentTreeMap
        Returns the lowest key greater than or equal to key.
        Specified by:
        ceilingKey in interface ConsistentTreeMap<V>
        Parameters:
        key - the key
        Returns:
        the key or null
      • higherKey

        public java.lang.String higherKey​(java.lang.String key)
        Description copied from interface: ConsistentTreeMap
        Returns the lowest key greater than key.
        Specified by:
        higherKey in interface ConsistentTreeMap<V>
        Parameters:
        key - the key
        Returns:
        the key or null
      • navigableKeySet

        public java.util.NavigableSet<java.lang.String> navigableKeySet()
        Description copied from interface: ConsistentTreeMap
        Returns a navigable set of the keys in this map.
        Specified by:
        navigableKeySet in interface ConsistentTreeMap<V>
        Returns:
        a navigable key set
      • size

        public int size()
        Description copied from interface: ConsistentMap
        Returns the number of entries in the map.
        Specified by:
        size in interface ConsistentMap<java.lang.String,​V>
        Returns:
        map size.
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: ConsistentMap
        Returns true if the map is empty.
        Specified by:
        isEmpty in interface ConsistentMap<java.lang.String,​V>
        Returns:
        true if map has no entries, false otherwise
      • containsKey

        public boolean containsKey​(java.lang.String key)
        Description copied from interface: ConsistentMap
        Returns true if this map contains a mapping for the specified key.
        Specified by:
        containsKey in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        key - key
        Returns:
        true if map contains key, false otherwise
      • containsValue

        public boolean containsValue​(V value)
        Description copied from interface: ConsistentMap
        Returns true if this map contains the specified value.
        Specified by:
        containsValue in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        value - value
        Returns:
        true if map contains value, false otherwise.
      • get

        public Versioned<V> get​(java.lang.String key)
        Description copied from interface: ConsistentMap
        Returns the value (and version) to which the specified key is mapped, or null if this map contains no mapping for the key.
        Specified by:
        get in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        key - the key whose associated value (and version) is to be returned
        Returns:
        the value (and version) to which the specified key is mapped, or null if this map contains no mapping for the key
      • getOrDefault

        public Versioned<V> getOrDefault​(java.lang.String key,
                                         V defaultValue)
        Description copied from interface: ConsistentMap
        Returns the value (and version) to which the specified key is mapped, or the provided default value if this map contains no mapping for the key.

        Note: a non-null Versioned value will be returned even if the defaultValue is null.

        Specified by:
        getOrDefault in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        key - the key whose associated value (and version) is to be returned
        defaultValue - the default value to return if the key is not set
        Returns:
        the value (and version) to which the specified key is mapped, or null if this map contains no mapping for the key
      • computeIfAbsent

        public Versioned<V> computeIfAbsent​(java.lang.String key,
                                            java.util.function.Function<? super java.lang.String,​? extends V> mappingFunction)
        Description copied from interface: ConsistentMap
        If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null.
        Specified by:
        computeIfAbsent in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        key - key with which the specified value is to be associated
        mappingFunction - the function to compute a value
        Returns:
        the current (existing or computed) value associated with the specified key, or null if the computed value is null. Method throws ConsistentMapException.ConcurrentModification if a concurrent modification of map is detected
      • compute

        public Versioned<V> compute​(java.lang.String key,
                                    java.util.function.BiFunction<? super java.lang.String,​? super V,​? extends V> remappingFunction)
        Description copied from interface: ConsistentMap
        Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping). If the computed value is null, the current mapping will be removed from the map.
        Specified by:
        compute in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        key - key with which the specified value is to be associated
        remappingFunction - the function to compute a value
        Returns:
        the new value associated with the specified key, or null if none. This method throws ConsistentMapException.ConcurrentModification if a concurrent modification of map is detected
      • computeIfPresent

        public Versioned<V> computeIfPresent​(java.lang.String key,
                                             java.util.function.BiFunction<? super java.lang.String,​? super V,​? extends V> remappingFunction)
        Description copied from interface: ConsistentMap
        If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value. If the computed value is null, the current mapping will be removed from the map.
        Specified by:
        computeIfPresent in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        key - key with which the specified value is to be associated
        remappingFunction - the function to compute a value
        Returns:
        the new value associated with the specified key, or null if none. This method throws ConsistentMapException.ConcurrentModification if a concurrent modification of map is detected
      • computeIf

        public Versioned<V> computeIf​(java.lang.String key,
                                      java.util.function.Predicate<? super V> condition,
                                      java.util.function.BiFunction<? super java.lang.String,​? super V,​? extends V> remappingFunction)
        Description copied from interface: ConsistentMap
        If the value for the specified key satisfies a condition, attempts to compute a new mapping given the key and its current mapped value. If the computed value is null, the current mapping will be removed from the map.
        Specified by:
        computeIf in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        key - key with which the specified value is to be associated
        condition - condition that should evaluate to true for the computation to proceed
        remappingFunction - the function to compute a value
        Returns:
        the new value associated with the specified key, or the old value if condition evaluates to false. This method throws ConsistentMapException.ConcurrentModification if a concurrent modification of map is detected
      • put

        public Versioned<V> put​(java.lang.String key,
                                V value)
        Description copied from interface: ConsistentMap
        Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value.
        Specified by:
        put in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        key - key with which the specified value is to be associated
        value - value to be associated with the specified key
        Returns:
        the previous value (and version) associated with key, or null if there was no mapping for key.
      • putAndGet

        public Versioned<V> putAndGet​(java.lang.String key,
                                      V value)
        Description copied from interface: ConsistentMap
        Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value.
        Specified by:
        putAndGet in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        key - key with which the specified value is to be associated
        value - value to be associated with the specified key
        Returns:
        new value.
      • remove

        public Versioned<V> remove​(java.lang.String key)
        Description copied from interface: ConsistentMap
        Removes the mapping for a key from this map if it is present (optional operation).
        Specified by:
        remove in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        key - key whose value is to be removed from the map
        Returns:
        the value (and version) to which this map previously associated the key, or null if the map contained no mapping for the key.
      • clear

        public void clear()
        Description copied from interface: ConsistentMap
        Removes all of the mappings from this map (optional operation). The map will be empty after this call returns.
        Specified by:
        clear in interface ConsistentMap<java.lang.String,​V>
      • keySet

        public java.util.Set<java.lang.String> keySet()
        Description copied from interface: ConsistentMap
        Returns a Set view of the keys contained in this map. This method differs from the behavior of java.util.Map.keySet() in that what is returned is a unmodifiable snapshot view of the keys in the ConsistentMap. Attempts to modify the returned set, whether direct or via its iterator, result in an UnsupportedOperationException.
        Specified by:
        keySet in interface ConsistentMap<java.lang.String,​V>
        Returns:
        a set of the keys contained in this map
      • values

        public java.util.Collection<Versioned<V>> values()
        Description copied from interface: ConsistentMap
        Returns the collection of values (and associated versions) contained in this map. This method differs from the behavior of java.util.Map.values() in that what is returned is a unmodifiable snapshot view of the values in the ConsistentMap. Attempts to modify the returned collection, whether direct or via its iterator, result in an UnsupportedOperationException.
        Specified by:
        values in interface ConsistentMap<java.lang.String,​V>
        Returns:
        a collection of the values (and associated versions) contained in this map
      • entrySet

        public java.util.Set<java.util.Map.Entry<java.lang.String,​Versioned<V>>> entrySet()
        Description copied from interface: ConsistentMap
        Returns the set of entries contained in this map. This method differs from the behavior of java.util.Map.entrySet() in that what is returned is a unmodifiable snapshot view of the entries in the ConsistentMap. Attempts to modify the returned set, whether direct or via its iterator, result in an UnsupportedOperationException.
        Specified by:
        entrySet in interface ConsistentMap<java.lang.String,​V>
        Returns:
        set of entries contained in this map.
      • putIfAbsent

        public Versioned<V> putIfAbsent​(java.lang.String key,
                                        V value)
        Description copied from interface: ConsistentMap
        If the specified key is not already associated with a value associates it with the given value and returns null, else returns the current value.
        Specified by:
        putIfAbsent in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        key - key with which the specified value is to be associated
        value - value to be associated with the specified key
        Returns:
        the previous value associated with the specified key or null if key does not already mapped to a value.
      • remove

        public boolean remove​(java.lang.String key,
                              V value)
        Description copied from interface: ConsistentMap
        Removes the entry for the specified key only if it is currently mapped to the specified value.
        Specified by:
        remove in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        key - key with which the specified value is associated
        value - value expected to be associated with the specified key
        Returns:
        true if the value was removed
      • remove

        public boolean remove​(java.lang.String key,
                              long version)
        Description copied from interface: ConsistentMap
        Removes the entry for the specified key only if its current version in the map is equal to the specified version.
        Specified by:
        remove in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        key - key with which the specified version is associated
        version - version expected to be associated with the specified key
        Returns:
        true if the value was removed
      • replace

        public Versioned<V> replace​(java.lang.String key,
                                    V value)
        Description copied from interface: ConsistentMap
        Replaces the entry for the specified key only if there is any value which associated with specified key.
        Specified by:
        replace in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        key - key with which the specified value is associated
        value - value expected to be associated with the specified key
        Returns:
        the previous value associated with the specified key or null
      • replace

        public boolean replace​(java.lang.String key,
                               V oldValue,
                               V newValue)
        Description copied from interface: ConsistentMap
        Replaces the entry for the specified key only if currently mapped to the specified value.
        Specified by:
        replace in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        key - key with which the specified value is associated
        oldValue - value expected to be associated with the specified key
        newValue - value to be associated with the specified key
        Returns:
        true if the value was replaced
      • replace

        public boolean replace​(java.lang.String key,
                               long oldVersion,
                               V newValue)
        Description copied from interface: ConsistentMap
        Replaces the entry for the specified key only if it is currently mapped to the specified version.
        Specified by:
        replace in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        key - key key with which the specified value is associated
        oldVersion - version expected to be associated with the specified key
        newValue - value to be associated with the specified key
        Returns:
        true if the value was replaced
      • iterator

        public java.util.Iterator<java.util.Map.Entry<java.lang.String,​Versioned<V>>> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<V>
      • addListener

        public void addListener​(MapEventListener<java.lang.String,​V> listener,
                                java.util.concurrent.Executor executor)
        Description copied from interface: ConsistentMap
        Registers the specified listener to be notified whenever the map is updated.
        Specified by:
        addListener in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        listener - listener to notify about map events
        executor - executor to use for handling incoming map events
      • removeListener

        public void removeListener​(MapEventListener<java.lang.String,​V> listener)
        Description copied from interface: ConsistentMap
        Unregisters the specified listener such that it will no longer receive map change notifications.
        Specified by:
        removeListener in interface ConsistentMap<java.lang.String,​V>
        Parameters:
        listener - listener to unregister
      • asJavaMap

        public java.util.Map<java.lang.String,​V> asJavaMap()
        Description copied from interface: ConsistentMap
        Returns a java.util.Map instance backed by this ConsistentMap.
        Specified by:
        asJavaMap in interface ConsistentMap<java.lang.String,​V>
        Returns:
        java.util.Map
      • subMap

        public java.util.NavigableMap<java.lang.String,​V> subMap​(java.lang.String upperKey,
                                                                       java.lang.String lowerKey,
                                                                       boolean inclusiveUpper,
                                                                       boolean inclusiveLower)
        Description copied from interface: ConsistentTreeMap
        Returns a navigable map containing the entries from the original map which are larger than (or if specified equal to) lowerKey AND less than (or if specified equal to) upperKey.
        Specified by:
        subMap in interface ConsistentTreeMap<V>
        Parameters:
        upperKey - the upper bound for the keys in this map
        lowerKey - the lower bound for the keys in this map
        inclusiveUpper - whether keys equal to the upperKey should be included
        inclusiveLower - whether keys equal to the lowerKey should be included
        Returns:
        a navigable map containing entries in the specified range (this may be empty)