-
- -

Class UnitDatabase.PrefixedUnitMap

-
-
-
    -
  • java.lang.Object
  • -
  • -
      -
    • org.unitConverter.unit.UnitDatabase.PrefixedUnitMap
    • -
    -
  • -
-
-
    -
  • -
    -
    All Implemented Interfaces:
    -
    java.util.Map<java.lang.String,​Unit>
    -
    -
    -
    Enclosing class:
    -
    UnitDatabase
    -
    -
    -
    private static final class UnitDatabase.PrefixedUnitMap
    -extends java.lang.Object
    -implements java.util.Map<java.lang.String,​Unit>
    -
    A map for units that allows the use of prefixes. -

    - As this map implementation is intended to be used as a sort of "augmented view" of a unit and prefix map, it is - unmodifiable but instead reflects the changes to the maps passed into it. Do not edit this map, instead edit the - maps that were passed in during construction. -

    -

    - The rules for applying prefixes onto units are the following: -

      -
    • Prefixes can only be applied to linear units.
    • -
    • Before attempting to search for prefixes in a unit name, this map will first search for a unit name. So, if - there are two units, "B" and "AB", and a prefix "A", this map will favour the unit "AB" over the unit "B" with - the prefix "A", even though they have the same string.
    • -
    • Longer prefixes are preferred to shorter prefixes. So, if you have units "BC" and "C", and prefixes "AB" and - "A", inputting "ABC" will return the unit "C" with the prefix "AB", not "BC" with the prefix "A".
    • -
    -

    -

    - This map is infinite in size if there is at least one unit and at least one prefix. If it is infinite, some - operations that only work with finite collections, like converting name/entry sets to arrays, will throw an - IllegalStateException. -

    -

    - Because of ambiguities between prefixes (i.e. kilokilo = mega), containsValue(java.lang.Object) and values() - currently ignore prefixes. -

    -
    -
    Since:
    -
    2019-04-13, v0.2.0
    -
    Author:
    -
    Adrien Hopkins
    -
    -
  • -
-
-
-
    -
  • - -
    - -
    - -
    -
      -
    • - - -

      Field Summary

      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Fields 
      Modifier and TypeFieldDescription
      private java.util.Set<java.util.Map.Entry<java.lang.String,​Unit>>entrySet 
      private java.util.Set<java.lang.String>keySet 
      private java.util.Map<java.lang.String,​UnitPrefix>prefixes -
      The available prefixes for use.
      -
      private java.util.Map<java.lang.String,​Unit>units -
      The units stored in this collection, without prefixes.
      -
      private java.util.Collection<Unit>values 
      -
    • -
    -
    - -
    -
      -
    • - - -

      Constructor Summary

      - - - - - - - - - - -
      Constructors 
      ConstructorDescription
      PrefixedUnitMap​(java.util.Map<java.lang.String,​Unit> units, - java.util.Map<java.lang.String,​UnitPrefix> prefixes) -
      Creates the PrefixedUnitMap.
      -
      -
    • -
    -
    - -
    -
      -
    • - - -

      Method Summary

      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      voidclear() 
      Unitcompute​(java.lang.String key, - java.util.function.BiFunction<? super java.lang.String,​? super Unit,​? extends Unit> remappingFunction) 
      UnitcomputeIfAbsent​(java.lang.String key, - java.util.function.Function<? super java.lang.String,​? extends Unit> mappingFunction) 
      UnitcomputeIfPresent​(java.lang.String key, - java.util.function.BiFunction<? super java.lang.String,​? super Unit,​? extends Unit> remappingFunction) 
      booleancontainsKey​(java.lang.Object key) 
      booleancontainsValue​(java.lang.Object value)
      java.util.Set<java.util.Map.Entry<java.lang.String,​Unit>>entrySet() 
      Unitget​(java.lang.Object key) 
      booleanisEmpty() 
      java.util.Set<java.lang.String>keySet() 
      Unitmerge​(java.lang.String key, - Unit value, - java.util.function.BiFunction<? super Unit,​? super Unit,​? extends Unit> remappingFunction) 
      Unitput​(java.lang.String key, - Unit value) 
      voidputAll​(java.util.Map<? extends java.lang.String,​? extends Unit> m) 
      UnitputIfAbsent​(java.lang.String key, - Unit value) 
      Unitremove​(java.lang.Object key) 
      booleanremove​(java.lang.Object key, - java.lang.Object value) 
      Unitreplace​(java.lang.String key, - Unit value) 
      booleanreplace​(java.lang.String key, - Unit oldValue, - Unit newValue) 
      voidreplaceAll​(java.util.function.BiFunction<? super java.lang.String,​? super Unit,​? extends Unit> function) 
      intsize() 
      java.lang.StringtoString() 
      java.util.Collection<Unit>values()
      -
        -
      • - - -

        Methods inherited from class java.lang.Object

        -clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • -
      -
        -
      • - - -

        Methods inherited from interface java.util.Map

        -equals, forEach, getOrDefault, hashCode
      • -
      -
    • -
    -
    -
  • -
-
-
-
    -
  • - -
    -
      -
    • - - -

      Field Detail

      - - - -
        -
      • -

        units

        -
        private final java.util.Map<java.lang.String,​Unit> units
        -
        The units stored in this collection, without prefixes.
        -
        -
        Since:
        -
        2019-04-13, v0.2.0
        -
        -
      • -
      - - - -
        -
      • -

        prefixes

        -
        private final java.util.Map<java.lang.String,​UnitPrefix> prefixes
        -
        The available prefixes for use.
        -
        -
        Since:
        -
        2019-04-13, v0.2.0
        -
        -
      • -
      - - - -
        -
      • -

        values

        -
        private transient java.util.Collection<Unit> values
        -
      • -
      - - - -
        -
      • -

        keySet

        -
        private transient java.util.Set<java.lang.String> keySet
        -
      • -
      - - - -
        -
      • -

        entrySet

        -
        private transient java.util.Set<java.util.Map.Entry<java.lang.String,​Unit>> entrySet
        -
      • -
      -
    • -
    -
    - -
    -
      -
    • - - -

      Constructor Detail

      - - - -
        -
      • -

        PrefixedUnitMap

        -
        public PrefixedUnitMap​(java.util.Map<java.lang.String,​Unit> units,
        -                       java.util.Map<java.lang.String,​UnitPrefix> prefixes)
        -
        Creates the PrefixedUnitMap.
        -
        -
        Parameters:
        -
        units - map mapping unit names to units
        -
        prefixes - map mapping prefix names to prefixes
        -
        Since:
        -
        2019-04-13, v0.2.0
        -
        -
      • -
      -
    • -
    -
    - -
    -
      -
    • - - -

      Method Detail

      - - - -
        -
      • -

        clear

        -
        public void clear()
        -
        -
        Specified by:
        -
        clear in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        compute

        -
        public Unit compute​(java.lang.String key,
        -                    java.util.function.BiFunction<? super java.lang.String,​? super Unit,​? extends Unit> remappingFunction)
        -
        -
        Specified by:
        -
        compute in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        computeIfAbsent

        -
        public Unit computeIfAbsent​(java.lang.String key,
        -                            java.util.function.Function<? super java.lang.String,​? extends Unit> mappingFunction)
        -
        -
        Specified by:
        -
        computeIfAbsent in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        computeIfPresent

        -
        public Unit computeIfPresent​(java.lang.String key,
        -                             java.util.function.BiFunction<? super java.lang.String,​? super Unit,​? extends Unit> remappingFunction)
        -
        -
        Specified by:
        -
        computeIfPresent in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        containsKey

        -
        public boolean containsKey​(java.lang.Object key)
        -
        -
        Specified by:
        -
        containsKey in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        containsValue

        -
        public boolean containsValue​(java.lang.Object value)
        -
        - -

        - Because of ambiguities between prefixes (i.e. kilokilo = mega), this method only tests for prefixless units. -

        -
        -
        Specified by:
        -
        containsValue in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        entrySet

        -
        public java.util.Set<java.util.Map.Entry<java.lang.String,​Unit>> entrySet()
        -
        -
        Specified by:
        -
        entrySet in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        get

        -
        public Unit get​(java.lang.Object key)
        -
        -
        Specified by:
        -
        get in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        isEmpty

        -
        public boolean isEmpty()
        -
        -
        Specified by:
        -
        isEmpty in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        keySet

        -
        public java.util.Set<java.lang.String> keySet()
        -
        -
        Specified by:
        -
        keySet in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        merge

        -
        public Unit merge​(java.lang.String key,
        -                  Unit value,
        -                  java.util.function.BiFunction<? super Unit,​? super Unit,​? extends Unit> remappingFunction)
        -
        -
        Specified by:
        -
        merge in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        put

        -
        public Unit put​(java.lang.String key,
        -                Unit value)
        -
        -
        Specified by:
        -
        put in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        putAll

        -
        public void putAll​(java.util.Map<? extends java.lang.String,​? extends Unit> m)
        -
        -
        Specified by:
        -
        putAll in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        putIfAbsent

        -
        public Unit putIfAbsent​(java.lang.String key,
        -                        Unit value)
        -
        -
        Specified by:
        -
        putIfAbsent in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        remove

        -
        public Unit remove​(java.lang.Object key)
        -
        -
        Specified by:
        -
        remove in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        remove

        -
        public boolean remove​(java.lang.Object key,
        -                      java.lang.Object value)
        -
        -
        Specified by:
        -
        remove in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        replace

        -
        public Unit replace​(java.lang.String key,
        -                    Unit value)
        -
        -
        Specified by:
        -
        replace in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        replace

        -
        public boolean replace​(java.lang.String key,
        -                       Unit oldValue,
        -                       Unit newValue)
        -
        -
        Specified by:
        -
        replace in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        replaceAll

        -
        public void replaceAll​(java.util.function.BiFunction<? super java.lang.String,​? super Unit,​? extends Unit> function)
        -
        -
        Specified by:
        -
        replaceAll in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        size

        -
        public int size()
        -
        -
        Specified by:
        -
        size in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      - - - -
        -
      • -

        toString

        -
        public java.lang.String toString()
        -
        -
        Overrides:
        -
        toString in class java.lang.Object
        -
        -
      • -
      - - - -
        -
      • -

        values

        -
        public java.util.Collection<Unit> values()
        -
        - -

        - Because of ambiguities between prefixes (i.e. kilokilo = mega), this method ignores prefixes. -

        -
        -
        Specified by:
        -
        values in interface java.util.Map<java.lang.String,​Unit>
        -
        -
      • -
      -
    • -
    -
    -
  • -
-
-
-