Class ArrayMapper

java.lang.Object
ch.nolix.base.commontype.arraymapper.ArrayMapper
All Implemented Interfaces:
IArrayMapper

public final class ArrayMapper extends Object implements IArrayMapper
Author:
Silvan Wyss
  • Constructor Details

    • ArrayMapper

      public ArrayMapper()
  • Method Details

    • toByteArray

      public <E> byte[] toByteArray(Iterable<E> iterable, int n, Function<E,Byte> byteMapper)
      The time complexity of this method is O(n) if the given iterable contains n elements.
      Specified by:
      toByteArray in interface IArrayMapper
      Type Parameters:
      E - the type of the elements of the given iterable
      Parameters:
      iterable - the mapped iterable, is considered to be empty when is null
      n -
      byteMapper -
      Returns:
      a new array with the first n bytes the given byteMapper maps from the elements of the given iterable, mapping null elements to 0
    • toDoubleArray

      public <E> double[] toDoubleArray(Iterable<E> iterable, int n, ToDoubleFunction<E> doubleMapper)
      The time complexity of this method is O(n) if the given iterable contains n elements.
      Specified by:
      toDoubleArray in interface IArrayMapper
      Type Parameters:
      E - the type of the elements of the given iterable
      Parameters:
      iterable - the mapped iterable, is considered to be empty when is null
      n -
      doubleMapper -
      Returns:
      a new array with the first n doubles the given doubleMapper maps from the elements of the given iterable, mapping null elements to 0.0
    • toIntArray

      public <E> int[] toIntArray(Iterable<E> iterable, int n, ToIntFunction<E> intMapper)
      The time complexity of this method is O(n) if the given iterable contains n elements.
      Specified by:
      toIntArray in interface IArrayMapper
      Type Parameters:
      E - the type of the elements of the given iterable
      Parameters:
      iterable - the mapped iterable, is considered to be empty when is null
      n -
      intMapper -
      Returns:
      a new array with the first n ints the given intMapper maps from the elements of the given iterable, mapping null elements to 0