Float buffer FloatBuffer in java

Source: Internet
Author: User

Float buffer FloatBuffer in java
I. Overview:

java.lang.Object  java.nio.Buffer      java.nio.FloatBuffer
public abstract class FloatBuffer extends Buffer implements Comparable
 

This class defines four types of operations on the float Buffer:

Read and Write the absolute and relative values of a single float.GetAndPutMethod;

Transmits the continuous float sequence in this buffer to the relativeBatch getMethod;

Transmits the continuous float sequence in the float array or other float buffers to the relativeBatch putMethod; and

Float BufferCompacting,DuplicatingAndSlicingMethod.

The float buffer can pass throughAllocationCreated by usingWrappingPackage an existing float array into the buffer to allocate space for the buffer content, or create an existing byte BufferViewTo create

Like the byte buffer, the float buffer is eitherDirect, Or yesNon-direct. Through suchWrapThe float buffer created by the method will be non-direct. When and only when the byte buffer itself is direct, the float buffer created as the byte buffer view is direct. By callingisDirectMethod to Determine whether the float buffer is direct.

Specify methods in this class (they do not return other values) to return the buffer where these methods are called. This allows links to method calls.


Ii. Detailed Methods

1. public static FloatBufferAllocate(Int capacity) allocates a new float buffer.

The position of the new buffer is zero, and its boundary is its capacity, which is marked as undefined. It will haveUnderlying implementation ArrayAndArray offsetIt will be zero.

Parameters: capacity-New buffer capacity, in float Return Value:New float Buffer Throw: IllegalArgumentException-If CapacityNegative integer 2, public static FloatBuffer Wrap(Float [] array, int offset, int length)

Package the float array into the buffer.

The given float array supports the new buffer; that is, the modification of the buffer will lead to the modification of the array, and vice versa. The new buffer capacity will beArray. lengthAnd its location isOffset, The boundary isOffset + lengthThe tag is undefined. ItsUnderlying implementation ArrayFor the given array, and itsArray offsetIt will be zero.

Parameters: array-New Buffer array supported offset-The offset of the sub-array to be used. It must be non-negative and not greater Array. length. Set the location of the new buffer to this value. length-The length of the sub-array to be used. It must be non-negative and not greater Array. length-offset. Set the boundary of the new buffer Offset + length. Return Value:New float Buffer Throw: IndexOutOfBoundsException-If OffsetAnd LengthParameter premise is not true 3. public static FloatBuffer Wrap(Float [] array)

Package the float array into the buffer.

The given float array supports the new buffer; that is, the modification of the buffer will lead to the modification of the array, and vice versa. The capacity and boundary of the new buffer will beArray. lengthThe position is zero, and its mark is undefined. ItsUnderlying implementation ArrayFor the given array, and itsArray offsetIt will be zero.

Parameters: array-Array implementing this buffer zone Return Value:New float buffer 4. public abstract FloatBuffer Slice()

Create a new float buffer, whose content is the shared subsequence of the buffer content.

The content of the new buffer will start from the current location of the buffer. Changes to the buffer content are visible in the new buffer, and vice versa; the locations, boundaries, and tag values of the two buffers are independent of each other.

The position of the new buffer will be zero, and its capacity and boundaries will be the number of float remaining in the buffer, which is marked as undefined. When and only when the buffer is direct, the new buffer is direct. When and only when the buffer is read-only, the new buffer is read-only.

Return Value:New float buffer 5. public abstract FloatBuffer Duplicate()

Create a new float buffer that shares the content of this buffer.

The content of the new buffer will be the content of this buffer. Changes to the buffer content are visible in the new buffer, and vice versa; the locations, boundaries, and tag values of the two buffers are independent of each other.

The capacity, boundary, location, and tag value of the new buffer will be the same as that of the buffer. When and only when the buffer is direct, the new buffer is direct. When and only when the buffer is read-only, the new buffer is read-only.

Return Value:New float buffer 6. public abstract FloatBuffer AsReadOnlyBuffer()

Create a new read-only float buffer that shares the content of this buffer.

The content of the new buffer will be the content of this buffer. Changes to this buffer zone are visible in the new buffer zone, but the new buffer zone will be read-only and cannot be used to modify shared content. The locations, boundaries, and tag values of the two buffers are independent of each other.

The capacity, boundary, location, and tag value of the new buffer will be the same as that of the buffer.

If the buffer itself is read-only, this method correspondsduplicateThe methods are identical.

Return Value:New read-only float buffer 7. public abstract float Get()

Relative GetMethod. Read the float at the current position of the buffer, and then the position increments.

Return Value:Float of the Current Buffer location Throw: BufferUnderflowException-If the current position of the buffer zone is no less than its limit 8, public abstract FloatBuffer Put(Float f)

Relative PutMethod (Optional).

Write a given float to the current location of the buffer, and then the position increments.

Parameters: f-Float to be written Return Value:This buffer zone Throw: BufferOverflowException-If the current location of the buffer zone is not smaller than the limit ReadOnlyBufferException-If the buffer is read-only 9, public abstract float Get(Int index)

Absolute GetMethod. Read the float at a given position.

Parameters: index-Index where float is read Return Value:Float at the given Index Throw: IndexOutOfBoundsException-If IndexIs negative or not less than the buffer limit 10, public abstract FloatBuffer Put(Int index, float f)

Absolute PutMethod (Optional).

Write the given float to the given index of the buffer.

Parameters: index-Float will be written to this location f-Float value to be written Return Value:This buffer zone Throw: IndexOutOfBoundsException-If IndexIs negative or not less than the buffer limit ReadOnlyBufferException-If the buffer is read-only 11 or public FloatBuffer Get(Float [] dst, int offset, int length)

Relative batch GetMethod.

This method transfers the float of this buffer to the given target array. If the remaining float in the buffer is less than the float required by the request, that is, ifLength > Remaining ()Will not transmit float and throwBufferUnderflowException.

Otherwise, this method in this bufferLengthFloat is copied to the given array. The current position of the buffer and the given offset position in the array start to be copied. Then the location of the buffer increases progressivelyLength.

In other words, the method is called in the formSrc. get (dst, off, len)The call is exactly the same as the following loop statement:

     for (int i = off; i < off + len; i++)         dst[i] = src.get(); 
The difference is that it first checks whether the buffer has sufficient float, which may be more efficient.

Parameters: dst-Write the float Array offset-The offset of the first float to be written in the array. It must be non-negative and not greater Dst. length length-The maximum number of float entries to write to a given array. The value must be non-negative and not greater Dst. length-offset Return Value:This buffer zone Throw: BufferUnderflowException-If the remaining float in this buffer zone is less Length IndexOutOfBoundsException-If OffsetAnd LengthParameter premise is not true 12, public FloatBuffer Get(Float [] dst)

Relative batch GetMethod.

This method transfers the float of this buffer to the given target array. The method is called in the formSrc. get (), Which is exactly the same as the following:

     src.get(a, 0, a.length) 

Return Value:This buffer zone Throw: BufferUnderflowException-If the remaining float in this buffer zone is less Length13. public FloatBuffer Put(FloatBuffer src)

Relative batch PutMethod (Optional).

This method transfers the remaining float in the given source buffer to this buffer. If the remaining float space in the source buffer is greater than the remaining float space in the buffer, that isSrc. remaining () > Remaining ()Will not transmit float and throwBufferOverflowException.

Otherwise, this method will specifyN=Src. remaining ()Float copies to this buffer zone, starting from the current position of each buffer zone. Then the locations of the two buffers increase progressively.N.

In other words, the method is called in the formDst. put (src), The effect is exactly the same as the following loop statement:

     while (src.hasRemaining())         dst.put(src.get()); 
The difference is that it first checks whether the buffer has sufficient space, which may be more efficient.

Parameters: src-The source buffer from which the float is to be read. Return Value:This buffer zone Throw: BufferOverflowException-The buffer does not have enough space for the remaining float in the source buffer. IllegalArgumentException-If the source buffer is the buffer ReadOnlyBufferException-If the buffer is read-only 14 or public FloatBuffer Put(Float [] src, int offset, int length) Relative batch PutMethod (Optional).

This method transfers float in the given source array to this buffer. If you want to copy more float space from the array than the remaining float space in the buffer, that is, ifLength > Remaining ()Will not transmit float and throwBufferOverflowException.

Otherwise, this method will giveLengthFloat data is copied to the buffer, and the data is copied from the given offset position in the array and the current position in the buffer. Then the location of the buffer increases progressivelyLength.

In other words, the method is called in the formDst. put (src, off, len), The effect is exactly the same as the following loop statement:

     for (int i = off; i < off + len; i++)         dst.put(a[i]); 
The difference is that it first checks whether the buffer has sufficient space, which may be more efficient.

Parameters: src-Array from which float is to be read offset-The offset of the first float to be read in the array. It must be non-negative and not greater Array. length length-The number of float entries to be read from a given array. The value must be non-negative and not greater Array. length-offset Return Value:This buffer zone Throw: BufferOverflowException-If the buffer zone does not have enough space IndexOutOfBoundsException-If OffsetAnd LengthParameter prerequisite is not true ReadOnlyBufferException-If the buffer is read-only 15, public finalFloatBuffer Put(Float [] src)

Relative batch PutMethod (Optional).

This method transfers all content in the given source float array to this buffer. The method is called in the formDst. put (), Which is exactly the same as the following:

     dst.put(a, 0, a.length) 

Return Value:This buffer zone Throw: BufferOverflowException-If the buffer zone does not have enough space ReadOnlyBufferException-If the buffer is read-only 16, public final boolean HasArray()

Determine whether the buffer can be implemented through an accessible float array.

If this method returnsTrueCan be called safelyarrayAndarrayOffsetMethod.

Specified:Class BufferIn hasArray Return Value:If and only if an array implementing this buffer exists and this buffer is not a read-only buffer True17. public final float [] Array()

Returns the float array that implements this buffer. (Optional).

Modifying the content of this buffer will cause the returned array to be modified, and vice versa.

You must call this method before calling this method.hasArrayMethod To ensure that the buffer has an accessible underlying implementation array.

Specified:Class BufferIn array Return Value:Array implementing this buffer Throw: ReadOnlyBufferException-If there is an array implementing this buffer, but the buffer is read-only UnsupportedOperationException-If no accessible array exists, this buffer zone 18 and public final int will be implemented. ArrayOffset()

Returns the offset of the first element of the buffer in the underlying implementation array of the buffer. (Optional).

If there is an array implementing this buffer, the buffer locationPCorresponding to array indexP+ArrayOffset ().

You must call this method before calling this method.hasArrayMethod To ensure that the buffer has an accessible underlying implementation array.

Specified:Class BufferIn arrayOffset Return Value:Offset of the first element of the buffer in the buffer Array Throw: ReadOnlyBufferException-If there is an array implementing this buffer, but the buffer is read-only UnsupportedOperationException-If no accessible array exists, implement the buffer 19 and public abstractFloatBuffer. Compact()

Compress this buffer (Optional).

Copy the float (if any) between the current location and boundary of the buffer to the beginning of the buffer. Coming soonP=Position ()Copy the float at to index 0, and then copy the indexPCopy float at + 1 to index 1, and so on until IndexLimit ()-Copy float at 1 to indexN=Limit ()-1-P. Then, set the buffer locationN + 1And set its limit to its capacity. If a tag is defined, discard it.

Set the buffer location to the number of float copies, instead of zero, so that after this method is called, you can call another relativePutMethod.

Return Value:This buffer zone Throw: ReadOnlyBufferException-If the buffer is read-only 20, public abstract boolean IsDirect() Determine whether the float buffer is direct.

Specified:Class BufferIn isDirect Return Value:If and only if this buffer zone is direct True21. public String ToString()

Returns the string that summarizes the buffer status.

Overwrite:Class ObjectIn toString Return Value:A summary string 22, public int HashCode()

Returns the hash code of the buffer.

The hash code of the float buffer only depends on its remaining elements.Position ()Start till (including)Limit ()-1.

Because the buffer hash code is related to the content, we recommend that you do not use the buffer as a key in hash ing or similar data structures unless you know that their content will not change.

Overwrite:Class ObjectIn hashCode Return Value:Current hash code of this buffer For more information, see: Object.equals(java.lang.Object), Hashtable23. public boolean Equals(Object ob)

Determine whether the buffer is the same as another object.

The two float buffers are the same if and only if:

They have the same element type,

They have the same number of remaining elements and

The two remaining element sequences (irrelevant to their starting position) are point-by-point.

The float buffer is different from any other type of object.

Overwrite:Class ObjectIn equals Parameters: ob-Objects to be compared in this buffer zone Return Value:If and only if the buffer is the same as the given object True24. public int CompareTo(FloatBuffer that)

Compare this buffer with another buffer.

The method for comparing two float buffers is to compare their remaining Element Sequences in alphabetical order, regardless of the starting position of each sequence in its corresponding buffer.

The float buffer cannot be compared with any other type of object.

Specified:Interface Comparable In compareTo Parameters: that-Object to be compared. Return Value:If the buffer is less than, equal to, or greater than the given buffer, return a negative integer, zero, or positive integer 25, and public specified actbyteorder. Order() Obtain the byte sequence of the buffer.

Existing by allocation or packagingFloatThe byte sequence of the float buffer created by arrays is the underlying hardwareLocal Sequence. The byte sequence of the float buffer created as the byte buffer view is the byte sequence of the byte buffer when the view is created.

Return Value:Byte sequence of this buffer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.