Interface IMultiDimensionalReadOnlyList<TItem>

  • Type Parameters:
    TItem - Type of the items in the list.
    All Superinterfaces:
    Serializable

    public interface IMultiDimensionalReadOnlyList<TItem>
    extends Serializable
    Represents a nested list where items can be associated with multi indices, similar to a multidimensional array.
    Since:
    8.0.0
    Author:
    XIMA MEDIA GmbH
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      List<TItem> getAllFlat​(int[] index)
      Finds all values starting at the given index, similarly to getAll(), but flattened into a single list.
      <TTarget> Object getAllNested​(int[] index, Function<TItem,​TTarget> mapper)
      Finds all values, starting at the index.
      int getChildCount​(int[] index)
      list.setValue(new int[] {0, 0}, "x") list.setValue(new int[] {0, 1}, "y") list.getSize(new int[] {}); // => 1 list.getSize(new int[] {0}); // => 2 list.getSize(new int[] {0, 0}); // => 0 list.getSize(new int[] {0, 1}); // => 0
      TItem getLast()  
      int getMaxIndexLength()
      list.setValue(new int[] {0}, "w") list.setValue(new int[] {0, 0}, "x") list.setValue(new int[] {0, 1}, "y") list.setValue(new int[] {5, 2, 9, 4}, "z") list.getMaxIndexLength(); // => 4
      int getMinIndexLength()
      list.setValue(new int[] {0}, "w") list.setValue(new int[] {0, 0}, "x") list.setValue(new int[] {0, 1}, "y") list.setValue(new int[] {5, 2, 9, 4}, "z") list.getMinIndexLength(); // => 1
      TItem getValue​(int[] index)
      list.setValue(new int[] {0}, "x") list.setValue(new int[] {0, 0}, "y") list.setValue(new int[] {0, 2}, "z") list.setValue(new int[] {2}, "a") list.getValue(new int[] {}); // => null list.getValue(new int[] {0}); // => "x" list.getValue(new int[] {0, 0}); // => "y" list.getValue(new int[] {0, 1}); // => null list.getValue(new int[] {0, 2}); // => "z" list.getValue(new int[] {1}); // => null list.getValue(new int[] {2}); // => "a" list.getValue(new int[] {0, 0, 0}); // => null list.getValue(new int[] {0, 0, 9}); // => null
      boolean hasValue​(int[] index)
      list.setValue(new int[] {0}, "x") list.setValue(new int[] {0, 0}, "y") list.setValue(new int[] {0, 2}, "z") list.setValue(new int[] {2}, null) list.setValue(new int[] {3}, "a") list.hasValue(new int[] {}); // => false list.hasValue(new int[] {0}); // => true list.hasValue(new int[] {0, 0}); // => true list.hasValue(new int[] {0, 1}); // => false list.hasValue(new int[] {0, 2}); // => true list.hasValue(new int[] {1}); // => false list.hasValue(new int[] {2}); // => true list.hasValue(new int[] {3}); // => true list.hasValue(new int[] {0,0,0}); // => false
      IMultiDimensionalReadOnlyList<TItem> immutableCopy()  
      int size()
      list.setValue(new int[] {0}, "w") list.setValue(new int[] {0, 0}, "x") list.setValue(new int[] {0, 1}, "y") list.setValue(new int[] {5, 2, 9, 4}, "z") list.getSize(}); // => 4
    • Method Detail

      • getAllFlat

        @Nonnull
        List<TItem> getAllFlat​(@Nonnull
                               int[] index)
        Finds all values starting at the given index, similarly to getAll(), but flattened into a single list.

        When the index has more elements than the longest index for which a value exists, the given index is capped to the length of that longest index.

         list.setValue(new int[] {0, 0}, "x1")
         list.setValue(new int[] {0, 1}, "y1")
         list.setValue(new int[] {1, 0}, "x2")
         list.setValue(new int[] {1, 1}, "y2")
        
         list.getAllFlat(new int[] {0, 0}); // => List("x1")
         list.getAllFlat(new int[] {0, 1}); // => List("y1")
         list.getAllFlat(new int[] {0}); // => List("x1", "y1")
         list.getAllFlat(new int[] {1}); // => List("x2", "y2")
         list.getAllFlat(new int[] {}); // => List("x1", "y1", "x2", "y2")
        
         list.getAllFlat(new int[] {0, 0, 0}); // => List("x1")
         list.getAllFlat(new int[] {0, 0, 2}); // => List("x1")
         list.getAllFlat(new int[] {0, 0, 99}); // => List("x1")
        
         list.setValue(new int[] {0, 0, 2}, "002")
         list.getAllFlat(new int[] {0, 0, 0}); // => List()
         list.getAllFlat(new int[] {0, 0, 2}); // => List("002")
         list.getAllFlat(new int[] {0, 0, 99}); // => List()
         
        Parameters:
        index - Multidimensional index at which to get the values.
        Returns:
        A list with all mapped values as a non-nested list, starting at the given index.
      • getAllNested

        @Nullable
        <TTarget> Object getAllNested​(@Nonnull
                                      int[] index,
                                      @Nonnull
                                      Function<TItem,​TTarget> mapper)
        Finds all values, starting at the index. When there are no child values at the given index, the value itself is returned. Otherwise, a nested list with all child values, grand child values etc. is returned.

        When the index has more elements than the longest index for which a value exists, the given index is capped to the length of that longest index.

         list.setValue(new int[] {0, 0}, "#x1")
         list.setValue(new int[] {0, 1}, "#y1")
         list.setValue(new int[] {1, 0}, "#x2")
         list.setValue(new int[] {1, 1}, "#y2")
        
         list.getAllNested(new int[] {0, 0}, x -> x.substring(1)); // => "x1"
         list.getAllNested(new int[] {0, 1}, x -> x.substring(1)); // => "y1"
         list.getAllNested(new int[] {0}, x -> x.substring(1)); // => List("x1", "y1")
         list.getAllNested(new int[] {1}, x -> x.substring(1)); // => List("x2", "y2")
         list.getAllNested(new int[] {}, x -> x.substring(1)); // => List(List("x1", "y1"), List("x2", "y2"))
        
         list.getAllNested(new int[] {0, 0, 0}, x -> x.substring(1)); // => "x1"
         list.getAllNested(new int[] {0, 0, 2}, x -> x.substring(1)); // => "x1"
         list.getAllNested(new int[] {0, 0, 99}, x -> x.substring(1)); // => "x1"
        
         list.setValue(new int[] {0, 0, 2}, "#002")
         list.getAllNested(new int[] {0, 0, 0}, x -> x.substring(1)); // => null
         list.getAllNested(new int[] {0, 0, 2}, x -> x.substring(1)); // => "002"
         list.getAllNested(new int[] {0, 0, 99}, x -> x.substring(1)); // => null
         
        Type Parameters:
        TTarget - Type of the mapped items.
        Parameters:
        index - Index to access.
        mapper - Maps each item to the target value.
        Returns:
        Either the mapped getValue(index) at the given index when it is a leaf node (does not have children, i.e. getSize(index) == 0), or a list of all mapped values at the given index otherwise. The list may be nested.
      • getChildCount

        int getChildCount​(@Nonnull
                          int[] index)
         list.setValue(new int[] {0, 0}, "x")
         list.setValue(new int[] {0, 1}, "y")
        
         list.getSize(new int[] {}); // => 1
         list.getSize(new int[] {0}); // => 2
         list.getSize(new int[] {0, 0}); // => 0
         list.getSize(new int[] {0, 1}); // => 0
         
        Parameters:
        index - Multidimensional index at which check the size.
        Returns:
        The number of children at the given index, or 0 when the index is at a leaf position.
      • getLast

        @Nullable
        TItem getLast()
        Returns:
        The last item in the multidimensional list.
      • getMaxIndexLength

        int getMaxIndexLength()
         list.setValue(new int[] {0}, "w")
         list.setValue(new int[] {0, 0}, "x")
         list.setValue(new int[] {0, 1}, "y")
         list.setValue(new int[] {5, 2, 9, 4}, "z")
        
         list.getMaxIndexLength(); // => 4
         
        Returns:
        The length of the longest multi index for which a value exists. 0 if this list is empty.
      • getMinIndexLength

        int getMinIndexLength()
         list.setValue(new int[] {0}, "w")
         list.setValue(new int[] {0, 0}, "x")
         list.setValue(new int[] {0, 1}, "y")
         list.setValue(new int[] {5, 2, 9, 4}, "z")
        
         list.getMinIndexLength(); // => 1
         
        Returns:
        The length of the smaller multi index for which a value exists. 0 if this list is empty.
      • getValue

        @Nullable
        TItem getValue​(@Nonnull
                       int[] index)
         list.setValue(new int[] {0}, "x")
         list.setValue(new int[] {0, 0}, "y")
         list.setValue(new int[] {0, 2}, "z")
         list.setValue(new int[] {2}, "a")
        
         list.getValue(new int[] {}); // => null
         list.getValue(new int[] {0}); // => "x"
         list.getValue(new int[] {0, 0}); // => "y"
         list.getValue(new int[] {0, 1}); // => null
         list.getValue(new int[] {0, 2}); // => "z"
         list.getValue(new int[] {1}); // => null
         list.getValue(new int[] {2}); // => "a"
        
         list.getValue(new int[] {0, 0, 0}); // => null
         list.getValue(new int[] {0, 0, 9}); // => null
         
        Parameters:
        index - Multidimensional index at which to get the value.
        Returns:
        Gets the value that was set for the given nested index, or null if no value was set yet.
      • hasValue

        boolean hasValue​(@Nonnull
                         int[] index)
         list.setValue(new int[] {0}, "x")
         list.setValue(new int[] {0, 0}, "y")
         list.setValue(new int[] {0, 2}, "z")
         list.setValue(new int[] {2}, null)
         list.setValue(new int[] {3}, "a")
        
         list.hasValue(new int[] {}); // => false
         list.hasValue(new int[] {0}); // => true
         list.hasValue(new int[] {0, 0}); // => true
         list.hasValue(new int[] {0, 1}); // => false
         list.hasValue(new int[] {0, 2}); // => true
         list.hasValue(new int[] {1}); // => false
         list.hasValue(new int[] {2}); // => true
         list.hasValue(new int[] {3}); // => true
        
         list.hasValue(new int[] {0,0,0}); // => false
         
        Parameters:
        index - Multidimensional index at which to check.
        Returns:
        true when a value exists for the given index.
      • size

        int size()
         list.setValue(new int[] {0}, "w")
         list.setValue(new int[] {0, 0}, "x")
         list.setValue(new int[] {0, 1}, "y")
         list.setValue(new int[] {5, 2, 9, 4}, "z")
        
         list.getSize(}); // => 4
         
        Returns:
        The total number of values at any index.