CPD Results

The following document contains the results of PMD's CPD 7.14.0.

Duplications

File Line
com/irurueta/geometry/io/Loader.java 121
com/irurueta/geometry/io/MaterialLoader.java 140
}

    /**
     * Get maximum size (in bytes) to determine whether a file is completely
     * cached in memory (if lower than maximum size), or if it is just streamed
     * (if greater than maximum size).
     *
     * @return Maximum size to determine whether file is cached in memory or not.
     */
    public long getFileSizeLimitToKeepInMemory() {
        return fileSizeLimitToKeepInMemory;
    }

    /**
     * Sets maximum size (in bytes) to determine whether a file is completely
     * cached in memory (if lower than maximum size), or if it is just streamed
     * (if greater than maximum size).
     *
     * @param fileSizeLimitToKeepInMemory maximum size to determine whether file
     *                                    is cached in memory or not.
     * @throws LockedException if loader is locked because it is currently
     *                         processing a file.
     */
    public void setFileSizeLimitToKeepInMemory(final long fileSizeLimitToKeepInMemory) throws LockedException {
        if (isLocked()) {
            throw new LockedException();
        }

        this.fileSizeLimitToKeepInMemory = fileSizeLimitToKeepInMemory;
    }

    /**
     * Indicates whether a file to be loaded has already been set.
     *
     * @return True if file has already been provided, false otherwise.
     */
    public boolean hasFile() {
        return reader != null;
    }

    /**
     * Sets file to be loaded.
     *
     * @param f file to be loaded.
     * @throws LockedException raised if this instance is loaded because a file
     *                         is already being loaded.
     * @throws IOException     raised if provided file does not exist or if an I/O
     *                         exception occurs.
     */
    @SuppressWarnings("DuplicatedCode")
    public void setFile(final File f) throws LockedException, IOException {
        if (isLocked()) {
            throw new LockedException();
        }
        file = f;

        if (reader != null) {
            // close previous file
            reader.close();
        }

        if (f.length() < fileSizeLimitToKeepInMemory) {
            reader = new MappedFileReaderAndWriter(f, FileChannel.MapMode.READ_ONLY);
        } else {
            reader = new FileReaderAndWriter(f, FileChannel.MapMode.READ_ONLY);
        }
    }

    /**
     * Closes file provided to this loader.
     *
     * @throws IOException if an I/O error occurs.
     */
    @Override
    public void close() throws IOException {
        if (reader != null) {
            reader.close();
            reader = null;
        }
    }

    /**
     * Determines whether this instance is locked.
     * A loader remains locked while decoding of a file is being done.
     * This instance will remain locked once the loading process starts until
     * it finishes either successfully or not.
     * While this instance remains locked no parameters can be changed,
     * otherwise a LockedException will be raised.
     *
     * @return True if instance is locked, false otherwise.
     */
    public synchronized boolean isLocked() {
File Line
com/irurueta/geometry/io/FileReaderAndWriter.java 805
com/irurueta/geometry/io/MappedFileReaderAndWriter.java 821
}

    /**
     * Writes an unsigned int to the file as four bytes, using provided endian
     * type.
     * Provided integer value is converted to an unsigned int by taking into
     * account only the four lower bytes.
     * If endian type is big endian, then natural byte order is preserved (and
     * high byte is written first), if little endian order is chosen, then byte
     * order is reversed.
     * The write starts at the current position of the file pointer.
     *
     * @param v          an unsigned int to be written (long is converted to unsigned
     *                   short).
     * @param endianType endian type. If it is big endian, natural byte order is
     *                   preserved, otherwise byte order is reversed.
     * @throws IOException if an I/O error occurs.
     */
    @Override
    public void writeUnsignedInt(final long v, final EndianType endianType) throws IOException {
        final var firstIntByte = (int) (0xff & (v >> 24));
        final var secondIntByte = (int) (0xff & ((v << 8) >> 24));
        final var thirdIntByte = (int) (0xff & ((v << 16) >> 24));
        final var fourthIntByte = (int) (0xff & ((v << 24) >> 24));

        final var machineValue = (firstIntByte << 24) | (secondIntByte << 16) | (thirdIntByte << 8) | fourthIntByte;
        final var value = Util.toEndianType(endianType, machineValue);

        randomAccessFile.writeInt(value);
File Line
com/irurueta/geometry/io/LoaderOBJ.java 1430
com/irurueta/geometry/io/LoaderOBJ.java 1986
String vertexLine = reader.readLine();
                                    if (!vertexLine.startsWith("v ")) {
                                        throw new LoaderException();
                                    }
                                    vertexLine = vertexLine.substring("v ".length()).trim();
                                    // retrieve words in vertexLine, which contain
                                    // vertex coordinates either as x, y, z or x,
                                    // y, z, w
                                    final var vertexCoordinates = vertexLine.split(" ");
                                    if (vertexCoordinates.length == 4) {
                                        // homogeneous coordinates x, y, z, w

                                        // check that values are valid
                                        if (vertexCoordinates[0].isEmpty()) {
                                            throw new LoaderException();
                                        }
                                        if (vertexCoordinates[1].isEmpty()) {
                                            throw new LoaderException();
                                        }
                                        if (vertexCoordinates[2].isEmpty()) {
                                            throw new LoaderException();
                                        }
                                        if (vertexCoordinates[3].isEmpty()) {
                                            throw new LoaderException();
                                        }
File Line
com/irurueta/geometry/io/LoaderOBJ.java 1688
com/irurueta/geometry/io/LoaderOBJ.java 1762
com/irurueta/geometry/io/LoaderOBJ.java 1836
final var entry = verticesStreamPositionMap.floorEntry(index);
                if (entry != null) {
                    final var origIndex = entry.getKey();
                    final var pos = entry.getValue();
                    if ((origIndex <= index) && (pos >= 0)) {
                        startIndex = origIndex;
                        startStreamPos = pos;
                    }
                }
            }

            // if we need to read next vertex, don't do anything, otherwise
            // move to next vertex location if reading some vertex located
            // further on the stream. For previous vertex indices, start
            // from beginning
            if (reader.getPosition() != startStreamPos) {
                reader.seek(startStreamPos);
            }

            // read from stream until start of data of desired vertex
            var streamPosition = 0L;
            for (var i = startIndex; i <= index; i++) {

                // when traversing stream of data until reaching desired
                // index, we add all vertex, texture and normal positions
                // into maps
                String str;
                var end = false;
                do {
                    streamPosition = reader.getPosition();
                    str = reader.readLine();
                    if (str == null) {
                        end = true;
                        break;
                    }

                    if (str.startsWith("v ")) {
File Line
com/irurueta/geometry/io/FileReaderAndWriter.java 783
com/irurueta/geometry/io/MappedFileReaderAndWriter.java 798
}

    /**
     * Writes an unsigned int to the file as four bytes, high byte first.
     * Provided integer value is converted to an unsigned int by taking into
     * account only the four lower bytes. The write starts at the current
     * position of the file pointer.
     *
     * @param v an unsigned int to be written (long is converted to unsigned
     *          int).
     * @throws IOException if an I/O error occurs.
     */
    @Override
    public void writeUnsignedInt(final long v) throws IOException {
        final var firstIntByte = (int) (0xff & (v >> 24));
        final var secondIntByte = (int) (0xff & ((v << 8) >> 24));
        final var thirdIntByte = (int) (0xff & ((v << 16) >> 24));
        final var fourthIntByte = (int) (0xff & ((v << 24) >> 24));

        final var value = (firstIntByte << 24) | (secondIntByte << 16) | (thirdIntByte << 8) | fourthIntByte;

        randomAccessFile.writeInt(value);
File Line
com/irurueta/geometry/io/MeshWriterBinary.java 129
com/irurueta/geometry/io/MeshWriterJson.java 293
if (chunk.getMinX() < minX) {
                    minX = chunk.getMinX();
                }
                if (chunk.getMinY() < minY) {
                    minY = chunk.getMinY();
                }
                if (chunk.getMinZ() < minZ) {
                    minZ = chunk.getMinZ();
                }

                if (chunk.getMaxX() > maxX) {
                    maxX = chunk.getMaxX();
                }
                if (chunk.getMaxY() > maxY) {
                    maxY = chunk.getMaxY();
                }
                if (chunk.getMaxZ() > maxZ) {
                    maxZ = chunk.getMaxZ();
                }
File Line
com/irurueta/geometry/io/LoaderOBJ.java 647
com/irurueta/geometry/io/LoaderSTL.java 202
}

    /**
     * Determines if provided file is a valid file that can be read by this
     * loader.
     *
     * @return true if file is valid, false otherwise.
     * @throws LockedException raised if this instance is already locked.
     * @throws IOException     if an I/O error occurs..
     */
    @Override
    public boolean isValidFile() throws LockedException, IOException {
        if (!hasFile()) {
            throw new IOException();
        }
        if (isLocked()) {
            throw new LockedException();
        }
        return true;
    }

    /**
     * Starts the loading process of provided file.
     * This method returns a LoaderIterator to start the iterative process to
     * load a file in small chunks of data.
     *
     * @return a loader iterator to read the file in a step-by-step process.
     * @throws LockedException   raised if this instance is already locked.
     * @throws NotReadyException raised if this instance is not yet ready.
     * @throws IOException       if an I/O error occurs.
     * @throws LoaderException   if file is corrupted or cannot be interpreted.
     */
    @Override
    public LoaderIterator load() throws LockedException, NotReadyException, IOException, LoaderException {
        if (isLocked()) {
            throw new LockedException();
        }
        if (!isReady()) {
            throw new NotReadyException();
        }

        setLocked(true);
        if (listener != null) {
            listener.onLoadStart(this);
        }

        loaderIterator = new LoaderIteratorOBJ(this);
File Line
com/irurueta/geometry/io/FileReaderAndWriter.java 442
com/irurueta/geometry/io/MappedFileReaderAndWriter.java 463
final var streamValue = randomAccessFile.readInt();
        final var value = Util.fromEndianType(endianType, streamValue);

        // convert value to byte array
        final var firstIntByte = 0xff & (value >> 24);
        final var secondIntByte = 0xff & ((value << 8) >> 24);
        final var thirdIntByte = 0xff & ((value << 16) >> 24);
        final var fourthIntByte = 0xff & ((value << 24) >> 24);

        // return it as integer
        return ((long) firstIntByte << 24) | (secondIntByte << 16) | (thirdIntByte << 8) | fourthIntByte;
    }

    /**
     * Reads a signed 64-bit integer from this file. This method reads eight
     * bytes from the file, starting at the current file pointer. If the bytes
     * read, in order, are b1, b2, b3, b4, b5, b6, b7, and b8, where:
     * 0 &lt;= b1, b2, b3, b4. b5. b6. b7. b8 &lt;= 255,
     * then the result is equal to:
     * ((long)b1 &lt;&lt; 56) + ((long)b2 &lt;&lt; 48)
     * + ((long)b3 &lt;&lt; 40) + ((long)b4 &lt;&lt; 32)
     * + ((long)b5 &lt;&lt; 24) + ((long)b6 &lt;&lt; 16)
     * + ((long)b7 &lt;&lt; 8) + b8
     * This method blocks until the eight bytes are read, the end of the stream
     * is detected, or an exception is thrown.
     *
     * @return the next eight bytes of this file, interpreted as a long.
     * @throws IOException if an I/O error occurs.
     */
    @Override
    public long readLong() throws IOException {