Package org.epics.util.array
Class UnsafeUnwrapper
- java.lang.Object
-
- org.epics.util.array.UnsafeUnwrapper
-
public class UnsafeUnwrapper extends Object
A set of utilities that allows, when really needed, to get the primitive array wrapped by theArrayXxx
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 theCollectionNumber
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()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.
-
-
-
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
-
-