All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.algart.arrays.JBuffers Maven / Gradle / Ivy

Go to download

Open-source Java libraries, supporting generalized smart arrays and matrices with elements of any types, including a wide set of 2D-, 3D- and multidimensional image processing and other algorithms, working with arrays and matrices.

There is a newer version: 1.4.23
Show newest version
/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2007-2024 Daniel Alievsky, AlgART Laboratory (http://algart.net)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package net.algart.arrays;

import java.nio.*;
import java.util.Objects;

/**
 * 

Some operations for Java NIO buffers manipulation in the same manner as array operations from * {@link JArrays} and java.util.Arrays classes.

* *

This class cannot be instantiated.

* * @author Daniel Alievsky */ public class JBuffers { private static final int FILL_NON_BLOCKED_LEN = 256; // must be 2^k private static final int FILL_BLOCK_LEN = 4 * 1024; // must be 2^k private static final int ZERO_FILL_BLOCK_LEN = 4 * 1024; // must be 2^k private static final boolean OPTIMIZE_BYTE_MIN_MAX_BY_TABLES = false; // antioptimization under Java 1.6+ private JBuffers() { } /*Repeat() byte ==> char,,short,,int,,long,,float,,double;; Byte ==> Char,,Short,,Int,,Long,,Float,,Double */ /** * Copies count byte elements from src buffer, * starting from srcPos index, * to the dest buffer, starting from destPos index. * It is an analog of standard System.arraycopy method for ByteBuffer. * *

This method works correctly even if src == dest * and the copied areas overlap, * i.e. if Math.abs(destPos - srcPos) < count. * More precisely, in this case the copying is performed as if the * elements at positions srcPos..srcPos+count-1 in src buffer * were first copied to a temporary array with count elements * and then the contents of the temporary array were copied into positions * destPos..destPos+count-1 in dest buffer. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param dest the destination ByteBuffer. * @param destPos starting index of element to replace. * @param src the source ByteBuffer. * @param srcPos starting index of element to be copied. * @param count the number of elements to be copied (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void copyByteBuffer(ByteBuffer dest, int destPos, ByteBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); if (src == dest && srcPos == destPos) { return; } copyByteBuffer(dest, destPos, src, srcPos, count, src == dest && srcPos <= destPos && srcPos + count > destPos); } /** * Copies count byte elements from src buffer, * starting from srcPos index, * to the dest buffer, starting from destPos index, * in normal or reverse order depending on reverseOrder argument. * *

If reverseOrder flag is false, this method copies elements in normal order: * element #srcPos of src * to element #destPos of dest, then * element #srcPos+1 of src * to element #destPos+1 of dest, then * element #srcPos+2 of src * to element #destPos+2 of dest, ..., then * element #srcPos+count-1 of src * to element #destPos+count-1 of dest. * If reverseOrder flag is true, this method copies elements in reverse order: * element #srcPos+count-1 of src * to element #destPos+count-1 of dest, then * element #srcPos+count-2 of src * to element #destPos+count-2 of dest, ..., then * element #srcPos of src to element #destPos of dest. * Usually, copying in reverse order is slower, but it is necessary if src * and dest are the same buffer or views or the same data (for example, * buffers mapped to the same file), the copied areas overlap and * destination position is greater than source position. * If src==dest, you may use {@link #copyByteBuffer(ByteBuffer, int, ByteBuffer, int, int)} * method that chooses the suitable order automatically. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param dest the destination ByteBuffer. * @param destPos starting index of element to replace. * @param src the source ByteBuffer. * @param srcPos starting index of element to be copied. * @param count the number of elements to be copied (should be >=0). * @param reverseOrder if true, the elements will be copied in the reverse order. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void copyByteBuffer( ByteBuffer dest, int destPos, ByteBuffer src, int srcPos, int count, boolean reverseOrder) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(src.limit(), srcPos, dest.limit(), destPos, count); if (reverseOrder) { int srcPos2 = srcPos + count - 1; int destPos2 = destPos + count - 1; for (; srcPos2 >= srcPos; srcPos2--, destPos2--) { dest.put(destPos2, src.get(srcPos2)); } } else { src = src.duplicate(); dest = dest.duplicate(); src.position(srcPos); dest.position(destPos); src.limit(srcPos + count); dest.put(src); } } /** * Swaps count byte elements in first buffer, * starting from firstPos index, * with count byte elements in second buffer, * starting from secondPos index. * *

Some elements may be swapped incorrectly if the swapped areas overlap, * i.e. if first==second and Math.abs(firstIndex - secondIndex) < count, * or if first and second are views of the same data * (for example, buffers mapped to the same file) and the corresponding areas of this data * overlap. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param first the first ByteBuffer. * @param firstPos starting index of element to exchange in the first ByteBuffer. * @param second the second ByteBuffer. * @param secondPos starting index of element to exchange in the second ByteBuffer. * @param count the number of elements to be exchanged (should be >=0). * @throws NullPointerException if either first or second is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void swapByteBuffer( ByteBuffer first, int firstPos, ByteBuffer second, int secondPos, int count) { Objects.requireNonNull(first, "Null first argument"); Objects.requireNonNull(second, "Null second argument"); JArrays.rangeCheck(first.limit(), firstPos, second.limit(), secondPos, count); for (int firstPosMax = firstPos + count; firstPos < firstPosMax; firstPos++, secondPos++) { byte v1 = first.get(firstPos); byte v2 = second.get(secondPos); first.put(firstPos, v2); second.put(secondPos, v1); } } /*Repeat.AutoGeneratedStart !! Auto-generated: NOT EDIT !! */ /** * Copies count char elements from src buffer, * starting from srcPos index, * to the dest buffer, starting from destPos index. * It is an analog of standard System.arraycopy method for CharBuffer. * *

This method works correctly even if src == dest * and the copied areas overlap, * i.e. if Math.abs(destPos - srcPos) < count. * More precisely, in this case the copying is performed as if the * elements at positions srcPos..srcPos+count-1 in src buffer * were first copied to a temporary array with count elements * and then the contents of the temporary array were copied into positions * destPos..destPos+count-1 in dest buffer. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param dest the destination CharBuffer. * @param destPos starting index of element to replace. * @param src the source CharBuffer. * @param srcPos starting index of element to be copied. * @param count the number of elements to be copied (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void copyCharBuffer(CharBuffer dest, int destPos, CharBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); if (src == dest && srcPos == destPos) { return; } copyCharBuffer(dest, destPos, src, srcPos, count, src == dest && srcPos <= destPos && srcPos + count > destPos); } /** * Copies count char elements from src buffer, * starting from srcPos index, * to the dest buffer, starting from destPos index, * in normal or reverse order depending on reverseOrder argument. * *

If reverseOrder flag is false, this method copies elements in normal order: * element #srcPos of src * to element #destPos of dest, then * element #srcPos+1 of src * to element #destPos+1 of dest, then * element #srcPos+2 of src * to element #destPos+2 of dest, ..., then * element #srcPos+count-1 of src * to element #destPos+count-1 of dest. * If reverseOrder flag is true, this method copies elements in reverse order: * element #srcPos+count-1 of src * to element #destPos+count-1 of dest, then * element #srcPos+count-2 of src * to element #destPos+count-2 of dest, ..., then * element #srcPos of src to element #destPos of dest. * Usually, copying in reverse order is slower, but it is necessary if src * and dest are the same buffer or views or the same data (for example, * buffers mapped to the same file), the copied areas overlap and * destination position is greater than source position. * If src==dest, you may use {@link #copyCharBuffer(CharBuffer, int, CharBuffer, int, int)} * method that chooses the suitable order automatically. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param dest the destination CharBuffer. * @param destPos starting index of element to replace. * @param src the source CharBuffer. * @param srcPos starting index of element to be copied. * @param count the number of elements to be copied (should be >=0). * @param reverseOrder if true, the elements will be copied in the reverse order. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void copyCharBuffer( CharBuffer dest, int destPos, CharBuffer src, int srcPos, int count, boolean reverseOrder) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(src.limit(), srcPos, dest.limit(), destPos, count); if (reverseOrder) { int srcPos2 = srcPos + count - 1; int destPos2 = destPos + count - 1; for (; srcPos2 >= srcPos; srcPos2--, destPos2--) { dest.put(destPos2, src.get(srcPos2)); } } else { src = src.duplicate(); dest = dest.duplicate(); src.position(srcPos); dest.position(destPos); src.limit(srcPos + count); dest.put(src); } } /** * Swaps count char elements in first buffer, * starting from firstPos index, * with count char elements in second buffer, * starting from secondPos index. * *

Some elements may be swapped incorrectly if the swapped areas overlap, * i.e. if first==second and Math.abs(firstIndex - secondIndex) < count, * or if first and second are views of the same data * (for example, buffers mapped to the same file) and the corresponding areas of this data * overlap. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param first the first CharBuffer. * @param firstPos starting index of element to exchange in the first CharBuffer. * @param second the second CharBuffer. * @param secondPos starting index of element to exchange in the second CharBuffer. * @param count the number of elements to be exchanged (should be >=0). * @throws NullPointerException if either first or second is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void swapCharBuffer( CharBuffer first, int firstPos, CharBuffer second, int secondPos, int count) { Objects.requireNonNull(first, "Null first argument"); Objects.requireNonNull(second, "Null second argument"); JArrays.rangeCheck(first.limit(), firstPos, second.limit(), secondPos, count); for (int firstPosMax = firstPos + count; firstPos < firstPosMax; firstPos++, secondPos++) { char v1 = first.get(firstPos); char v2 = second.get(secondPos); first.put(firstPos, v2); second.put(secondPos, v1); } } /** * Copies count short elements from src buffer, * starting from srcPos index, * to the dest buffer, starting from destPos index. * It is an analog of standard System.arraycopy method for ShortBuffer. * *

This method works correctly even if src == dest * and the copied areas overlap, * i.e. if Math.abs(destPos - srcPos) < count. * More precisely, in this case the copying is performed as if the * elements at positions srcPos..srcPos+count-1 in src buffer * were first copied to a temporary array with count elements * and then the contents of the temporary array were copied into positions * destPos..destPos+count-1 in dest buffer. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param dest the destination ShortBuffer. * @param destPos starting index of element to replace. * @param src the source ShortBuffer. * @param srcPos starting index of element to be copied. * @param count the number of elements to be copied (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void copyShortBuffer(ShortBuffer dest, int destPos, ShortBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); if (src == dest && srcPos == destPos) { return; } copyShortBuffer(dest, destPos, src, srcPos, count, src == dest && srcPos <= destPos && srcPos + count > destPos); } /** * Copies count short elements from src buffer, * starting from srcPos index, * to the dest buffer, starting from destPos index, * in normal or reverse order depending on reverseOrder argument. * *

If reverseOrder flag is false, this method copies elements in normal order: * element #srcPos of src * to element #destPos of dest, then * element #srcPos+1 of src * to element #destPos+1 of dest, then * element #srcPos+2 of src * to element #destPos+2 of dest, ..., then * element #srcPos+count-1 of src * to element #destPos+count-1 of dest. * If reverseOrder flag is true, this method copies elements in reverse order: * element #srcPos+count-1 of src * to element #destPos+count-1 of dest, then * element #srcPos+count-2 of src * to element #destPos+count-2 of dest, ..., then * element #srcPos of src to element #destPos of dest. * Usually, copying in reverse order is slower, but it is necessary if src * and dest are the same buffer or views or the same data (for example, * buffers mapped to the same file), the copied areas overlap and * destination position is greater than source position. * If src==dest, you may use {@link #copyShortBuffer(ShortBuffer, int, ShortBuffer, int, int)} * method that chooses the suitable order automatically. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param dest the destination ShortBuffer. * @param destPos starting index of element to replace. * @param src the source ShortBuffer. * @param srcPos starting index of element to be copied. * @param count the number of elements to be copied (should be >=0). * @param reverseOrder if true, the elements will be copied in the reverse order. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void copyShortBuffer( ShortBuffer dest, int destPos, ShortBuffer src, int srcPos, int count, boolean reverseOrder) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(src.limit(), srcPos, dest.limit(), destPos, count); if (reverseOrder) { int srcPos2 = srcPos + count - 1; int destPos2 = destPos + count - 1; for (; srcPos2 >= srcPos; srcPos2--, destPos2--) { dest.put(destPos2, src.get(srcPos2)); } } else { src = src.duplicate(); dest = dest.duplicate(); src.position(srcPos); dest.position(destPos); src.limit(srcPos + count); dest.put(src); } } /** * Swaps count short elements in first buffer, * starting from firstPos index, * with count short elements in second buffer, * starting from secondPos index. * *

Some elements may be swapped incorrectly if the swapped areas overlap, * i.e. if first==second and Math.abs(firstIndex - secondIndex) < count, * or if first and second are views of the same data * (for example, buffers mapped to the same file) and the corresponding areas of this data * overlap. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param first the first ShortBuffer. * @param firstPos starting index of element to exchange in the first ShortBuffer. * @param second the second ShortBuffer. * @param secondPos starting index of element to exchange in the second ShortBuffer. * @param count the number of elements to be exchanged (should be >=0). * @throws NullPointerException if either first or second is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void swapShortBuffer( ShortBuffer first, int firstPos, ShortBuffer second, int secondPos, int count) { Objects.requireNonNull(first, "Null first argument"); Objects.requireNonNull(second, "Null second argument"); JArrays.rangeCheck(first.limit(), firstPos, second.limit(), secondPos, count); for (int firstPosMax = firstPos + count; firstPos < firstPosMax; firstPos++, secondPos++) { short v1 = first.get(firstPos); short v2 = second.get(secondPos); first.put(firstPos, v2); second.put(secondPos, v1); } } /** * Copies count int elements from src buffer, * starting from srcPos index, * to the dest buffer, starting from destPos index. * It is an analog of standard System.arraycopy method for IntBuffer. * *

This method works correctly even if src == dest * and the copied areas overlap, * i.e. if Math.abs(destPos - srcPos) < count. * More precisely, in this case the copying is performed as if the * elements at positions srcPos..srcPos+count-1 in src buffer * were first copied to a temporary array with count elements * and then the contents of the temporary array were copied into positions * destPos..destPos+count-1 in dest buffer. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param dest the destination IntBuffer. * @param destPos starting index of element to replace. * @param src the source IntBuffer. * @param srcPos starting index of element to be copied. * @param count the number of elements to be copied (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void copyIntBuffer(IntBuffer dest, int destPos, IntBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); if (src == dest && srcPos == destPos) { return; } copyIntBuffer(dest, destPos, src, srcPos, count, src == dest && srcPos <= destPos && srcPos + count > destPos); } /** * Copies count int elements from src buffer, * starting from srcPos index, * to the dest buffer, starting from destPos index, * in normal or reverse order depending on reverseOrder argument. * *

If reverseOrder flag is false, this method copies elements in normal order: * element #srcPos of src * to element #destPos of dest, then * element #srcPos+1 of src * to element #destPos+1 of dest, then * element #srcPos+2 of src * to element #destPos+2 of dest, ..., then * element #srcPos+count-1 of src * to element #destPos+count-1 of dest. * If reverseOrder flag is true, this method copies elements in reverse order: * element #srcPos+count-1 of src * to element #destPos+count-1 of dest, then * element #srcPos+count-2 of src * to element #destPos+count-2 of dest, ..., then * element #srcPos of src to element #destPos of dest. * Usually, copying in reverse order is slower, but it is necessary if src * and dest are the same buffer or views or the same data (for example, * buffers mapped to the same file), the copied areas overlap and * destination position is greater than source position. * If src==dest, you may use {@link #copyIntBuffer(IntBuffer, int, IntBuffer, int, int)} * method that chooses the suitable order automatically. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param dest the destination IntBuffer. * @param destPos starting index of element to replace. * @param src the source IntBuffer. * @param srcPos starting index of element to be copied. * @param count the number of elements to be copied (should be >=0). * @param reverseOrder if true, the elements will be copied in the reverse order. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void copyIntBuffer( IntBuffer dest, int destPos, IntBuffer src, int srcPos, int count, boolean reverseOrder) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(src.limit(), srcPos, dest.limit(), destPos, count); if (reverseOrder) { int srcPos2 = srcPos + count - 1; int destPos2 = destPos + count - 1; for (; srcPos2 >= srcPos; srcPos2--, destPos2--) { dest.put(destPos2, src.get(srcPos2)); } } else { src = src.duplicate(); dest = dest.duplicate(); src.position(srcPos); dest.position(destPos); src.limit(srcPos + count); dest.put(src); } } /** * Swaps count int elements in first buffer, * starting from firstPos index, * with count int elements in second buffer, * starting from secondPos index. * *

Some elements may be swapped incorrectly if the swapped areas overlap, * i.e. if first==second and Math.abs(firstIndex - secondIndex) < count, * or if first and second are views of the same data * (for example, buffers mapped to the same file) and the corresponding areas of this data * overlap. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param first the first IntBuffer. * @param firstPos starting index of element to exchange in the first IntBuffer. * @param second the second IntBuffer. * @param secondPos starting index of element to exchange in the second IntBuffer. * @param count the number of elements to be exchanged (should be >=0). * @throws NullPointerException if either first or second is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void swapIntBuffer( IntBuffer first, int firstPos, IntBuffer second, int secondPos, int count) { Objects.requireNonNull(first, "Null first argument"); Objects.requireNonNull(second, "Null second argument"); JArrays.rangeCheck(first.limit(), firstPos, second.limit(), secondPos, count); for (int firstPosMax = firstPos + count; firstPos < firstPosMax; firstPos++, secondPos++) { int v1 = first.get(firstPos); int v2 = second.get(secondPos); first.put(firstPos, v2); second.put(secondPos, v1); } } /** * Copies count long elements from src buffer, * starting from srcPos index, * to the dest buffer, starting from destPos index. * It is an analog of standard System.arraycopy method for LongBuffer. * *

This method works correctly even if src == dest * and the copied areas overlap, * i.e. if Math.abs(destPos - srcPos) < count. * More precisely, in this case the copying is performed as if the * elements at positions srcPos..srcPos+count-1 in src buffer * were first copied to a temporary array with count elements * and then the contents of the temporary array were copied into positions * destPos..destPos+count-1 in dest buffer. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param dest the destination LongBuffer. * @param destPos starting index of element to replace. * @param src the source LongBuffer. * @param srcPos starting index of element to be copied. * @param count the number of elements to be copied (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void copyLongBuffer(LongBuffer dest, int destPos, LongBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); if (src == dest && srcPos == destPos) { return; } copyLongBuffer(dest, destPos, src, srcPos, count, src == dest && srcPos <= destPos && srcPos + count > destPos); } /** * Copies count long elements from src buffer, * starting from srcPos index, * to the dest buffer, starting from destPos index, * in normal or reverse order depending on reverseOrder argument. * *

If reverseOrder flag is false, this method copies elements in normal order: * element #srcPos of src * to element #destPos of dest, then * element #srcPos+1 of src * to element #destPos+1 of dest, then * element #srcPos+2 of src * to element #destPos+2 of dest, ..., then * element #srcPos+count-1 of src * to element #destPos+count-1 of dest. * If reverseOrder flag is true, this method copies elements in reverse order: * element #srcPos+count-1 of src * to element #destPos+count-1 of dest, then * element #srcPos+count-2 of src * to element #destPos+count-2 of dest, ..., then * element #srcPos of src to element #destPos of dest. * Usually, copying in reverse order is slower, but it is necessary if src * and dest are the same buffer or views or the same data (for example, * buffers mapped to the same file), the copied areas overlap and * destination position is greater than source position. * If src==dest, you may use {@link #copyLongBuffer(LongBuffer, int, LongBuffer, int, int)} * method that chooses the suitable order automatically. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param dest the destination LongBuffer. * @param destPos starting index of element to replace. * @param src the source LongBuffer. * @param srcPos starting index of element to be copied. * @param count the number of elements to be copied (should be >=0). * @param reverseOrder if true, the elements will be copied in the reverse order. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void copyLongBuffer( LongBuffer dest, int destPos, LongBuffer src, int srcPos, int count, boolean reverseOrder) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(src.limit(), srcPos, dest.limit(), destPos, count); if (reverseOrder) { int srcPos2 = srcPos + count - 1; int destPos2 = destPos + count - 1; for (; srcPos2 >= srcPos; srcPos2--, destPos2--) { dest.put(destPos2, src.get(srcPos2)); } } else { src = src.duplicate(); dest = dest.duplicate(); src.position(srcPos); dest.position(destPos); src.limit(srcPos + count); dest.put(src); } } /** * Swaps count long elements in first buffer, * starting from firstPos index, * with count long elements in second buffer, * starting from secondPos index. * *

Some elements may be swapped incorrectly if the swapped areas overlap, * i.e. if first==second and Math.abs(firstIndex - secondIndex) < count, * or if first and second are views of the same data * (for example, buffers mapped to the same file) and the corresponding areas of this data * overlap. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param first the first LongBuffer. * @param firstPos starting index of element to exchange in the first LongBuffer. * @param second the second LongBuffer. * @param secondPos starting index of element to exchange in the second LongBuffer. * @param count the number of elements to be exchanged (should be >=0). * @throws NullPointerException if either first or second is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void swapLongBuffer( LongBuffer first, int firstPos, LongBuffer second, int secondPos, int count) { Objects.requireNonNull(first, "Null first argument"); Objects.requireNonNull(second, "Null second argument"); JArrays.rangeCheck(first.limit(), firstPos, second.limit(), secondPos, count); for (int firstPosMax = firstPos + count; firstPos < firstPosMax; firstPos++, secondPos++) { long v1 = first.get(firstPos); long v2 = second.get(secondPos); first.put(firstPos, v2); second.put(secondPos, v1); } } /** * Copies count float elements from src buffer, * starting from srcPos index, * to the dest buffer, starting from destPos index. * It is an analog of standard System.arraycopy method for FloatBuffer. * *

This method works correctly even if src == dest * and the copied areas overlap, * i.e. if Math.abs(destPos - srcPos) < count. * More precisely, in this case the copying is performed as if the * elements at positions srcPos..srcPos+count-1 in src buffer * were first copied to a temporary array with count elements * and then the contents of the temporary array were copied into positions * destPos..destPos+count-1 in dest buffer. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param dest the destination FloatBuffer. * @param destPos starting index of element to replace. * @param src the source FloatBuffer. * @param srcPos starting index of element to be copied. * @param count the number of elements to be copied (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void copyFloatBuffer(FloatBuffer dest, int destPos, FloatBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); if (src == dest && srcPos == destPos) { return; } copyFloatBuffer(dest, destPos, src, srcPos, count, src == dest && srcPos <= destPos && srcPos + count > destPos); } /** * Copies count float elements from src buffer, * starting from srcPos index, * to the dest buffer, starting from destPos index, * in normal or reverse order depending on reverseOrder argument. * *

If reverseOrder flag is false, this method copies elements in normal order: * element #srcPos of src * to element #destPos of dest, then * element #srcPos+1 of src * to element #destPos+1 of dest, then * element #srcPos+2 of src * to element #destPos+2 of dest, ..., then * element #srcPos+count-1 of src * to element #destPos+count-1 of dest. * If reverseOrder flag is true, this method copies elements in reverse order: * element #srcPos+count-1 of src * to element #destPos+count-1 of dest, then * element #srcPos+count-2 of src * to element #destPos+count-2 of dest, ..., then * element #srcPos of src to element #destPos of dest. * Usually, copying in reverse order is slower, but it is necessary if src * and dest are the same buffer or views or the same data (for example, * buffers mapped to the same file), the copied areas overlap and * destination position is greater than source position. * If src==dest, you may use {@link #copyFloatBuffer(FloatBuffer, int, FloatBuffer, int, int)} * method that chooses the suitable order automatically. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param dest the destination FloatBuffer. * @param destPos starting index of element to replace. * @param src the source FloatBuffer. * @param srcPos starting index of element to be copied. * @param count the number of elements to be copied (should be >=0). * @param reverseOrder if true, the elements will be copied in the reverse order. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void copyFloatBuffer( FloatBuffer dest, int destPos, FloatBuffer src, int srcPos, int count, boolean reverseOrder) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(src.limit(), srcPos, dest.limit(), destPos, count); if (reverseOrder) { int srcPos2 = srcPos + count - 1; int destPos2 = destPos + count - 1; for (; srcPos2 >= srcPos; srcPos2--, destPos2--) { dest.put(destPos2, src.get(srcPos2)); } } else { src = src.duplicate(); dest = dest.duplicate(); src.position(srcPos); dest.position(destPos); src.limit(srcPos + count); dest.put(src); } } /** * Swaps count float elements in first buffer, * starting from firstPos index, * with count float elements in second buffer, * starting from secondPos index. * *

Some elements may be swapped incorrectly if the swapped areas overlap, * i.e. if first==second and Math.abs(firstIndex - secondIndex) < count, * or if first and second are views of the same data * (for example, buffers mapped to the same file) and the corresponding areas of this data * overlap. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param first the first FloatBuffer. * @param firstPos starting index of element to exchange in the first FloatBuffer. * @param second the second FloatBuffer. * @param secondPos starting index of element to exchange in the second FloatBuffer. * @param count the number of elements to be exchanged (should be >=0). * @throws NullPointerException if either first or second is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void swapFloatBuffer( FloatBuffer first, int firstPos, FloatBuffer second, int secondPos, int count) { Objects.requireNonNull(first, "Null first argument"); Objects.requireNonNull(second, "Null second argument"); JArrays.rangeCheck(first.limit(), firstPos, second.limit(), secondPos, count); for (int firstPosMax = firstPos + count; firstPos < firstPosMax; firstPos++, secondPos++) { float v1 = first.get(firstPos); float v2 = second.get(secondPos); first.put(firstPos, v2); second.put(secondPos, v1); } } /** * Copies count double elements from src buffer, * starting from srcPos index, * to the dest buffer, starting from destPos index. * It is an analog of standard System.arraycopy method for DoubleBuffer. * *

This method works correctly even if src == dest * and the copied areas overlap, * i.e. if Math.abs(destPos - srcPos) < count. * More precisely, in this case the copying is performed as if the * elements at positions srcPos..srcPos+count-1 in src buffer * were first copied to a temporary array with count elements * and then the contents of the temporary array were copied into positions * destPos..destPos+count-1 in dest buffer. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param dest the destination DoubleBuffer. * @param destPos starting index of element to replace. * @param src the source DoubleBuffer. * @param srcPos starting index of element to be copied. * @param count the number of elements to be copied (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void copyDoubleBuffer(DoubleBuffer dest, int destPos, DoubleBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); if (src == dest && srcPos == destPos) { return; } copyDoubleBuffer(dest, destPos, src, srcPos, count, src == dest && srcPos <= destPos && srcPos + count > destPos); } /** * Copies count double elements from src buffer, * starting from srcPos index, * to the dest buffer, starting from destPos index, * in normal or reverse order depending on reverseOrder argument. * *

If reverseOrder flag is false, this method copies elements in normal order: * element #srcPos of src * to element #destPos of dest, then * element #srcPos+1 of src * to element #destPos+1 of dest, then * element #srcPos+2 of src * to element #destPos+2 of dest, ..., then * element #srcPos+count-1 of src * to element #destPos+count-1 of dest. * If reverseOrder flag is true, this method copies elements in reverse order: * element #srcPos+count-1 of src * to element #destPos+count-1 of dest, then * element #srcPos+count-2 of src * to element #destPos+count-2 of dest, ..., then * element #srcPos of src to element #destPos of dest. * Usually, copying in reverse order is slower, but it is necessary if src * and dest are the same buffer or views or the same data (for example, * buffers mapped to the same file), the copied areas overlap and * destination position is greater than source position. * If src==dest, you may use {@link #copyDoubleBuffer(DoubleBuffer, int, DoubleBuffer, int, int)} * method that chooses the suitable order automatically. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param dest the destination DoubleBuffer. * @param destPos starting index of element to replace. * @param src the source DoubleBuffer. * @param srcPos starting index of element to be copied. * @param count the number of elements to be copied (should be >=0). * @param reverseOrder if true, the elements will be copied in the reverse order. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void copyDoubleBuffer( DoubleBuffer dest, int destPos, DoubleBuffer src, int srcPos, int count, boolean reverseOrder) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(src.limit(), srcPos, dest.limit(), destPos, count); if (reverseOrder) { int srcPos2 = srcPos + count - 1; int destPos2 = destPos + count - 1; for (; srcPos2 >= srcPos; srcPos2--, destPos2--) { dest.put(destPos2, src.get(srcPos2)); } } else { src = src.duplicate(); dest = dest.duplicate(); src.position(srcPos); dest.position(destPos); src.limit(srcPos + count); dest.put(src); } } /** * Swaps count double elements in first buffer, * starting from firstPos index, * with count double elements in second buffer, * starting from secondPos index. * *

Some elements may be swapped incorrectly if the swapped areas overlap, * i.e. if first==second and Math.abs(firstIndex - secondIndex) < count, * or if first and second are views of the same data * (for example, buffers mapped to the same file) and the corresponding areas of this data * overlap. * *

This method does not modify limit, position and mark properties * of the passed buffers. * * @param first the first DoubleBuffer. * @param firstPos starting index of element to exchange in the first DoubleBuffer. * @param second the second DoubleBuffer. * @param secondPos starting index of element to exchange in the second DoubleBuffer. * @param count the number of elements to be exchanged (should be >=0). * @throws NullPointerException if either first or second is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limits. */ public static void swapDoubleBuffer( DoubleBuffer first, int firstPos, DoubleBuffer second, int secondPos, int count) { Objects.requireNonNull(first, "Null first argument"); Objects.requireNonNull(second, "Null second argument"); JArrays.rangeCheck(first.limit(), firstPos, second.limit(), secondPos, count); for (int firstPosMax = firstPos + count; firstPos < firstPosMax; firstPos++, secondPos++) { double v1 = first.get(firstPos); double v2 = second.get(secondPos); first.put(firstPos, v2); second.put(secondPos, v1); } } /*Repeat.AutoGeneratedEnd*/ /*Repeat() byte ==> char,,short,,int,,long,,float,,double;; Byte ==> Char,,Short,,Int,,Long,,Float,,Double */ /** * Fills count elements in the dest buffer, * starting from the element #destPos, * by the specified value. Be careful: the second int argument in this method * is the number of filled element, but not the end filled index * as in java.util.Arrays.fill methods. * *

This method does not modify limit, position and mark properties * of the passed buffer. * * @param dest the filled ByteBuffer. * @param destPos starting index of element to replace. * @param count the number of elements to be filled (should be >=0). * @param value the filler. * @throws NullPointerException if dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limit. */ public static void fillByteBuffer(ByteBuffer dest, int destPos, int count, byte value) { Objects.requireNonNull(dest, "Null dest argument"); JArrays.rangeCheck(dest.limit(), destPos, count); if (count >= FILL_NON_BLOCKED_LEN) { byte[] arr; if (value != 0) { arr = new byte[FILL_BLOCK_LEN]; JArrays.fill(arr, value); } else { arr = new byte[ZERO_FILL_BLOCK_LEN]; } ByteBuffer destDup = dest.duplicate(); destDup.position(destPos); for (; count >= arr.length; count -= arr.length) { destDup.put(arr); } destDup.put(arr, 0, count); } else { for (int k = 0; k < count; k++) { dest.put(destPos + k, value); } } } /*Repeat.AutoGeneratedStart !! Auto-generated: NOT EDIT !! */ /** * Fills count elements in the dest buffer, * starting from the element #destPos, * by the specified value. Be careful: the second int argument in this method * is the number of filled element, but not the end filled index * as in java.util.Arrays.fill methods. * *

This method does not modify limit, position and mark properties * of the passed buffer. * * @param dest the filled CharBuffer. * @param destPos starting index of element to replace. * @param count the number of elements to be filled (should be >=0). * @param value the filler. * @throws NullPointerException if dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limit. */ public static void fillCharBuffer(CharBuffer dest, int destPos, int count, char value) { Objects.requireNonNull(dest, "Null dest argument"); JArrays.rangeCheck(dest.limit(), destPos, count); if (count >= FILL_NON_BLOCKED_LEN) { char[] arr; if (value != 0) { arr = new char[FILL_BLOCK_LEN]; JArrays.fill(arr, value); } else { arr = new char[ZERO_FILL_BLOCK_LEN]; } CharBuffer destDup = dest.duplicate(); destDup.position(destPos); for (; count >= arr.length; count -= arr.length) { destDup.put(arr); } destDup.put(arr, 0, count); } else { for (int k = 0; k < count; k++) { dest.put(destPos + k, value); } } } /** * Fills count elements in the dest buffer, * starting from the element #destPos, * by the specified value. Be careful: the second int argument in this method * is the number of filled element, but not the end filled index * as in java.util.Arrays.fill methods. * *

This method does not modify limit, position and mark properties * of the passed buffer. * * @param dest the filled ShortBuffer. * @param destPos starting index of element to replace. * @param count the number of elements to be filled (should be >=0). * @param value the filler. * @throws NullPointerException if dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limit. */ public static void fillShortBuffer(ShortBuffer dest, int destPos, int count, short value) { Objects.requireNonNull(dest, "Null dest argument"); JArrays.rangeCheck(dest.limit(), destPos, count); if (count >= FILL_NON_BLOCKED_LEN) { short[] arr; if (value != 0) { arr = new short[FILL_BLOCK_LEN]; JArrays.fill(arr, value); } else { arr = new short[ZERO_FILL_BLOCK_LEN]; } ShortBuffer destDup = dest.duplicate(); destDup.position(destPos); for (; count >= arr.length; count -= arr.length) { destDup.put(arr); } destDup.put(arr, 0, count); } else { for (int k = 0; k < count; k++) { dest.put(destPos + k, value); } } } /** * Fills count elements in the dest buffer, * starting from the element #destPos, * by the specified value. Be careful: the second int argument in this method * is the number of filled element, but not the end filled index * as in java.util.Arrays.fill methods. * *

This method does not modify limit, position and mark properties * of the passed buffer. * * @param dest the filled IntBuffer. * @param destPos starting index of element to replace. * @param count the number of elements to be filled (should be >=0). * @param value the filler. * @throws NullPointerException if dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limit. */ public static void fillIntBuffer(IntBuffer dest, int destPos, int count, int value) { Objects.requireNonNull(dest, "Null dest argument"); JArrays.rangeCheck(dest.limit(), destPos, count); if (count >= FILL_NON_BLOCKED_LEN) { int[] arr; if (value != 0) { arr = new int[FILL_BLOCK_LEN]; JArrays.fill(arr, value); } else { arr = new int[ZERO_FILL_BLOCK_LEN]; } IntBuffer destDup = dest.duplicate(); destDup.position(destPos); for (; count >= arr.length; count -= arr.length) { destDup.put(arr); } destDup.put(arr, 0, count); } else { for (int k = 0; k < count; k++) { dest.put(destPos + k, value); } } } /** * Fills count elements in the dest buffer, * starting from the element #destPos, * by the specified value. Be careful: the second int argument in this method * is the number of filled element, but not the end filled index * as in java.util.Arrays.fill methods. * *

This method does not modify limit, position and mark properties * of the passed buffer. * * @param dest the filled LongBuffer. * @param destPos starting index of element to replace. * @param count the number of elements to be filled (should be >=0). * @param value the filler. * @throws NullPointerException if dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limit. */ public static void fillLongBuffer(LongBuffer dest, int destPos, int count, long value) { Objects.requireNonNull(dest, "Null dest argument"); JArrays.rangeCheck(dest.limit(), destPos, count); if (count >= FILL_NON_BLOCKED_LEN) { long[] arr; if (value != 0) { arr = new long[FILL_BLOCK_LEN]; JArrays.fill(arr, value); } else { arr = new long[ZERO_FILL_BLOCK_LEN]; } LongBuffer destDup = dest.duplicate(); destDup.position(destPos); for (; count >= arr.length; count -= arr.length) { destDup.put(arr); } destDup.put(arr, 0, count); } else { for (int k = 0; k < count; k++) { dest.put(destPos + k, value); } } } /** * Fills count elements in the dest buffer, * starting from the element #destPos, * by the specified value. Be careful: the second int argument in this method * is the number of filled element, but not the end filled index * as in java.util.Arrays.fill methods. * *

This method does not modify limit, position and mark properties * of the passed buffer. * * @param dest the filled FloatBuffer. * @param destPos starting index of element to replace. * @param count the number of elements to be filled (should be >=0). * @param value the filler. * @throws NullPointerException if dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limit. */ public static void fillFloatBuffer(FloatBuffer dest, int destPos, int count, float value) { Objects.requireNonNull(dest, "Null dest argument"); JArrays.rangeCheck(dest.limit(), destPos, count); if (count >= FILL_NON_BLOCKED_LEN) { float[] arr; if (value != 0) { arr = new float[FILL_BLOCK_LEN]; JArrays.fill(arr, value); } else { arr = new float[ZERO_FILL_BLOCK_LEN]; } FloatBuffer destDup = dest.duplicate(); destDup.position(destPos); for (; count >= arr.length; count -= arr.length) { destDup.put(arr); } destDup.put(arr, 0, count); } else { for (int k = 0; k < count; k++) { dest.put(destPos + k, value); } } } /** * Fills count elements in the dest buffer, * starting from the element #destPos, * by the specified value. Be careful: the second int argument in this method * is the number of filled element, but not the end filled index * as in java.util.Arrays.fill methods. * *

This method does not modify limit, position and mark properties * of the passed buffer. * * @param dest the filled DoubleBuffer. * @param destPos starting index of element to replace. * @param count the number of elements to be filled (should be >=0). * @param value the filler. * @throws NullPointerException if dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if copying would cause access of data outside buffer limit. */ public static void fillDoubleBuffer(DoubleBuffer dest, int destPos, int count, double value) { Objects.requireNonNull(dest, "Null dest argument"); JArrays.rangeCheck(dest.limit(), destPos, count); if (count >= FILL_NON_BLOCKED_LEN) { double[] arr; if (value != 0) { arr = new double[FILL_BLOCK_LEN]; JArrays.fill(arr, value); } else { arr = new double[ZERO_FILL_BLOCK_LEN]; } DoubleBuffer destDup = dest.duplicate(); destDup.position(destPos); for (; count >= arr.length; count -= arr.length) { destDup.put(arr); } destDup.put(arr, 0, count); } else { for (int k = 0; k < count; k++) { dest.put(destPos + k, value); } } } /*Repeat.AutoGeneratedEnd*/ /*Repeat() byte ==> char,,short,,int,,long,,float,,double;; Byte ==> Char,,Short,,Int,,Long,,Float,,Double */ /** * Returns the minimal index k, so that * lowIndex<=k<min(highIndex,buffer.limit()) * and buffer.get(k)==value, * or -1 if there is no such buffer element. * *

In particular, if lowIndex>=buffer.limit() or lowIndex>=highIndex, * this method returns -1, * and if lowIndex<0, the result is the same as if lowIndex==0. * * @param buffer the searched ByteBuffer. * @param lowIndex the low index for search (inclusive). * @param highIndex the high index for search (exclusive); * pass buffer.limit() to search all remaining elements. * @param value the value to be found. * @return the index of the first occurrence of this value in range lowIndex..highIndex-1, * or -1 if this value does not occur * or if max(lowIndex,0)>=min(highIndex,buffer.limit()). * @throws NullPointerException if buffer is {@code null}. * @see #lastIndexOfByte(ByteBuffer, int, int, byte) */ public static int indexOfByte(ByteBuffer buffer, int lowIndex, int highIndex, byte value) { Objects.requireNonNull(buffer, "Null buffer argument"); if (lowIndex < 0) { lowIndex = 0; } int maxPlus1 = Math.min(buffer.limit(), highIndex); for (; lowIndex < maxPlus1; lowIndex++) { if (buffer.get(lowIndex) == value) { return lowIndex; } } return -1; } /** * Returns the maximal index k, so that highIndex>k>=max(lowIndex,0) * and buffer.get(k)==value, * or -1 if there is no such buffer element. * *

In particular, if highIndex<=0 or highIndex<=lowIndex, * this method returns -1, * and if highIndex>=buffer.limit(), the result * is the same as if highIndex==buffer.limit(). * *

Note that lowIndex and highIndex arguments have the same sense as in * {@link #indexOfByte(ByteBuffer, int, int, byte)} method: * they describe the search index range lowIndex<=k<highIndex. * * @param buffer the searched Java array. * @param lowIndex the low index in the array for search (inclusive); * pass 0 to search all remaining elements. * @param highIndex the high index in the array for search (exclusive). * @param value the value to be found. * @return the index of the last occurrence of this value in range lowIndex..highIndex-1, * or -1 if this value does not occur * or if max(lowIndex,0)>=min(highIndex,buffer.limit()). * @throws NullPointerException if buffer is {@code null}. * @see #indexOfByte(ByteBuffer, int, int, byte) */ public static int lastIndexOfByte(ByteBuffer buffer, int lowIndex, int highIndex, byte value) { Objects.requireNonNull(buffer, "Null buffer argument"); if (highIndex > buffer.limit()) { highIndex = buffer.limit(); } int min = Math.max(lowIndex, 0); while (highIndex > min) { if (buffer.get(--highIndex) == value) { return highIndex; } } return -1; } /*Repeat.AutoGeneratedStart !! Auto-generated: NOT EDIT !! */ /** * Returns the minimal index k, so that * lowIndex<=k<min(highIndex,buffer.limit()) * and buffer.get(k)==value, * or -1 if there is no such buffer element. * *

In particular, if lowIndex>=buffer.limit() or lowIndex>=highIndex, * this method returns -1, * and if lowIndex<0, the result is the same as if lowIndex==0. * * @param buffer the searched CharBuffer. * @param lowIndex the low index for search (inclusive). * @param highIndex the high index for search (exclusive); * pass buffer.limit() to search all remaining elements. * @param value the value to be found. * @return the index of the first occurrence of this value in range lowIndex..highIndex-1, * or -1 if this value does not occur * or if max(lowIndex,0)>=min(highIndex,buffer.limit()). * @throws NullPointerException if buffer is {@code null}. * @see #lastIndexOfChar(CharBuffer, int, int, char) */ public static int indexOfChar(CharBuffer buffer, int lowIndex, int highIndex, char value) { Objects.requireNonNull(buffer, "Null buffer argument"); if (lowIndex < 0) { lowIndex = 0; } int maxPlus1 = Math.min(buffer.limit(), highIndex); for (; lowIndex < maxPlus1; lowIndex++) { if (buffer.get(lowIndex) == value) { return lowIndex; } } return -1; } /** * Returns the maximal index k, so that highIndex>k>=max(lowIndex,0) * and buffer.get(k)==value, * or -1 if there is no such buffer element. * *

In particular, if highIndex<=0 or highIndex<=lowIndex, * this method returns -1, * and if highIndex>=buffer.limit(), the result * is the same as if highIndex==buffer.limit(). * *

Note that lowIndex and highIndex arguments have the same sense as in * {@link #indexOfChar(CharBuffer, int, int, char)} method: * they describe the search index range lowIndex<=k<highIndex. * * @param buffer the searched Java array. * @param lowIndex the low index in the array for search (inclusive); * pass 0 to search all remaining elements. * @param highIndex the high index in the array for search (exclusive). * @param value the value to be found. * @return the index of the last occurrence of this value in range lowIndex..highIndex-1, * or -1 if this value does not occur * or if max(lowIndex,0)>=min(highIndex,buffer.limit()). * @throws NullPointerException if buffer is {@code null}. * @see #indexOfChar(CharBuffer, int, int, char) */ public static int lastIndexOfChar(CharBuffer buffer, int lowIndex, int highIndex, char value) { Objects.requireNonNull(buffer, "Null buffer argument"); if (highIndex > buffer.limit()) { highIndex = buffer.limit(); } int min = Math.max(lowIndex, 0); while (highIndex > min) { if (buffer.get(--highIndex) == value) { return highIndex; } } return -1; } /** * Returns the minimal index k, so that * lowIndex<=k<min(highIndex,buffer.limit()) * and buffer.get(k)==value, * or -1 if there is no such buffer element. * *

In particular, if lowIndex>=buffer.limit() or lowIndex>=highIndex, * this method returns -1, * and if lowIndex<0, the result is the same as if lowIndex==0. * * @param buffer the searched ShortBuffer. * @param lowIndex the low index for search (inclusive). * @param highIndex the high index for search (exclusive); * pass buffer.limit() to search all remaining elements. * @param value the value to be found. * @return the index of the first occurrence of this value in range lowIndex..highIndex-1, * or -1 if this value does not occur * or if max(lowIndex,0)>=min(highIndex,buffer.limit()). * @throws NullPointerException if buffer is {@code null}. * @see #lastIndexOfShort(ShortBuffer, int, int, short) */ public static int indexOfShort(ShortBuffer buffer, int lowIndex, int highIndex, short value) { Objects.requireNonNull(buffer, "Null buffer argument"); if (lowIndex < 0) { lowIndex = 0; } int maxPlus1 = Math.min(buffer.limit(), highIndex); for (; lowIndex < maxPlus1; lowIndex++) { if (buffer.get(lowIndex) == value) { return lowIndex; } } return -1; } /** * Returns the maximal index k, so that highIndex>k>=max(lowIndex,0) * and buffer.get(k)==value, * or -1 if there is no such buffer element. * *

In particular, if highIndex<=0 or highIndex<=lowIndex, * this method returns -1, * and if highIndex>=buffer.limit(), the result * is the same as if highIndex==buffer.limit(). * *

Note that lowIndex and highIndex arguments have the same sense as in * {@link #indexOfShort(ShortBuffer, int, int, short)} method: * they describe the search index range lowIndex<=k<highIndex. * * @param buffer the searched Java array. * @param lowIndex the low index in the array for search (inclusive); * pass 0 to search all remaining elements. * @param highIndex the high index in the array for search (exclusive). * @param value the value to be found. * @return the index of the last occurrence of this value in range lowIndex..highIndex-1, * or -1 if this value does not occur * or if max(lowIndex,0)>=min(highIndex,buffer.limit()). * @throws NullPointerException if buffer is {@code null}. * @see #indexOfShort(ShortBuffer, int, int, short) */ public static int lastIndexOfShort(ShortBuffer buffer, int lowIndex, int highIndex, short value) { Objects.requireNonNull(buffer, "Null buffer argument"); if (highIndex > buffer.limit()) { highIndex = buffer.limit(); } int min = Math.max(lowIndex, 0); while (highIndex > min) { if (buffer.get(--highIndex) == value) { return highIndex; } } return -1; } /** * Returns the minimal index k, so that * lowIndex<=k<min(highIndex,buffer.limit()) * and buffer.get(k)==value, * or -1 if there is no such buffer element. * *

In particular, if lowIndex>=buffer.limit() or lowIndex>=highIndex, * this method returns -1, * and if lowIndex<0, the result is the same as if lowIndex==0. * * @param buffer the searched IntBuffer. * @param lowIndex the low index for search (inclusive). * @param highIndex the high index for search (exclusive); * pass buffer.limit() to search all remaining elements. * @param value the value to be found. * @return the index of the first occurrence of this value in range lowIndex..highIndex-1, * or -1 if this value does not occur * or if max(lowIndex,0)>=min(highIndex,buffer.limit()). * @throws NullPointerException if buffer is {@code null}. * @see #lastIndexOfInt(IntBuffer, int, int, int) */ public static int indexOfInt(IntBuffer buffer, int lowIndex, int highIndex, int value) { Objects.requireNonNull(buffer, "Null buffer argument"); if (lowIndex < 0) { lowIndex = 0; } int maxPlus1 = Math.min(buffer.limit(), highIndex); for (; lowIndex < maxPlus1; lowIndex++) { if (buffer.get(lowIndex) == value) { return lowIndex; } } return -1; } /** * Returns the maximal index k, so that highIndex>k>=max(lowIndex,0) * and buffer.get(k)==value, * or -1 if there is no such buffer element. * *

In particular, if highIndex<=0 or highIndex<=lowIndex, * this method returns -1, * and if highIndex>=buffer.limit(), the result * is the same as if highIndex==buffer.limit(). * *

Note that lowIndex and highIndex arguments have the same sense as in * {@link #indexOfInt(IntBuffer, int, int, int)} method: * they describe the search index range lowIndex<=k<highIndex. * * @param buffer the searched Java array. * @param lowIndex the low index in the array for search (inclusive); * pass 0 to search all remaining elements. * @param highIndex the high index in the array for search (exclusive). * @param value the value to be found. * @return the index of the last occurrence of this value in range lowIndex..highIndex-1, * or -1 if this value does not occur * or if max(lowIndex,0)>=min(highIndex,buffer.limit()). * @throws NullPointerException if buffer is {@code null}. * @see #indexOfInt(IntBuffer, int, int, int) */ public static int lastIndexOfInt(IntBuffer buffer, int lowIndex, int highIndex, int value) { Objects.requireNonNull(buffer, "Null buffer argument"); if (highIndex > buffer.limit()) { highIndex = buffer.limit(); } int min = Math.max(lowIndex, 0); while (highIndex > min) { if (buffer.get(--highIndex) == value) { return highIndex; } } return -1; } /** * Returns the minimal index k, so that * lowIndex<=k<min(highIndex,buffer.limit()) * and buffer.get(k)==value, * or -1 if there is no such buffer element. * *

In particular, if lowIndex>=buffer.limit() or lowIndex>=highIndex, * this method returns -1, * and if lowIndex<0, the result is the same as if lowIndex==0. * * @param buffer the searched LongBuffer. * @param lowIndex the low index for search (inclusive). * @param highIndex the high index for search (exclusive); * pass buffer.limit() to search all remaining elements. * @param value the value to be found. * @return the index of the first occurrence of this value in range lowIndex..highIndex-1, * or -1 if this value does not occur * or if max(lowIndex,0)>=min(highIndex,buffer.limit()). * @throws NullPointerException if buffer is {@code null}. * @see #lastIndexOfLong(LongBuffer, int, int, long) */ public static int indexOfLong(LongBuffer buffer, int lowIndex, int highIndex, long value) { Objects.requireNonNull(buffer, "Null buffer argument"); if (lowIndex < 0) { lowIndex = 0; } int maxPlus1 = Math.min(buffer.limit(), highIndex); for (; lowIndex < maxPlus1; lowIndex++) { if (buffer.get(lowIndex) == value) { return lowIndex; } } return -1; } /** * Returns the maximal index k, so that highIndex>k>=max(lowIndex,0) * and buffer.get(k)==value, * or -1 if there is no such buffer element. * *

In particular, if highIndex<=0 or highIndex<=lowIndex, * this method returns -1, * and if highIndex>=buffer.limit(), the result * is the same as if highIndex==buffer.limit(). * *

Note that lowIndex and highIndex arguments have the same sense as in * {@link #indexOfLong(LongBuffer, int, int, long)} method: * they describe the search index range lowIndex<=k<highIndex. * * @param buffer the searched Java array. * @param lowIndex the low index in the array for search (inclusive); * pass 0 to search all remaining elements. * @param highIndex the high index in the array for search (exclusive). * @param value the value to be found. * @return the index of the last occurrence of this value in range lowIndex..highIndex-1, * or -1 if this value does not occur * or if max(lowIndex,0)>=min(highIndex,buffer.limit()). * @throws NullPointerException if buffer is {@code null}. * @see #indexOfLong(LongBuffer, int, int, long) */ public static int lastIndexOfLong(LongBuffer buffer, int lowIndex, int highIndex, long value) { Objects.requireNonNull(buffer, "Null buffer argument"); if (highIndex > buffer.limit()) { highIndex = buffer.limit(); } int min = Math.max(lowIndex, 0); while (highIndex > min) { if (buffer.get(--highIndex) == value) { return highIndex; } } return -1; } /** * Returns the minimal index k, so that * lowIndex<=k<min(highIndex,buffer.limit()) * and buffer.get(k)==value, * or -1 if there is no such buffer element. * *

In particular, if lowIndex>=buffer.limit() or lowIndex>=highIndex, * this method returns -1, * and if lowIndex<0, the result is the same as if lowIndex==0. * * @param buffer the searched FloatBuffer. * @param lowIndex the low index for search (inclusive). * @param highIndex the high index for search (exclusive); * pass buffer.limit() to search all remaining elements. * @param value the value to be found. * @return the index of the first occurrence of this value in range lowIndex..highIndex-1, * or -1 if this value does not occur * or if max(lowIndex,0)>=min(highIndex,buffer.limit()). * @throws NullPointerException if buffer is {@code null}. * @see #lastIndexOfFloat(FloatBuffer, int, int, float) */ public static int indexOfFloat(FloatBuffer buffer, int lowIndex, int highIndex, float value) { Objects.requireNonNull(buffer, "Null buffer argument"); if (lowIndex < 0) { lowIndex = 0; } int maxPlus1 = Math.min(buffer.limit(), highIndex); for (; lowIndex < maxPlus1; lowIndex++) { if (buffer.get(lowIndex) == value) { return lowIndex; } } return -1; } /** * Returns the maximal index k, so that highIndex>k>=max(lowIndex,0) * and buffer.get(k)==value, * or -1 if there is no such buffer element. * *

In particular, if highIndex<=0 or highIndex<=lowIndex, * this method returns -1, * and if highIndex>=buffer.limit(), the result * is the same as if highIndex==buffer.limit(). * *

Note that lowIndex and highIndex arguments have the same sense as in * {@link #indexOfFloat(FloatBuffer, int, int, float)} method: * they describe the search index range lowIndex<=k<highIndex. * * @param buffer the searched Java array. * @param lowIndex the low index in the array for search (inclusive); * pass 0 to search all remaining elements. * @param highIndex the high index in the array for search (exclusive). * @param value the value to be found. * @return the index of the last occurrence of this value in range lowIndex..highIndex-1, * or -1 if this value does not occur * or if max(lowIndex,0)>=min(highIndex,buffer.limit()). * @throws NullPointerException if buffer is {@code null}. * @see #indexOfFloat(FloatBuffer, int, int, float) */ public static int lastIndexOfFloat(FloatBuffer buffer, int lowIndex, int highIndex, float value) { Objects.requireNonNull(buffer, "Null buffer argument"); if (highIndex > buffer.limit()) { highIndex = buffer.limit(); } int min = Math.max(lowIndex, 0); while (highIndex > min) { if (buffer.get(--highIndex) == value) { return highIndex; } } return -1; } /** * Returns the minimal index k, so that * lowIndex<=k<min(highIndex,buffer.limit()) * and buffer.get(k)==value, * or -1 if there is no such buffer element. * *

In particular, if lowIndex>=buffer.limit() or lowIndex>=highIndex, * this method returns -1, * and if lowIndex<0, the result is the same as if lowIndex==0. * * @param buffer the searched DoubleBuffer. * @param lowIndex the low index for search (inclusive). * @param highIndex the high index for search (exclusive); * pass buffer.limit() to search all remaining elements. * @param value the value to be found. * @return the index of the first occurrence of this value in range lowIndex..highIndex-1, * or -1 if this value does not occur * or if max(lowIndex,0)>=min(highIndex,buffer.limit()). * @throws NullPointerException if buffer is {@code null}. * @see #lastIndexOfDouble(DoubleBuffer, int, int, double) */ public static int indexOfDouble(DoubleBuffer buffer, int lowIndex, int highIndex, double value) { Objects.requireNonNull(buffer, "Null buffer argument"); if (lowIndex < 0) { lowIndex = 0; } int maxPlus1 = Math.min(buffer.limit(), highIndex); for (; lowIndex < maxPlus1; lowIndex++) { if (buffer.get(lowIndex) == value) { return lowIndex; } } return -1; } /** * Returns the maximal index k, so that highIndex>k>=max(lowIndex,0) * and buffer.get(k)==value, * or -1 if there is no such buffer element. * *

In particular, if highIndex<=0 or highIndex<=lowIndex, * this method returns -1, * and if highIndex>=buffer.limit(), the result * is the same as if highIndex==buffer.limit(). * *

Note that lowIndex and highIndex arguments have the same sense as in * {@link #indexOfDouble(DoubleBuffer, int, int, double)} method: * they describe the search index range lowIndex<=k<highIndex. * * @param buffer the searched Java array. * @param lowIndex the low index in the array for search (inclusive); * pass 0 to search all remaining elements. * @param highIndex the high index in the array for search (exclusive). * @param value the value to be found. * @return the index of the last occurrence of this value in range lowIndex..highIndex-1, * or -1 if this value does not occur * or if max(lowIndex,0)>=min(highIndex,buffer.limit()). * @throws NullPointerException if buffer is {@code null}. * @see #indexOfDouble(DoubleBuffer, int, int, double) */ public static int lastIndexOfDouble(DoubleBuffer buffer, int lowIndex, int highIndex, double value) { Objects.requireNonNull(buffer, "Null buffer argument"); if (highIndex > buffer.limit()) { highIndex = buffer.limit(); } int min = Math.max(lowIndex, 0); while (highIndex > min) { if (buffer.get(--highIndex) == value) { return highIndex; } } return -1; } /*Repeat.AutoGeneratedEnd*/ /** * Replaces count elements in dest array, * starting from the element #destPos, * with the minimum of them and corresponding count elements in src buffer, * starting from the element #srcPos. * The byte elements are considered to be unsigned: min(a,b)=(a&0xFF)<(b&0xFF)?a:b. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source ByteBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void minByteArrayAndBuffer(byte[] dest, int destPos, ByteBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); if (OPTIMIZE_BYTE_MIN_MAX_BY_TABLES) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] = JArrays.MinMaxTables.MIN_TABLE[ ((src.get(srcPos) & 0xFF) << 8) | (dest[destPos] & 0xFF)]; } } else { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { byte v = src.get(srcPos); if ((v & 0xFF) < (dest[destPos] & 0xFF)) { dest[destPos] = v; } } } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the minimum of them and corresponding count elements in src buffer, * starting from the element #srcPos. * The byte elements are considered to be unsigned: min(a,b)=(a&0xFF)<(b&0xFF)?a:b. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source ByteBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void maxByteArrayAndBuffer(byte[] dest, int destPos, ByteBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); if (OPTIMIZE_BYTE_MIN_MAX_BY_TABLES) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] = JArrays.MinMaxTables.MAX_TABLE[ ((src.get(srcPos) & 0xFF) << 8) | (dest[destPos] & 0xFF)]; } } else { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { byte v = src.get(srcPos); if ((v & 0xFF) > (dest[destPos] & 0xFF)) { dest[destPos] = v; } } } } /*Repeat() short ==> char,,int,,long,,float,,double;; Short ==> Char,,Int,,Long,,Float,,Double;; (\s*&(?:amp;)?\s*0xFFFF) ==> ,,...;; (The\s+\w+\s+elements.*?<\/code>\.\s*\*) ==> ,,... */ /** * Replaces count elements in dest array, * starting from the element #destPos, * with the minimum of them and corresponding count elements in src buffer, * starting from the element #srcPos. * The short elements are considered to be unsigned: min(a,b)=(a&0xFFFF)<(b&0xFFFF)?a:b. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source ShortBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void minShortArrayAndBuffer(short[] dest, int destPos, ShortBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { short v = src.get(srcPos); if ((v & 0xFFFF) < (dest[destPos] & 0xFFFF)) { dest[destPos] = v; } } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the minimum of them and corresponding count elements in src buffer, * starting from the element #srcPos. * The short elements are considered to be unsigned: min(a,b)=(a&0xFFFF)<(b&0xFFFF)?a:b. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source ShortBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void maxShortArrayAndBuffer(short[] dest, int destPos, ShortBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { short v = src.get(srcPos); if ((v & 0xFFFF) > (dest[destPos] & 0xFFFF)) { dest[destPos] = v; } } } /*Repeat.AutoGeneratedStart !! Auto-generated: NOT EDIT !! */ /** * Replaces count elements in dest array, * starting from the element #destPos, * with the minimum of them and corresponding count elements in src buffer, * starting from the element #srcPos. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source CharBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void minCharArrayAndBuffer(char[] dest, int destPos, CharBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { char v = src.get(srcPos); if ((v) < (dest[destPos])) { dest[destPos] = v; } } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the minimum of them and corresponding count elements in src buffer, * starting from the element #srcPos. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source CharBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void maxCharArrayAndBuffer(char[] dest, int destPos, CharBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { char v = src.get(srcPos); if ((v) > (dest[destPos])) { dest[destPos] = v; } } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the minimum of them and corresponding count elements in src buffer, * starting from the element #srcPos. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source IntBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void minIntArrayAndBuffer(int[] dest, int destPos, IntBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { int v = src.get(srcPos); if ((v) < (dest[destPos])) { dest[destPos] = v; } } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the minimum of them and corresponding count elements in src buffer, * starting from the element #srcPos. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source IntBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void maxIntArrayAndBuffer(int[] dest, int destPos, IntBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { int v = src.get(srcPos); if ((v) > (dest[destPos])) { dest[destPos] = v; } } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the minimum of them and corresponding count elements in src buffer, * starting from the element #srcPos. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source LongBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void minLongArrayAndBuffer(long[] dest, int destPos, LongBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { long v = src.get(srcPos); if ((v) < (dest[destPos])) { dest[destPos] = v; } } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the minimum of them and corresponding count elements in src buffer, * starting from the element #srcPos. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source LongBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void maxLongArrayAndBuffer(long[] dest, int destPos, LongBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { long v = src.get(srcPos); if ((v) > (dest[destPos])) { dest[destPos] = v; } } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the minimum of them and corresponding count elements in src buffer, * starting from the element #srcPos. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source FloatBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void minFloatArrayAndBuffer(float[] dest, int destPos, FloatBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { float v = src.get(srcPos); if ((v) < (dest[destPos])) { dest[destPos] = v; } } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the minimum of them and corresponding count elements in src buffer, * starting from the element #srcPos. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source FloatBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void maxFloatArrayAndBuffer(float[] dest, int destPos, FloatBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { float v = src.get(srcPos); if ((v) > (dest[destPos])) { dest[destPos] = v; } } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the minimum of them and corresponding count elements in src buffer, * starting from the element #srcPos. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source DoubleBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void minDoubleArrayAndBuffer(double[] dest, int destPos, DoubleBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { double v = src.get(srcPos); if ((v) < (dest[destPos])) { dest[destPos] = v; } } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the minimum of them and corresponding count elements in src buffer, * starting from the element #srcPos. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source DoubleBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void maxDoubleArrayAndBuffer(double[] dest, int destPos, DoubleBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { double v = src.get(srcPos); if ((v) > (dest[destPos])) { dest[destPos] = v; } } } /*Repeat.AutoGeneratedEnd*/ /*Repeat() byte ==> char,,short,,int,,long,,float,,double;; Byte ==> Char,,Short,,Int,,Long,,Float,,Double;; (\(int\)\s*)(src) ==> $2,,$1$2,,$2,,$1$2,,$1$2,,$1$2;; (\s*&(?:amp;)?\s*0xFF) ==> ,,$1FF,, ,,...;; (The\s+\w+\s+elements.*?\.\s*\*) ==> ,,$1,, ,,... */ /** * Replaces count elements in dest array, * starting from the element #destPos, * with the sum of them and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]+=(src.get(srcPos+i)&0xFF). * The byte elements are considered to be unsigned. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source ByteBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void addByteBufferToArray(int[] dest, int destPos, ByteBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += (int) src.get(srcPos) & 0xFF; } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the sum of them and corresponding count elements in src buffer, * multiplied by mult argument, * starting from the element #srcPos: * dest[destPos+i]+=(src.get(srcPos+i)&0xFF)*mult. * The byte elements are considered to be unsigned. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source ByteBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @param mult the elements from src array are multiplied by this value before adding. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void addByteBufferToArray( double[] dest, int destPos, ByteBuffer src, int srcPos, int count, double mult) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); if (mult == 0.0) { return; } if (mult == 1.0) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += src.get(srcPos) & 0xFF; } } else if (mult == -1.0) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] -= src.get(srcPos) & 0xFF; } } else { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += (src.get(srcPos) & 0xFF) * mult; } } } /*Repeat.AutoGeneratedStart !! Auto-generated: NOT EDIT !! */ /** * Replaces count elements in dest array, * starting from the element #destPos, * with the sum of them and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]+=(src.get(srcPos+i)). * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source CharBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void addCharBufferToArray(int[] dest, int destPos, CharBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += src.get(srcPos); } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the sum of them and corresponding count elements in src buffer, * multiplied by mult argument, * starting from the element #srcPos: * dest[destPos+i]+=(src.get(srcPos+i))*mult. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source CharBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @param mult the elements from src array are multiplied by this value before adding. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void addCharBufferToArray( double[] dest, int destPos, CharBuffer src, int srcPos, int count, double mult) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); if (mult == 0.0) { return; } if (mult == 1.0) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += src.get(srcPos); } } else if (mult == -1.0) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] -= src.get(srcPos); } } else { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += (src.get(srcPos)) * mult; } } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the sum of them and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]+=(src.get(srcPos+i)&0xFFFF). * The short elements are considered to be unsigned. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source ShortBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void addShortBufferToArray(int[] dest, int destPos, ShortBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += (int) src.get(srcPos) & 0xFFFF; } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the sum of them and corresponding count elements in src buffer, * multiplied by mult argument, * starting from the element #srcPos: * dest[destPos+i]+=(src.get(srcPos+i)&0xFFFF)*mult. * The short elements are considered to be unsigned. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source ShortBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @param mult the elements from src array are multiplied by this value before adding. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void addShortBufferToArray( double[] dest, int destPos, ShortBuffer src, int srcPos, int count, double mult) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); if (mult == 0.0) { return; } if (mult == 1.0) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += src.get(srcPos) & 0xFFFF; } } else if (mult == -1.0) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] -= src.get(srcPos) & 0xFFFF; } } else { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += (src.get(srcPos) & 0xFFFF) * mult; } } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the sum of them and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]+=(src.get(srcPos+i)). * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source IntBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void addIntBufferToArray(int[] dest, int destPos, IntBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += src.get(srcPos); } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the sum of them and corresponding count elements in src buffer, * multiplied by mult argument, * starting from the element #srcPos: * dest[destPos+i]+=(src.get(srcPos+i))*mult. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source IntBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @param mult the elements from src array are multiplied by this value before adding. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void addIntBufferToArray( double[] dest, int destPos, IntBuffer src, int srcPos, int count, double mult) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); if (mult == 0.0) { return; } if (mult == 1.0) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += src.get(srcPos); } } else if (mult == -1.0) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] -= src.get(srcPos); } } else { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += (src.get(srcPos)) * mult; } } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the sum of them and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]+=(src.get(srcPos+i)). * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source LongBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void addLongBufferToArray(int[] dest, int destPos, LongBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += (int) src.get(srcPos); } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the sum of them and corresponding count elements in src buffer, * multiplied by mult argument, * starting from the element #srcPos: * dest[destPos+i]+=(src.get(srcPos+i))*mult. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source LongBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @param mult the elements from src array are multiplied by this value before adding. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void addLongBufferToArray( double[] dest, int destPos, LongBuffer src, int srcPos, int count, double mult) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); if (mult == 0.0) { return; } if (mult == 1.0) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += src.get(srcPos); } } else if (mult == -1.0) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] -= src.get(srcPos); } } else { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += (src.get(srcPos)) * mult; } } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the sum of them and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]+=(src.get(srcPos+i)). * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source FloatBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void addFloatBufferToArray(int[] dest, int destPos, FloatBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += (int) src.get(srcPos); } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the sum of them and corresponding count elements in src buffer, * multiplied by mult argument, * starting from the element #srcPos: * dest[destPos+i]+=(src.get(srcPos+i))*mult. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source FloatBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @param mult the elements from src array are multiplied by this value before adding. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void addFloatBufferToArray( double[] dest, int destPos, FloatBuffer src, int srcPos, int count, double mult) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); if (mult == 0.0) { return; } if (mult == 1.0) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += src.get(srcPos); } } else if (mult == -1.0) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] -= src.get(srcPos); } } else { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += (src.get(srcPos)) * mult; } } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the sum of them and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]+=(src.get(srcPos+i)). * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source DoubleBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void addDoubleBufferToArray(int[] dest, int destPos, DoubleBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += (int) src.get(srcPos); } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the sum of them and corresponding count elements in src buffer, * multiplied by mult argument, * starting from the element #srcPos: * dest[destPos+i]+=(src.get(srcPos+i))*mult. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source DoubleBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @param mult the elements from src array are multiplied by this value before adding. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limit. */ public static void addDoubleBufferToArray( double[] dest, int destPos, DoubleBuffer src, int srcPos, int count, double mult) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); if (mult == 0.0) { return; } if (mult == 1.0) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += src.get(srcPos); } } else if (mult == -1.0) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] -= src.get(srcPos); } } else { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] += (src.get(srcPos)) * mult; } } } /*Repeat.AutoGeneratedEnd*/ /*Repeat() (int\s*v\s*=) ==> $1,,$1;; (\(int\))(dest|src) ==> $1$2,,$1$2;; byte ==> char,,short;; Byte ==> Char,,Short;; BYTE ==> CHAR,,SHORT;; (\s*&(?:amp;)?\s*0xFF) ==> ,,$1FF;; (0\.\.0xFF) ==> $1FF,,$1FF;; (The\s+\w+\s+elements.*?\.\s*\*) ==> ,,$1 */ /** * Replaces count elements in dest array, * starting from the element #destPos, * with the difference of them and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]=dest[destPos+i]-src.get(srcPos+i). * If truncateOverflows argument is true, the difference is truncated * to 0..0xFF range before assigning to dest elements. * The byte elements are considered to be unsigned. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source ByteBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @param truncateOverflows whether the results should be truncated to 0..0xFF range. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limits. */ public static void subtractByteBufferFromArray( byte[] dest, int destPos, ByteBuffer src, int srcPos, int count, boolean truncateOverflows) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); if (truncateOverflows) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { int v = ((int) dest[destPos] & 0xFF) - ((int) src.get(srcPos) & 0xFF); dest[destPos] = v < 0 ? 0 : (byte) v; } } else { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] -= src.get(srcPos); } } } /*Repeat.AutoGeneratedStart !! Auto-generated: NOT EDIT !! */ /** * Replaces count elements in dest array, * starting from the element #destPos, * with the difference of them and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]=dest[destPos+i]-src.get(srcPos+i). * If truncateOverflows argument is true, the difference is truncated * to 0..0xFFFF range before assigning to dest elements. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source CharBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @param truncateOverflows whether the results should be truncated to 0..0xFFFF range. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limits. */ public static void subtractCharBufferFromArray( char[] dest, int destPos, CharBuffer src, int srcPos, int count, boolean truncateOverflows) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); if (truncateOverflows) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { int v = ((int) dest[destPos]) - ((int) src.get(srcPos)); dest[destPos] = v < 0 ? 0 : (char) v; } } else { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] -= src.get(srcPos); } } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the difference of them and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]=dest[destPos+i]-src.get(srcPos+i). * If truncateOverflows argument is true, the difference is truncated * to 0..0xFFFF range before assigning to dest elements. * The short elements are considered to be unsigned. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source ShortBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @param truncateOverflows whether the results should be truncated to 0..0xFFFF range. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limits. */ public static void subtractShortBufferFromArray( short[] dest, int destPos, ShortBuffer src, int srcPos, int count, boolean truncateOverflows) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); if (truncateOverflows) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { int v = ((int) dest[destPos] & 0xFFFF) - ((int) src.get(srcPos) & 0xFFFF); dest[destPos] = v < 0 ? 0 : (short) v; } } else { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] -= src.get(srcPos); } } } /*Repeat.AutoGeneratedEnd*/ /** * Replaces count elements in dest array, * starting from the element #destPos, * with the difference of them and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]=dest[destPos+i]-src.get(srcPos+i). * If truncateOverflows argument is true, the difference is truncated * to Integer.MIN_VALUE..Integer.MAX_VALUE range before assigning to dest elements. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source IntBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @param truncateOverflows whether the results should be truncated to * Integer.MIN_VALUE..Integer.MAX_VALUE range. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limits. */ public static void subtractIntBufferFromArray( int[] dest, int destPos, IntBuffer src, int srcPos, int count, boolean truncateOverflows) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); if (truncateOverflows) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { long v = (long) dest[destPos] - (long) src.get(srcPos); dest[destPos] = v < Integer.MIN_VALUE ? Integer.MIN_VALUE : v > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) v; } } else { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] -= src.get(srcPos); } } } /*Repeat() long ==> float,,double;; Long ==> Float,,Double */ /** * Replaces count elements in dest array, * starting from the element #destPos, * with the difference of them and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]=dest[destPos+i]-src.get(srcPos+i). * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source LongBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limits. */ public static void subtractLongBufferFromArray( long[] dest, int destPos, LongBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] -= src.get(srcPos); } } /*Repeat.AutoGeneratedStart !! Auto-generated: NOT EDIT !! */ /** * Replaces count elements in dest array, * starting from the element #destPos, * with the difference of them and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]=dest[destPos+i]-src.get(srcPos+i). * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source FloatBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limits. */ public static void subtractFloatBufferFromArray( float[] dest, int destPos, FloatBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] -= src.get(srcPos); } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the difference of them and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]=dest[destPos+i]-src.get(srcPos+i). * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source DoubleBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limits. */ public static void subtractDoubleBufferFromArray( double[] dest, int destPos, DoubleBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { dest[destPos] -= src.get(srcPos); } } /*Repeat.AutoGeneratedEnd*/ /*Repeat() byte ==> char,,short,,long,,float,,double;; Byte ==> Char,,Short,,Long,,Float,,Double;; (\s*&\s*0xFF) ==> ,,$1FF,, ,,...;; \((long|float|double)\)\s+ ==> ,,...;; (\(The\s+\w+\s+elements.*?\.\)\s*\*) ==> ,,$1,, ,,... */ /** * Replaces count elements in dest array, * starting from the element #destPos, * with the absolute value of the difference of them * and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]=|dest[destPos+i]-src.get(srcPos+i)|. * (The byte elements are considered to be unsigned.) * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source ByteBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limits. */ public static void absDiffOfByteArrayAndBuffer( byte[] dest, int destPos, ByteBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { byte v = src.get(srcPos); dest[destPos] = (dest[destPos] & 0xFF) >= (v & 0xFF) ? (byte) (dest[destPos] - v) : (byte) (v - dest[destPos]); } } /*Repeat.AutoGeneratedStart !! Auto-generated: NOT EDIT !! */ /** * Replaces count elements in dest array, * starting from the element #destPos, * with the absolute value of the difference of them * and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]=|dest[destPos+i]-src.get(srcPos+i)|. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source CharBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limits. */ public static void absDiffOfCharArrayAndBuffer( char[] dest, int destPos, CharBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { char v = src.get(srcPos); dest[destPos] = (dest[destPos]) >= (v) ? (char) (dest[destPos] - v) : (char) (v - dest[destPos]); } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the absolute value of the difference of them * and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]=|dest[destPos+i]-src.get(srcPos+i)|. * (The short elements are considered to be unsigned.) * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source ShortBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limits. */ public static void absDiffOfShortArrayAndBuffer( short[] dest, int destPos, ShortBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { short v = src.get(srcPos); dest[destPos] = (dest[destPos] & 0xFFFF) >= (v & 0xFFFF) ? (short) (dest[destPos] - v) : (short) (v - dest[destPos]); } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the absolute value of the difference of them * and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]=|dest[destPos+i]-src.get(srcPos+i)|. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source LongBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limits. */ public static void absDiffOfLongArrayAndBuffer( long[] dest, int destPos, LongBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { long v = src.get(srcPos); dest[destPos] = (dest[destPos]) >= (v) ? (dest[destPos] - v) : (v - dest[destPos]); } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the absolute value of the difference of them * and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]=|dest[destPos+i]-src.get(srcPos+i)|. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source FloatBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limits. */ public static void absDiffOfFloatArrayAndBuffer( float[] dest, int destPos, FloatBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { float v = src.get(srcPos); dest[destPos] = (dest[destPos]) >= (v) ? (dest[destPos] - v) : (v - dest[destPos]); } } /** * Replaces count elements in dest array, * starting from the element #destPos, * with the absolute value of the difference of them * and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]=|dest[destPos+i]-src.get(srcPos+i)|. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source DoubleBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limits. */ public static void absDiffOfDoubleArrayAndBuffer( double[] dest, int destPos, DoubleBuffer src, int srcPos, int count) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { double v = src.get(srcPos); dest[destPos] = (dest[destPos]) >= (v) ? (dest[destPos] - v) : (v - dest[destPos]); } } /*Repeat.AutoGeneratedEnd*/ /** * Replaces count elements in dest array, * starting from the element #destPos, * with the absolute value of the difference of them * and corresponding count elements in src buffer, * starting from the element #srcPos: * dest[destPos+i]=|dest[destPos+i]-src[srcPos+i]|. * If truncateOverflows argument is true, the difference is truncated * to 0..Integer.MAX_VALUE range before assigning to dest elements. * * @param dest the destination array. * @param destPos position of the first replaced element in the destination array. * @param src the source IntBuffer. * @param srcPos position of the first read element in the source buffer. * @param count the number of elements to be replaced (should be >=0). * @param truncateOverflows whether the results should be truncated to * Integer.MIN_VALUE..Integer.MAX_VALUE range. * @throws NullPointerException if either src or dest is {@code null}. * @throws IllegalArgumentException if count is negative. * @throws IndexOutOfBoundsException if accessing elements would cause access of data outside array bounds * or buffer limits. */ public static void absDiffOfIntArrayAndBuffer( int[] dest, int destPos, IntBuffer src, int srcPos, int count, boolean truncateOverflows) { Objects.requireNonNull(dest, "Null dest argument"); Objects.requireNonNull(src, "Null src argument"); JArrays.rangeCheck(dest.length, destPos, src.limit(), srcPos, count); if (truncateOverflows) { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { long v = (long) dest[destPos] - (long) src.get(srcPos); if (v < 0) { v = -v; } dest[destPos] = v > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) v; } } else { for (int srcPosMax = srcPos + count; srcPos < srcPosMax; srcPos++, destPos++) { int v = src.get(srcPos); dest[destPos] = dest[destPos] >= v ? dest[destPos] - v : v - dest[destPos]; } } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy