Class UnsafeUnwrapper


  • public class UnsafeUnwrapper
    extends Object
    A set of utilities that allows, when really needed, to get the primitive array wrapped by the ArrayXxx classes.

    These methods should only be used when the data stored in the array classes needs to be passed to other libraries that operate directly on primitive array. In these cases, the only choice is to break encapsulation and expose the internal state. USE WITH CAUTION.

    There are three type of methods. wrappedXxxArray returns the array the CollectionNumber is wrapping or null if no array is being wrapped. readSafeXxxArray returns an array, possibly a copy, that is always safe to read. writeSafeXxxArray returns an array, possibly a copy, that is always safe to write to.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  UnsafeUnwrapper.Array<T>
      A primitive array together with the starting index and the number of elements to be read from the starting index.
    • Constructor Summary

      Constructors 
      Constructor Description
      UnsafeUnwrapper()  
    • Constructor Detail

      • UnsafeUnwrapper

        public UnsafeUnwrapper()
    • Method Detail

      • wrappedArray

        public static UnsafeUnwrapper.Array<?> wrappedArray​(CollectionNumber coll)
        If available, return the array wrapped by the collection - USE WITH CAUTION AS IT EXPOSES THE INTERNAL STATE OF THE COLLECTION. This is provided in case an external routine for computation requires you to use array, and you want to avoid the copy for performance reason.
        Parameters:
        coll - the collection
        Returns:
        the array or null
      • wrappedFloatArray

        public static UnsafeUnwrapper.Array<float[]> wrappedFloatArray​(CollectionNumber coll)
        If available, return the array wrapped by the collection - USE WITH CAUTION AS IT EXPOSES THE INTERNAL STATE OF THE COLLECTION. This is provided in case an external routine for computation requires you to use array, and you want to avoid the copy for performance reason.
        Parameters:
        coll - the collection
        Returns:
        the array or null
      • wrappedDoubleArray

        public static UnsafeUnwrapper.Array<double[]> wrappedDoubleArray​(CollectionNumber coll)
        If available, return the array wrapped by the collection - USE WITH CAUTION AS IT EXPOSES THE INTERNAL STATE OF THE COLLECTION. This is provided in case an external routine for computation requires you to use array, and you want to avoid the copy for performance reason.
        Parameters:
        coll - the collection
        Returns:
        the array or null
      • wrappedByteArray

        public static UnsafeUnwrapper.Array<byte[]> wrappedByteArray​(CollectionNumber coll)
        If available, return the array wrapped by the collection - USE WITH CAUTION AS IT EXPOSES THE INTERNAL STATE OF THE COLLECTION. This is provided in case an external routine for computation requires you to use array, and you want to avoid the copy for performance reason.
        Parameters:
        coll - the collection
        Returns:
        the array or null
      • wrappedShortArray

        public static UnsafeUnwrapper.Array<short[]> wrappedShortArray​(CollectionNumber coll)
        If available, return the array wrapped by the collection - USE WITH CAUTION AS IT EXPOSES THE INTERNAL STATE OF THE COLLECTION. This is provided in case an external routine for computation requires you to use array, and you want to avoid the copy for performance reason.
        Parameters:
        coll - the collection
        Returns:
        the array or null
      • wrappedIntArray

        public static UnsafeUnwrapper.Array<int[]> wrappedIntArray​(CollectionNumber coll)
        If available, return the array wrapped by the collection - USE WITH CAUTION AS IT EXPOSES THE INTERNAL STATE OF THE COLLECTION. This is provided in case an external routine for computation requires you to use array, and you want to avoid the copy for performance reason.
        Parameters:
        coll - the collection
        Returns:
        the array or null
      • wrappedLongArray

        public static UnsafeUnwrapper.Array<long[]> wrappedLongArray​(CollectionNumber coll)
        If available, return the array wrapped by the collection - USE WITH CAUTION AS IT EXPOSES THE INTERNAL STATE OF THE COLLECTION. This is provided in case an external routine for computation requires you to use array, and you want to avoid the copy for performance reason.
        Parameters:
        coll - the collection
        Returns:
        the array or null
      • readSafeDoubleArray

        public static UnsafeUnwrapper.Array<double[]> readSafeDoubleArray​(CollectionNumber coll)
        Returns a double array that contains the elements of the collection meant for read-only - USE WITH CAUTION AS IT MAY EXPOSE THE INTERNAL STATE OF THE COLLECTION Returns either the wrapped array (if exists and matches the type) or a copy. It may return the array protected by an unmodifiable view.
        Parameters:
        coll - the collection
        Returns:
        the array
      • readSafeFloatArray

        public static UnsafeUnwrapper.Array<float[]> readSafeFloatArray​(CollectionNumber coll)
        Returns a float array that contains the elements of the collection meant for read-only - USE WITH CAUTION AS IT MAY EXPOSE THE INTERNAL STATE OF THE COLLECTION Returns either the wrapped array (if exists and matches the type) or a copy. It may return the array protected by an unmodifiable view.
        Parameters:
        coll - the collection
        Returns:
        the array
      • readSafeLongArray

        public static UnsafeUnwrapper.Array<long[]> readSafeLongArray​(CollectionNumber coll)
        Returns a long array that contains the elements of the collection meant for read-only - USE WITH CAUTION AS IT MAY EXPOSE THE INTERNAL STATE OF THE COLLECTION Returns either the wrapped array (if exists and matches the type) or a copy. It may return the array protected by an unmodifiable view.
        Parameters:
        coll - the collection
        Returns:
        the array
      • readSafeIntArray

        public static UnsafeUnwrapper.Array<int[]> readSafeIntArray​(CollectionNumber coll)
        Returns a int array that contains the elements of the collection meant for read-only - USE WITH CAUTION AS IT MAY EXPOSE THE INTERNAL STATE OF THE COLLECTION Returns either the wrapped array (if exists and matches the type) or a copy. It may return the array protected by an unmodifiable view.
        Parameters:
        coll - the collection
        Returns:
        the array
      • readSafeShortArray

        public static UnsafeUnwrapper.Array<short[]> readSafeShortArray​(CollectionNumber coll)
        Returns a short array that contains the elements of the collection meant for read-only - USE WITH CAUTION AS IT MAY EXPOSE THE INTERNAL STATE OF THE COLLECTION Returns either the wrapped array (if exists and matches the type) or a copy. It may return the array protected by an unmodifiable view.
        Parameters:
        coll - the collection
        Returns:
        the array
      • readSafeByteArray

        public static UnsafeUnwrapper.Array<byte[]> readSafeByteArray​(CollectionNumber coll)
        Returns a byte array that contains the elements of the collection meant for read-only - USE WITH CAUTION AS IT MAY EXPOSE THE INTERNAL STATE OF THE COLLECTION Returns either the wrapped array (if exists and matches the type) or a copy. It may return the array protected by an unmodifiable view.
        Parameters:
        coll - the collection
        Returns:
        the array
      • writeSafeDoubleArray

        public static UnsafeUnwrapper.Array<double[]> writeSafeDoubleArray​(CollectionNumber coll)
        Returns a double array that contains the elements of the collection meant - USE WITH CAUTION AS IT MAY EXPOSE THE INTERNAL STATE OF THE COLLECTION Returns either the wrapped array (if exists and matches the type and the collection is modifiable) or a copy.
        Parameters:
        coll - the collection
        Returns:
        the array
      • writeSafeFloatArray

        public static UnsafeUnwrapper.Array<float[]> writeSafeFloatArray​(CollectionNumber coll)
        Returns a float array that contains the elements of the collection meant - USE WITH CAUTION AS IT MAY EXPOSE THE INTERNAL STATE OF THE COLLECTION Returns either the wrapped array (if exists and matches the type and the collection is modifiable) or a copy.
        Parameters:
        coll - the collection
        Returns:
        the array
      • writeSafeLongArray

        public static UnsafeUnwrapper.Array<long[]> writeSafeLongArray​(CollectionNumber coll)
        Returns a long array that contains the elements of the collection meant - USE WITH CAUTION AS IT MAY EXPOSE THE INTERNAL STATE OF THE COLLECTION Returns either the wrapped array (if exists and matches the type and the collection is modifiable) or a copy.
        Parameters:
        coll - the collection
        Returns:
        the array
      • writeSafeIntArray

        public static UnsafeUnwrapper.Array<int[]> writeSafeIntArray​(CollectionNumber coll)
        Returns a int array that contains the elements of the collection meant - USE WITH CAUTION AS IT MAY EXPOSE THE INTERNAL STATE OF THE COLLECTION Returns either the wrapped array (if exists and matches the type and the collection is modifiable) or a copy.
        Parameters:
        coll - the collection
        Returns:
        the array
      • writeSafeShortArray

        public static UnsafeUnwrapper.Array<short[]> writeSafeShortArray​(CollectionNumber coll)
        Returns a short array that contains the elements of the collection meant - USE WITH CAUTION AS IT MAY EXPOSE THE INTERNAL STATE OF THE COLLECTION Returns either the wrapped array (if exists and matches the type and the collection is modifiable) or a copy.
        Parameters:
        coll - the collection
        Returns:
        the array
      • writeSafeByteArray

        public static UnsafeUnwrapper.Array<byte[]> writeSafeByteArray​(CollectionNumber coll)
        Returns a byte array that contains the elements of the collection meant - USE WITH CAUTION AS IT MAY EXPOSE THE INTERNAL STATE OF THE COLLECTION Returns either the wrapped array (if exists and matches the type and the collection is modifiable) or a copy.
        Parameters:
        coll - the collection
        Returns:
        the array