Java Assert assertBounds(final long reqOff, final long reqLen, final long allocSize)

Here you can find the source of assertBounds(final long reqOff, final long reqLen, final long allocSize)

Description

Perform bounds checking using java assert (if enabled) checking the requested offset and length against the allocated size.

License

Apache License

Parameter

Parameter Description
reqOff the requested offset
reqLen the requested length
allocSize the allocated size.

Declaration

static void assertBounds(final long reqOff, final long reqLen, final long allocSize) 

Method Source Code

//package com.java2s;
/*/*from   ww w.  ja v a 2  s . c  o m*/
 * Copyright 2015, Yahoo! Inc.
 * Licensed under the terms of the Apache License 2.0. See LICENSE file at the project root for terms.
 */

public class Main {
    /**
     * Perform bounds checking using java assert (if enabled) checking the requested offset and length 
     * against the allocated size. If any of the parameters are negative the assert will be thrown. 
     * @param reqOff the requested offset
     * @param reqLen the requested length
     * @param allocSize the allocated size. 
     */
    static void assertBounds(final long reqOff, final long reqLen, final long allocSize) {
        assert ((reqOff | reqLen | (reqOff + reqLen) | (allocSize - (reqOff + reqLen))) >= 0) : "offset: " + reqOff
                + ", reqLength: " + reqLen + ", size: " + allocSize;
    }
}

Related

  1. assertArrayIndex(int arrayLength, int offset, int length)
  2. assertArrayIndexScale(final String name, int actualIndexScale, int expectedIndexScale)
  3. assertArrayType(Object array)
  4. assertAssertionsEnabled()
  5. assertAttributeNameIsLegal(final String attributeName)
  6. assertByThrowing(boolean condition, String errorMessage)
  7. assertCharactersNotInString(final String illegalChars, final char... chars)
  8. assertCheckStrAndQuery(String str, String query)
  9. assertClassDoesNotExist(String className)