Class CharacterBuf
- java.lang.Object
-
- edu.rit.mp.Buf
-
- edu.rit.mp.CharacterBuf
-
- Direct Known Subclasses:
- CharacterArrayBuf, CharacterItemBuf, CharacterMatrixBuf, EmptyCharacterBuf, SharedCharacterArrayBuf, SharedCharacterBuf
public abstract class CharacterBuf extends Buf
Class CharacterBuf is the abstract base class for a buffer of character items sent or received using the Message Protocol (MP). In a message, a character item is represented as two bytes, most significant byte first.A buffer may be used to send one or more messages at the same time in multiple threads. If a buffer is being used to send a message or messages, the buffer must not be used to receive a message at the same time.
A buffer may be used to receive one message at a time. If a buffer is being used to receive a message, the buffer must not be used to receive another message in a different thread, and the buffer must not be used to send a message or messages.
A buffer is a conduit for retrieving and storing data in some underlying data structure. If the underlying data structure is multiple thread safe, then one thread can be retrieving or storing data via the buffer at the same time as other threads are accessing the data structure. If the underlying data structure is not multiple thread safe, then other threads must not access the data structure while one thread is retrieving or storing data via the buffer.
To create a CharacterBuf, call one of the following static factory methods:
- emptyBuffer()
- buffer()
- buffer (char)
- buffer (char[])
- sliceBuffer (char[], Range)
- sliceBuffers (char[], Range[])
- buffer (char[][])
- rowSliceBuffer (char[][], Range)
- rowSliceBuffers (char[][], Range[])
- colSliceBuffer (char[][], Range)
- colSliceBuffers (char[][], Range[])
- patchBuffer (char[][], Range, Range)
- patchBuffers (char[][], Range[], Range[])
- buffer (SharedCharacter)
- buffer (SharedCharacterArray)
- sliceBuffer (SharedCharacterArray, Range)
- sliceBuffers (SharedCharacterArray, Range[])
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description static CharacterItemBufbuffer()Create a buffer for a character item.static CharacterItemBufbuffer(char item)Create a buffer for a character item with the given initial value.static CharacterBufbuffer(char[] theArray)Create a buffer for the entire given character array.static CharacterBufbuffer(char[][] theMatrix)Create a buffer for the entire given character matrix.static CharacterBufbuffer(SharedCharacter item)Create a buffer for a shared character item.static CharacterBufbuffer(SharedCharacterArray theArray)Create a buffer for the entire given shared character array.static CharacterBufcolSliceBuffer(char[][] theMatrix, Range theColRange)Create a buffer for one column slice of the given character matrix.static CharacterBuf[]colSliceBuffers(char[][] theMatrix, Range[] theColRanges)Create an array of buffers for multiple column slices of the given character matrix.voidcopy(Buf theSrc)Copy items from the given buffer to this buffer.static CharacterBufemptyBuffer()Create an empty buffer.voidfill(java.lang.Object item)Fill this buffer with the given item.abstract charget(int i)Obtain the given item from this buffer.BufgetTemporaryBuf()Create a temporary buffer with the same type of items and the same length as this buffer.static CharacterBufpatchBuffer(char[][] theMatrix, Range theRowRange, Range theColRange)Create a buffer for one patch of the given character matrix.static CharacterBuf[]patchBuffers(char[][] theMatrix, Range[] theRowRanges, Range[] theColRanges)Create an array of buffers for multiple patches of the given character matrix.abstract voidput(int i, char item)Store the given item in this buffer.static CharacterBufrowSliceBuffer(char[][] theMatrix, Range theRowRange)Create a buffer for one row slice of the given character matrix.static CharacterBuf[]rowSliceBuffers(char[][] theMatrix, Range[] theRowRanges)Create an array of buffers for multiple row slices of the given character matrix.static CharacterBufsliceBuffer(char[] theArray, Range theRange)Create a buffer for one slice of the given character array.static CharacterBufsliceBuffer(SharedCharacterArray theArray, Range theRange)Create a buffer for one slice of the given shared character array.static CharacterBuf[]sliceBuffers(char[] theArray, Range[] theRanges)Create an array of buffers for multiple slices of the given character array.static CharacterBuf[]sliceBuffers(SharedCharacterArray theArray, Range[] theRanges)Create an array of buffers for multiple slices of the given shared character array.-
Methods inherited from class edu.rit.mp.Buf
getReductionBuf, length
-
-
-
-
Method Detail
-
emptyBuffer
public static CharacterBuf emptyBuffer()
Create an empty buffer. The buffer's length is 0. The buffer's item type is character.- Returns:
- Empty buffer.
-
buffer
public static CharacterItemBuf buffer()
Create a buffer for a character item. The item is stored in the item field of the buffer.- Returns:
- Buffer.
-
buffer
public static CharacterItemBuf buffer(char item)
Create a buffer for a character item with the given initial value. The item is stored in the item field of the buffer.- Parameters:
item- Initial value of the item field.- Returns:
- Buffer.
-
buffer
public static CharacterBuf buffer(char[] theArray)
Create a buffer for the entire given character array. The returned buffer encompasses all the elements in theArray.- Parameters:
theArray- Array.- Returns:
- Buffer.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theArray is null.
-
sliceBuffer
public static CharacterBuf sliceBuffer(char[] theArray, Range theRange)
Create a buffer for one slice of the given character array. The returned buffer encompasses theRange of elements in theArray. The range's stride may be 1 or greater than 1.- Parameters:
theArray- Array.theRange- Range of elements to include.- Returns:
- Buffer.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theArray is null or theRange is null.java.lang.IndexOutOfBoundsException- (unchecked exception) Thrown if theArray does not include all the indexes in theRange.
-
sliceBuffers
public static CharacterBuf[] sliceBuffers(char[] theArray, Range[] theRanges)
Create an array of buffers for multiple slices of the given character array. The returned buffer array has the same length as theRanges. Each element [i] of the returned buffer array encompasses the elements of theArray specified by theRanges[i]. Each range's stride may be 1 or greater than 1.- Parameters:
theArray- Array.theRanges- Array of ranges of elements to include.- Returns:
- Array of buffers.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theArray is null or theRanges or any element thereof is null.java.lang.IndexOutOfBoundsException- (unchecked exception) Thrown if theArray's allocation does not include any element of theRanges.
-
buffer
public static CharacterBuf buffer(char[][] theMatrix)
Create a buffer for the entire given character matrix. The returned buffer encompasses all the rows and all the columns in theMatrix.- Parameters:
theMatrix- Matrix.- Returns:
- Buffer.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theMatrix is null.
-
rowSliceBuffer
public static CharacterBuf rowSliceBuffer(char[][] theMatrix, Range theRowRange)
Create a buffer for one row slice of the given character matrix. The returned buffer encompasses theRowRange of rows, and all the columns, in theMatrix. The range's stride may be 1 or greater than 1.- Parameters:
theMatrix- Matrix.theRowRange- Range of rows to include.- Returns:
- Buffer.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theMatrix is null or theRowRange is null.java.lang.IndexOutOfBoundsException- (unchecked exception) Thrown if theMatrix's allocation does not include theRowRange.
-
rowSliceBuffers
public static CharacterBuf[] rowSliceBuffers(char[][] theMatrix, Range[] theRowRanges)
Create an array of buffers for multiple row slices of the given character matrix. The returned buffer array has the same length as theRowRanges. Each element [i] of the returned buffer array encompasses the rows of theMatrix specified by theRowRanges[i] and all the columns of theMatrix. Each range's stride may be 1 or greater than 1.- Parameters:
theMatrix- Matrix.theRowRanges- Array of ranges of rows to include.- Returns:
- Array of buffers.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theMatrix is null or theRowRanges or any element thereof is null.java.lang.IndexOutOfBoundsException- (unchecked exception) Thrown if theMatrix's allocation does not include any element of theRowRanges.
-
colSliceBuffer
public static CharacterBuf colSliceBuffer(char[][] theMatrix, Range theColRange)
Create a buffer for one column slice of the given character matrix. The returned buffer encompasses all the rows, and theColRange of columns, in theMatrix. The range's stride may be 1 or greater than 1.- Parameters:
theMatrix- Matrix.theColRange- Range of columns to include.- Returns:
- Buffer.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theMatrix is null or theColRange is null.java.lang.IndexOutOfBoundsException- (unchecked exception) Thrown if theMatrix's allocation does not include theColRange.
-
colSliceBuffers
public static CharacterBuf[] colSliceBuffers(char[][] theMatrix, Range[] theColRanges)
Create an array of buffers for multiple column slices of the given character matrix. The returned buffer array has the same length as theColRanges. Each element [i] of the returned buffer array encompasses all the rows of theMatrix and the columns of theMatrix specified by theColRanges[i]. Each range's stride may be 1 or greater than 1.- Parameters:
theMatrix- Matrix.theColRanges- Array of ranges of columns to include.- Returns:
- Array of buffers.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theMatrix is null or theColRanges or any element thereof is null.java.lang.IndexOutOfBoundsException- (unchecked exception) Thrown if theMatrix's allocation does not include any element of theColRanges.
-
patchBuffer
public static CharacterBuf patchBuffer(char[][] theMatrix, Range theRowRange, Range theColRange)
Create a buffer for one patch of the given character matrix. The returned buffer encompasses theRowRange of rows, and theColRange of columns, in theMatrix. Each range's stride may be 1 or greater than 1.- Parameters:
theMatrix- Matrix.theRowRange- Range of rows to include.theColRange- Range of columns to include.- Returns:
- Buffer.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theMatrix is null, theRowRange is null, or theColRange is null.java.lang.IndexOutOfBoundsException- (unchecked exception) Thrown if theMatrix's allocation does not include theRowRange and theColRange.
-
patchBuffers
public static CharacterBuf[] patchBuffers(char[][] theMatrix, Range[] theRowRanges, Range[] theColRanges)
Create an array of buffers for multiple patches of the given character matrix. The length of the returned buffer array is equal to the length of theRowRanges times the length of theColRanges. Each element of the returned buffer array encompasses the rows given in one element of theRowRanges array, and the columns given in one element of theColRanges array, in all possible combinations, of theMatrix. Each range's stride may be 1 or greater than 1.- Parameters:
theMatrix- Matrix.theRowRanges- Array of ranges of rows to include.theColRanges- Array of ranges of columns to include.- Returns:
- Array of buffers.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theMatrix is null, theRowRanges or any element thereof is null, or theColRanges or any element thereof is null.java.lang.IndexOutOfBoundsException- (unchecked exception) Thrown if theMatrix's allocation does not include any element of theRowRanges or theColRanges.
-
buffer
public static CharacterBuf buffer(SharedCharacter item)
Create a buffer for a shared character item. The item is wrapped in an instance of class SharedCharacter. Use the methods of the SharedCharacter object to access the actual item.- Parameters:
item- SharedCharacter object that wraps the item.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if item is null.
-
buffer
public static CharacterBuf buffer(SharedCharacterArray theArray)
Create a buffer for the entire given shared character array. The returned buffer encompasses all the elements in theArray.- Parameters:
theArray- Array.- Returns:
- Buffer.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theArray is null.
-
sliceBuffer
public static CharacterBuf sliceBuffer(SharedCharacterArray theArray, Range theRange)
Create a buffer for one slice of the given shared character array. The returned buffer encompasses theRange of elements in theArray. The range's stride may be 1 or greater than 1.- Parameters:
theArray- Array.theRange- Range of elements to include.- Returns:
- Buffer.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theArray is null or theRange is null.java.lang.IndexOutOfBoundsException- (unchecked exception) Thrown if theArray does not include all the indexes in theRange.
-
sliceBuffers
public static CharacterBuf[] sliceBuffers(SharedCharacterArray theArray, Range[] theRanges)
Create an array of buffers for multiple slices of the given shared character array. The returned buffer array has the same length as theRanges. Each element [i] of the returned buffer array encompasses the elements of theArray specified by theRanges[i]. Each range's stride may be 1 or greater than 1.- Parameters:
theArray- Array.theRanges- Array of ranges of elements to include.- Returns:
- Array of buffers.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theArray is null or theRanges or any element thereof is null.java.lang.IndexOutOfBoundsException- (unchecked exception) Thrown if theArray's allocation does not include any element of theRanges.
-
get
public abstract char get(int i)
Obtain the given item from this buffer.The get() method must not block the calling thread; if it does, all message I/O in MP will be blocked.
- Parameters:
i- Item index in the range 0 .. length()-1.- Returns:
- Item at index i.
-
put
public abstract void put(int i, char item)Store the given item in this buffer.The put() method must not block the calling thread; if it does, all message I/O in MP will be blocked.
- Parameters:
i- Item index in the range 0 .. length()-1.item- Item to be stored at index i.
-
copy
public void copy(Buf theSrc)
Copy items from the given buffer to this buffer. The number of items copied is this buffer's length or theSrc's length, whichever is smaller. If theSrc is this buffer, the copy() method does nothing.The default implementation of the copy() method calls the defaultCopy() method. A subclass can override the copy() method to use a more efficient algorithm.
-
fill
public void fill(java.lang.Object item)
Fill this buffer with the given item. The item is assigned to each element in this buffer.The item must be an instance of class Character. If the item is null, ' ' is assigned to each element in this buffer.
-
getTemporaryBuf
public Buf getTemporaryBuf()
Create a temporary buffer with the same type of items and the same length as this buffer. The new buffer items are stored in a newly created array, separate from the storage for this buffer's items.- Specified by:
getTemporaryBufin classBuf
-
-
DMelt 3.0 © DataMelt by jWork.ORG