44
55@ SuppressWarnings ("unused" )
66public class BufferUtils {
7+ /**
8+ * Prints the content of the given ShortBuffer.
9+ *
10+ * @param buffer The ShortBuffer to be printed.
11+ */
712 public static void printBuffer (ShortBuffer buffer ) {
813 System .out .print ("Buffer content: " );
914 while (buffer .hasRemaining ()) {
@@ -12,6 +17,14 @@ public static void printBuffer(ShortBuffer buffer) {
1217 System .out .println ();
1318 buffer .flip ();
1419 }
20+
21+ /**
22+ * Finds the middle value between two ShortBuffers and returns a new ShortBuffer containing these middle values.
23+ *
24+ * @param buffer1 The first ShortBuffer.
25+ * @param buffer2 The second ShortBuffer.
26+ * @return A new ShortBuffer containing the middle values.
27+ */
1528 public static ShortBuffer findMiddleValue (ShortBuffer buffer1 , ShortBuffer buffer2 ) {
1629 // Calculate the number of elements to be written to the middle buffer
1730 int writeCount = Math .min (buffer1 .remaining (), buffer2 .remaining ());
@@ -34,6 +47,14 @@ public static ShortBuffer findMiddleValue(ShortBuffer buffer1, ShortBuffer buffe
3447 buffer2 .flip (); // Prepare the buffer for reading
3548 return middleBuffer ;
3649 }
50+
51+ /**
52+ * Combines two ShortBuffers into a new one, where each element is the sum of the corresponding elements in the input buffers.
53+ *
54+ * @param buffer1 The first ShortBuffer.
55+ * @param buffer2 The second ShortBuffer.
56+ * @return A new ShortBuffer containing the combined values.
57+ */
3758 public static ShortBuffer combineValue (ShortBuffer buffer1 , ShortBuffer buffer2 ) {
3859 int combinedSize = buffer1 .remaining () + buffer2 .remaining ();
3960 ShortBuffer combinedBuffer = ShortBuffer .allocate (combinedSize );
@@ -57,6 +78,14 @@ public static ShortBuffer combineValue(ShortBuffer buffer1, ShortBuffer buffer2)
5778 combinedBuffer .flip (); // Prepare the buffer for reading
5879 return combinedBuffer ;
5980 }
81+
82+ /**
83+ * Divides each element in the given ShortBuffer by a factor and returns a new ShortBuffer containing the result.
84+ *
85+ * @param buffer The ShortBuffer to be divided.
86+ * @param factor The factor by which each element will be divided.
87+ * @return A new ShortBuffer containing the divided values.
88+ */
6089 public static ShortBuffer divideBuffer (ShortBuffer buffer , double factor ) {
6190 int writeCount = buffer .remaining ();
6291 ShortBuffer middleBuffer = ShortBuffer .allocate (writeCount );
@@ -67,6 +96,15 @@ public static ShortBuffer divideBuffer(ShortBuffer buffer, double factor) {
6796 middleBuffer .flip (); // Prepare the buffer for reading
6897 return middleBuffer ;
6998 }
99+
100+ /**
101+ * Multiplies each element in the given ShortBuffer by a factor and returns a new ShortBuffer containing the result.
102+ * The result is clamped to the range of a short value.
103+ *
104+ * @param buffer The ShortBuffer to be multiplied.
105+ * @param factor The factor by which each element will be multiplied.
106+ * @return A new ShortBuffer containing the multiplied values.
107+ */
70108 public static ShortBuffer multiplyBuffer (ShortBuffer buffer , double factor ) {
71109 int writeCount = buffer .remaining ();
72110 ShortBuffer middleBuffer = ShortBuffer .allocate (writeCount );
0 commit comments