Class CypherMapWrapper


  • public final class CypherMapWrapper
    extends java.lang.Object
    Wrapper around configuration options map
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      boolean containsKey​(java.lang.String key)
      Checks if the given key exists in the configuration.
      static CypherMapWrapper create​(java.util.Map<java.lang.String,​java.lang.Object> config)  
      static CypherMapWrapper empty()  
      static @NotNull java.lang.String failOnBlank​(java.lang.String key, @Nullable java.lang.String value)  
      static <T> T failOnNull​(java.lang.String key, T value)  
      <V> V get​(java.lang.String newKey, java.lang.String oldKey, V defaultValue)
      Deprecated.
      <V> V get​(java.lang.String key, V defaultValue)
      Deprecated.
      boolean getBool​(java.lang.String key, boolean defaultValue)  
      <V> V getChecked​(java.lang.String key, V defaultValue, java.lang.Class<V> expectedType)
      Get and convert the value under the given key to the given type.
      double getDouble​(java.lang.String key, double defaultValue)  
      int getInt​(java.lang.String key, int defaultValue)  
      java.util.List<java.lang.String> getList​(java.lang.String key)  
      long getLong​(java.lang.String key, long defaultValue)  
      java.util.Map<java.lang.String,​java.lang.Object> getMap​(java.lang.String key)  
      java.lang.Number getNumber​(java.lang.String key, java.lang.Number defaultValue)  
      java.lang.Number getNumber​(java.lang.String key, java.lang.String oldKey, java.lang.Number defaultValue)  
      <E> java.util.Optional<E> getOptional​(java.lang.String key, java.lang.Class<E> clazz)  
      java.util.Optional<java.lang.String> getString​(java.lang.String key)  
      @Nullable java.lang.String getString​(java.lang.String key, @Nullable java.lang.String defaultValue)  
      @Nullable java.lang.String getString​(java.lang.String key, java.lang.String oldKey, @Nullable java.lang.String defaultValue)  
      boolean isEmpty()  
      boolean requireBool​(java.lang.String key)  
      <V> V requireChecked​(java.lang.String key, java.lang.Class<V> expectedType)  
      double requireDouble​(java.lang.String key)  
      int requireInt​(java.lang.String key)  
      long requireLong​(java.lang.String key)  
      java.lang.Number requireNumber​(java.lang.String key)  
      void requireOnlyKeysFrom​(java.util.Collection<java.lang.String> allowedKeys)  
      java.lang.String requireString​(java.lang.String key)  
      java.util.Map<java.lang.String,​java.lang.Object> toMap()
      Returns a copy of the internal Map.
      static double validateDoubleRange​(java.lang.String key, double value, double min, double max, boolean minInclusive, boolean maxInclusive)  
      static int validateIntegerRange​(java.lang.String key, int value, int min, int max, boolean minInclusive, boolean maxInclusive)  
      static long validateLongRange​(java.lang.String key, long value, long min, long max, boolean minInclusive, boolean maxInclusive)  
      CypherMapWrapper.PairResult verifyMutuallyExclusivePairs​(java.lang.String firstPairKeyOne, java.lang.String firstPairKeyTwo, java.lang.String secondPairKeyOne, java.lang.String secondPairKeyTwo, java.lang.String errorPrefix)
      Verifies that only one of two mutually exclusive pairs of configuration keys is present.
      CypherMapWrapper withBoolean​(java.lang.String key, java.lang.Boolean value)  
      CypherMapWrapper withEntry​(java.lang.String key, java.lang.Object value)  
      CypherMapWrapper withNumber​(java.lang.String key, java.lang.Number value)  
      CypherMapWrapper withoutAny​(java.util.Collection<java.lang.String> keys)  
      CypherMapWrapper withoutEntry​(java.lang.String key)  
      CypherMapWrapper withString​(java.lang.String key, java.lang.String value)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • containsKey

        public boolean containsKey​(java.lang.String key)
        Checks if the given key exists in the configuration.
        Parameters:
        key - key to look for
        Returns:
        true, iff the key exists
      • isEmpty

        public boolean isEmpty()
      • getString

        public java.util.Optional<java.lang.String> getString​(java.lang.String key)
      • requireString

        public java.lang.String requireString​(java.lang.String key)
      • getMap

        public java.util.Map<java.lang.String,​java.lang.Object> getMap​(java.lang.String key)
      • getList

        public java.util.List<java.lang.String> getList​(java.lang.String key)
      • getOptional

        public <E> java.util.Optional<E> getOptional​(java.lang.String key,
                                                     java.lang.Class<E> clazz)
      • getString

        @Contract("_, !null -> !null")
        @Nullable
        public @Nullable java.lang.String getString​(java.lang.String key,
                                                    @Nullable
                                                    @Nullable java.lang.String defaultValue)
      • getString

        @Contract("_, _, !null -> !null")
        @Nullable
        public @Nullable java.lang.String getString​(java.lang.String key,
                                                    java.lang.String oldKey,
                                                    @Nullable
                                                    @Nullable java.lang.String defaultValue)
      • getBool

        public boolean getBool​(java.lang.String key,
                               boolean defaultValue)
      • requireBool

        public boolean requireBool​(java.lang.String key)
      • getNumber

        public java.lang.Number getNumber​(java.lang.String key,
                                          java.lang.Number defaultValue)
      • requireNumber

        public java.lang.Number requireNumber​(java.lang.String key)
      • getNumber

        public java.lang.Number getNumber​(java.lang.String key,
                                          java.lang.String oldKey,
                                          java.lang.Number defaultValue)
      • getLong

        public long getLong​(java.lang.String key,
                            long defaultValue)
      • requireLong

        public long requireLong​(java.lang.String key)
      • getInt

        public int getInt​(java.lang.String key,
                          int defaultValue)
      • requireInt

        public int requireInt​(java.lang.String key)
      • getDouble

        public double getDouble​(java.lang.String key,
                                double defaultValue)
      • toMap

        public java.util.Map<java.lang.String,​java.lang.Object> toMap()
        Returns a copy of the internal Map.
      • requireDouble

        public double requireDouble​(java.lang.String key)
      • getChecked

        @Contract("_, !null, _ -> !null")
        @Nullable
        public <V> V getChecked​(java.lang.String key,
                                @Nullable
                                V defaultValue,
                                java.lang.Class<V> expectedType)
        Get and convert the value under the given key to the given type.
        Returns:
        the found value under the key - if it is of the provided type, or the provided default value if no entry for the key is found (or it's mapped to null).
        Throws:
        java.lang.IllegalArgumentException - if a value was found, but it is not of the expected type.
      • requireChecked

        public <V> V requireChecked​(java.lang.String key,
                                    java.lang.Class<V> expectedType)
      • requireOnlyKeysFrom

        public void requireOnlyKeysFrom​(java.util.Collection<java.lang.String> allowedKeys)
      • get

        @Contract("_, !null -> !null")
        @Deprecated
        @Nullable
        public <V> V get​(java.lang.String key,
                         @Nullable
                         V defaultValue)
        Deprecated.
      • get

        @Contract("_, _, !null -> !null")
        @Deprecated
        @Nullable
        public <V> V get​(java.lang.String newKey,
                         java.lang.String oldKey,
                         @Nullable
                         V defaultValue)
        Deprecated.
      • failOnNull

        public static <T> T failOnNull​(java.lang.String key,
                                       T value)
      • failOnBlank

        @NotNull
        public static @NotNull java.lang.String failOnBlank​(java.lang.String key,
                                                            @Nullable
                                                            @Nullable java.lang.String value)
      • validateIntegerRange

        public static int validateIntegerRange​(java.lang.String key,
                                               int value,
                                               int min,
                                               int max,
                                               boolean minInclusive,
                                               boolean maxInclusive)
      • validateLongRange

        public static long validateLongRange​(java.lang.String key,
                                             long value,
                                             long min,
                                             long max,
                                             boolean minInclusive,
                                             boolean maxInclusive)
      • validateDoubleRange

        public static double validateDoubleRange​(java.lang.String key,
                                                 double value,
                                                 double min,
                                                 double max,
                                                 boolean minInclusive,
                                                 boolean maxInclusive)
      • verifyMutuallyExclusivePairs

        public CypherMapWrapper.PairResult verifyMutuallyExclusivePairs​(java.lang.String firstPairKeyOne,
                                                                        java.lang.String firstPairKeyTwo,
                                                                        java.lang.String secondPairKeyOne,
                                                                        java.lang.String secondPairKeyTwo,
                                                                        java.lang.String errorPrefix)
                                                                 throws java.lang.IllegalArgumentException
        Verifies that only one of two mutually exclusive pairs of configuration keys is present. More precisely, the following condition is checked: (firstPairKeyOne AND firstPairKeyTwo) XOR (secondPairKeyOne AND secondPairKeyTwo) If the condition is verified, the return value will identify which one of the pairs is present. In the error case where the condition is violated, an IllegalArgumentException is thrown. The message of that exception depends on which keys are present, possible mis-spelled, or absent.
        Throws:
        java.lang.IllegalArgumentException
      • create

        public static CypherMapWrapper create​(java.util.Map<java.lang.String,​java.lang.Object> config)
      • withString

        public CypherMapWrapper withString​(java.lang.String key,
                                           java.lang.String value)
      • withNumber

        public CypherMapWrapper withNumber​(java.lang.String key,
                                           java.lang.Number value)
      • withBoolean

        public CypherMapWrapper withBoolean​(java.lang.String key,
                                            java.lang.Boolean value)
      • withEntry

        public CypherMapWrapper withEntry​(java.lang.String key,
                                          java.lang.Object value)
      • withoutAny

        public CypherMapWrapper withoutAny​(java.util.Collection<java.lang.String> keys)