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

tfw.immutable.ila.floatila.FloatIlaRemove Maven / Gradle / Ivy

Go to download

The FrameWork for building highly scalable and maintainable applications

The newest version!
package tfw.immutable.ila.floatila;

import java.io.IOException;
import tfw.check.Argument;

public final class FloatIlaRemove {
    private FloatIlaRemove() {
        // non-instantiable class
    }

    public static FloatIla create(FloatIla ila, long index) throws IOException {
        Argument.assertNotNull(ila, "ila");
        Argument.assertNotLessThan(index, 0, "index");
        Argument.assertLessThan(index, ila.length(), "index", "ila.length()");

        return new FloatIlaImpl(ila, index);
    }

    private static class FloatIlaImpl extends AbstractFloatIla {
        private final FloatIla ila;
        private final long index;

        private FloatIlaImpl(FloatIla ila, long index) {
            this.ila = ila;
            this.index = index;
        }

        @Override
        protected long lengthImpl() throws IOException {
            return ila.length() - 1;
        }

        @Override
        protected void getImpl(float[] array, int offset, long start, int length) throws IOException {
            final long startPlusLength = start + length;

            if ((index - 1) < start) {
                ila.get(array, offset, start + 1, length);
            } else if ((index + 1) > startPlusLength) {
                ila.get(array, offset, start, length);
            } else {
                final int indexMinusStart = (int) (index - start);
                ila.get(array, offset, start, indexMinusStart);
                ila.get(array, offset + indexMinusStart, index + 1, length - indexMinusStart);
            }
        }
    }
}
// AUTO GENERATED FROM TEMPLATE




© 2015 - 2024 Weber Informatics LLC | Privacy Policy