java.lang.IndexOutOfBoundsException Java Examples

The following examples show how to use java.lang.IndexOutOfBoundsException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: constructor.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs the test using the specified harness.
 *
 * @param harness  the test harness (<code>null</code> not permitted).
 */
public void test(TestHarness harness)
{
    IndexOutOfBoundsException object1 = new IndexOutOfBoundsException();
    harness.check(object1 != null);
    harness.check(object1.toString(), "java.lang.IndexOutOfBoundsException");

    IndexOutOfBoundsException object2 = new IndexOutOfBoundsException("nothing happens");
    harness.check(object2 != null);
    harness.check(object2.toString(), "java.lang.IndexOutOfBoundsException: nothing happens");

    IndexOutOfBoundsException object3 = new IndexOutOfBoundsException(null);
    harness.check(object3 != null);
    harness.check(object3.toString(), "java.lang.IndexOutOfBoundsException");

}
 
Example #2
Source File: TouchableMovementMethod.java    From SkyTube with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Find the span that was clicked
 *
 * @param widget    view the user clicked
 * @param spannable spannable string inside the clicked view
 * @param event     motion event that occurred
 * @return the touchable span that was pressed
 */
private URLSpan getPressedSpan(TextView widget, Spannable spannable, MotionEvent event) {
    int x = Math.round(event.getX());
    int y = Math.round(event.getY());

    x -= widget.getTotalPaddingLeft();
    y -= widget.getTotalPaddingTop();

    x += widget.getScrollX();
    y += widget.getScrollY();

    Layout layout = widget.getLayout();
    int line = layout.getLineForVertical(y);

    int off;
    try {
        off = layout.getOffsetForHorizontal(line, (float) x);
    } catch (IndexOutOfBoundsException e) {
        return null;
    }

    int end = layout.getLineEnd(line);

    // offset seems like it can be one off in some cases
    // Could be what was causing issue 7 in the first place:
    // https://github.com/klinker24/Android-TextView-LinkBuilder/issues/7
    if (off != end && off != end - 1) {
        URLSpan[] links = spannable.getSpans(off, off, URLSpan.class);

        if (links.length > 0) {
            return links[0];
        }
    }

    return null;
}
 
Example #3
Source File: FastIntBuffer.java    From vtd-xml with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Assigns a new int value to location index of the buffer instance.
 * @param index int
 * @param newValue int
 */
public void modifyEntry(int index, int newValue) {
	
        if (index < 0 || index > size - 1) {
            throw new IndexOutOfBoundsException();
        }

//        ((int[]) bufferArrayList.get((int) (index / pageSize)))[index % pageSize] =
        ((int[]) bufferArrayList.get((index >> exp)))[index & r] =
            newValue;
	
	}
 
Example #4
Source File: FastIntBuffer.java    From vtd-xml with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the int at the location specified by index.
 * @return int
 * @param index int
 */
public int intAt(int index) {
    if (index < 0 || index > size()-1) {
        throw new IndexOutOfBoundsException();
    }
//    int pageNum = (int) index / pageSize;
    int pageNum = index>>exp;
    //System.out.println("page Number is "+pageNum); 
//    int offset = index % pageSize;
    int offset = index & r;
    return ((int[]) bufferArrayList.get(pageNum))[offset];
}
 
Example #5
Source File: FastLongBuffer.java    From vtd-xml with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the upper 32 bit of the long at the index.
 * @return int
 * @param index int
 */
public int upper32At(int index) {
    if (index < 0 || index >= size()) {
        throw new IndexOutOfBoundsException();
    }
    int pageNum = (index >>exp);
    int offset = index & r;
    return (int)
        ((((long[]) bufferArrayList.get(pageNum))[offset] & (0xffffffffL << 32)) >> 32);

}
 
Example #6
Source File: FastLongBuffer.java    From vtd-xml with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Modify the value at the index to a new val.
 * @param index int
 * @param newValue long
 */
public void modifyEntry(int index, long newValue) {

    if (index < 0 || index > size + 1) {
        throw new IndexOutOfBoundsException();
    }
    //((long[]) bufferArrayList.get((int) (index / pageSize)))[index % pageSize] =
    ((long[]) bufferArrayList.get(index >> exp))[index & r] =
        newValue;
}
 
Example #7
Source File: FastLongBuffer.java    From vtd-xml with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the lower 32 bit of the integer at the given index.
 * @return int
 * @param index int
 */
 public int lower32At(int index) {
    if (index < 0 || index > size()) {
        throw new IndexOutOfBoundsException();
    }
    int pageNum =  (index >> exp);
    // int offset = index % pageSize;
    int offset = index & r;
    return (int) ((long[]) bufferArrayList.get(pageNum))[offset];
}
 
Example #8
Source File: FastLongBuffer.java    From vtd-xml with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the long val at given index value.
 * @return long
 * @param index int
 */
public long longAt(int index) {
    if (index < 0 || index > size()) {
        throw new IndexOutOfBoundsException();
    }
    int pageNum = (index >> exp);
    // int offset = index % r;
    int offset = index &r;
    return ((long[]) bufferArrayList.get(pageNum))[offset];
}
 
Example #9
Source File: FastIntBuffer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Assigns a new int value to location index of the buffer instance.
 * @param index int
 * @param newValue int
 */
public void modifyEntry(int index, int newValue) {
	
        if (index < 0 || index > size - 1) {
            throw new IndexOutOfBoundsException();
        }

//        ((int[]) bufferArrayList.get((int) (index / pageSize)))[index % pageSize] =
        ((int[]) bufferArrayList.get((index >> exp)))[index & r] =
            newValue;
	
	}
 
Example #10
Source File: FastIntBuffer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the int at the location specified by index.
 * @return int
 * @param index int
 */
public int intAt(int index) {
    if (index < 0 || index > size()-1) {
        throw new IndexOutOfBoundsException();
    }
//    int pageNum = (int) index / pageSize;
    int pageNum = index>>exp;
    //System.out.println("page Number is "+pageNum); 
//    int offset = index % pageSize;
    int offset = index & r;
    return ((int[]) bufferArrayList.get(pageNum))[offset];
}
 
Example #11
Source File: FastLongBuffer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the upper 32 bit of the long at the index.
 * @return int
 * @param index int
 */
public int upper32At(int index) {
    if (index < 0 || index >= size()) {
        throw new IndexOutOfBoundsException();
    }
    int pageNum = (index >>exp);
    int offset = index & r;
    return (int)
        ((((long[]) bufferArrayList.get(pageNum))[offset] & (0xffffffffL << 32)) >> 32);

}
 
Example #12
Source File: FastLongBuffer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Modify the value at the index to a new val.
 * @param index int
 * @param newValue long
 */
public void modifyEntry(int index, long newValue) {

    if (index < 0 || index > size + 1) {
        throw new IndexOutOfBoundsException();
    }
    //((long[]) bufferArrayList.get((int) (index / pageSize)))[index % pageSize] =
    ((long[]) bufferArrayList.get(index >> exp))[index & r] =
        newValue;
}
 
Example #13
Source File: FastLongBuffer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the lower 32 bit of the integer at the given index.
 * @return int
 * @param index int
 */
 public int lower32At(int index) {
    if (index < 0 || index > size()) {
        throw new IndexOutOfBoundsException();
    }
    int pageNum =  (index >> exp);
    // int offset = index % pageSize;
    int offset = index & r;
    return (int) ((long[]) bufferArrayList.get(pageNum))[offset];
}
 
Example #14
Source File: FastLongBuffer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the long val at given index value.
 * @return long
 * @param index int
 */
public long longAt(int index) {
    if (index < 0 || index > size()) {
        throw new IndexOutOfBoundsException();
    }
    int pageNum = (index >> exp);
    // int offset = index % r;
    int offset = index &r;
    return ((long[]) bufferArrayList.get(pageNum))[offset];
}
 
Example #15
Source File: FastLongBuffer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the lower 32 bit of the integer at the given index.
 * @return int
 * @param index int
 */
 public int lower32At(int index) {
    if (index < 0 || index > size()) {
        throw new IndexOutOfBoundsException();
    }
    int pageNum =  (index >> exp);
    // int offset = index % pageSize;
    int offset = index & r;
    return (int) ((long[]) bufferArrayList.get(pageNum))[offset];
}
 
Example #16
Source File: ParsingTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void checkIndexOutOfBoundsException(String val, int start, int end, int radix) {
    int n = 0;
    try {
        n = Integer.parseInt(val, start, end, radix);
        System.err.println("parseInt(" + val + ", " + start + ", " + end + ", " + radix  +
                ") incorrectly returned " + n);
        throw new RuntimeException();
    } catch (IndexOutOfBoundsException ioob) {
        ; // Expected
    }
}
 
Example #17
Source File: FastLongBuffer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the long val at given index value.
 * @return long
 * @param index int
 */
public long longAt(int index) {
    if (index < 0 || index > size()) {
        throw new IndexOutOfBoundsException();
    }
    int pageNum = (index >> exp);
    // int offset = index % r;
    int offset = index &r;
    return ((long[]) bufferArrayList.get(pageNum))[offset];
}
 
Example #18
Source File: TryCatch.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Runs the test using the specified harness.
 *
 * @param harness  the test harness (<code>null</code> not permitted).
 */
public void test(TestHarness harness)
{
    // flag that is set when exception is caught
    boolean caught = false;
    try {
        throw new IndexOutOfBoundsException("IndexOutOfBoundsException");
    }
    catch (IndexOutOfBoundsException e) {
        // correct exception was caught
        caught = true;
    }
    harness.check(caught);
}
 
Example #19
Source File: FastLongBuffer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Modify the value at the index to a new val.
 * @param index int
 * @param newValue long
 */
public void modifyEntry(int index, long newValue) {

    if (index < 0 || index > size + 1) {
        throw new IndexOutOfBoundsException();
    }
    //((long[]) bufferArrayList.get((int) (index / pageSize)))[index % pageSize] =
    ((long[]) bufferArrayList.get(index >> exp))[index & r] =
        newValue;
}
 
Example #20
Source File: FastLongBuffer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the upper 32 bit of the long at the index.
 * @return int
 * @param index int
 */
public int upper32At(int index) {
    if (index < 0 || index >= size()) {
        throw new IndexOutOfBoundsException();
    }
    int pageNum = (index >>exp);
    int offset = index & r;
    return (int)
        ((((long[]) bufferArrayList.get(pageNum))[offset] & (0xffffffffL << 32)) >> 32);

}
 
Example #21
Source File: FastIntBuffer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the int at the location specified by index.
 * @return int
 * @param index int
 */
public int intAt(int index) {
    if (index < 0 || index > size()-1) {
        throw new IndexOutOfBoundsException();
    }
//    int pageNum = (int) index / pageSize;
    int pageNum = index>>exp;
    //System.out.println("page Number is "+pageNum); 
//    int offset = index % pageSize;
    int offset = index & r;
    return ((int[]) bufferArrayList.get(pageNum))[offset];
}
 
Example #22
Source File: FastIntBuffer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Assigns a new int value to location index of the buffer instance.
 * @param index int
 * @param newValue int
 */
public void modifyEntry(int index, int newValue) {
	
        if (index < 0 || index > size - 1) {
            throw new IndexOutOfBoundsException();
        }

//        ((int[]) bufferArrayList.get((int) (index / pageSize)))[index % pageSize] =
        ((int[]) bufferArrayList.get((index >> exp)))[index & r] =
            newValue;
	
	}
 
Example #23
Source File: FastIntBuffer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a single int array representing every int in this buffer instance
 * @return int[]  (null if there isn't anything left in the buffer   
 * @param startingOffset int
 * @param len int
 * @return int[]
 */
public int[] getIntArray(int startingOffset, int len) {
    if (size <= 0 || startingOffset < 0) {
        throw (new IllegalArgumentException());
    }
    if ((startingOffset + len) > size()) {
        throw (new IndexOutOfBoundsException());
    }
    int[] result = new int[len]; // allocate result array

//    int first_index = (int) (startingOffset / pageSize);
//    int last_index = (int) ((startingOffset + len) / pageSize);
//    if ((startingOffset + len) % pageSize == 0) {
//        last_index--;
//    }
    int first_index = startingOffset >> exp;
    int last_index = (startingOffset + len)>> exp;
    if (((startingOffset + len) & r) == 0) {
        last_index--;
    }

    if (first_index == last_index) {
        // to see if there is a need to go across buffer boundry
        System.arraycopy(
            (int[]) (bufferArrayList.get(first_index)),
//            startingOffset % pageSize,
            startingOffset & r,
            result,
            0,
            len);
    } else {
        int int_array_offset = 0;
        for (int i = first_index; i <= last_index; i++) {
            int[] currentChunk = (int[]) bufferArrayList.get(i);
            if (i == first_index) // first section
                {
                System.arraycopy(
                    currentChunk,
//                  startingOffset % pageSize,
                    startingOffset & r,
                    result,
                    0,
//                  pageSize - (startingOffset % pageSize));
                    pageSize - (startingOffset & r));
//                int_array_offset += pageSize - (startingOffset) % pageSize;
                int_array_offset += pageSize - (startingOffset & r);
            } else if (i == last_index) // last sections
                {
                System.arraycopy(
                    currentChunk,
                    0,
                    result,
                    int_array_offset,
                    len - int_array_offset);

            } else {
                System.arraycopy(currentChunk, 0, result, int_array_offset, pageSize);
                int_array_offset += pageSize;
            }
        }
    }
    return result;
}
 
Example #24
Source File: FastIntBuffer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a single int array representing every int in this buffer instance
 * @return int[]  (null if there isn't anything left in the buffer   
 * @param startingOffset int
 * @param len int
 * @return int[]
 */
public int[] getIntArray(int startingOffset, int len) {
    if (size <= 0 || startingOffset < 0) {
        throw (new IllegalArgumentException());
    }
    if ((startingOffset + len) > size()) {
        throw (new IndexOutOfBoundsException());
    }
    int[] result = new int[len]; // allocate result array

//    int first_index = (int) (startingOffset / pageSize);
//    int last_index = (int) ((startingOffset + len) / pageSize);
//    if ((startingOffset + len) % pageSize == 0) {
//        last_index--;
//    }
    int first_index = startingOffset >> exp;
    int last_index = (startingOffset + len)>> exp;
    if (((startingOffset + len) & r) == 0) {
        last_index--;
    }

    if (first_index == last_index) {
        // to see if there is a need to go across buffer boundry
        System.arraycopy(
            (int[]) (bufferArrayList.get(first_index)),
//            startingOffset % pageSize,
            startingOffset & r,
            result,
            0,
            len);
    } else {
        int int_array_offset = 0;
        for (int i = first_index; i <= last_index; i++) {
            int[] currentChunk = (int[]) bufferArrayList.get(i);
            if (i == first_index) // first section
                {
                System.arraycopy(
                    currentChunk,
//                  startingOffset % pageSize,
                    startingOffset & r,
                    result,
                    0,
//                  pageSize - (startingOffset % pageSize));
                    pageSize - (startingOffset & r));
//                int_array_offset += pageSize - (startingOffset) % pageSize;
                int_array_offset += pageSize - (startingOffset & r);
            } else if (i == last_index) // last sections
                {
                System.arraycopy(
                    currentChunk,
                    0,
                    result,
                    int_array_offset,
                    len - int_array_offset);

            } else {
                System.arraycopy(currentChunk, 0, result, int_array_offset, pageSize);
                int_array_offset += pageSize;
            }
        }
    }
    return result;
}
 
Example #25
Source File: FastLongBuffer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return a selected chuck of long buffer as a long array.
 * @return long[]
 * @param startingOffset int
 * @param len int
 */
public long[] getLongArray(int startingOffset, int len) {
    if (size <= 0 || startingOffset < 0) {
        throw (new IllegalArgumentException());
    }
    if ((startingOffset + len) > size()) {
        throw (new IndexOutOfBoundsException());
    }

    long[] result = new long[len]; // allocate result array

    int first_index =  (startingOffset >> exp);
    int last_index = ((startingOffset + len) >>exp);

    //if ((startingOffset + len) % pageSize == 0) {
    if (((startingOffset + len) & r) == 0) {
        last_index--;
    }

    if (first_index == last_index) {
        // to see if there is a need to go across buffer boundry
        System.arraycopy(
            (long[]) (bufferArrayList.get(first_index)),
//            startingOffset % pageSize,
			startingOffset & r,
            result,
            0,
            len);
    } else {
        int long_array_offset = 0;
        for (int i = first_index; i <= last_index; i++) {
            long[] currentChunk = (long[]) bufferArrayList.get(i);
            if (i == first_index) // first section
                {
                System.arraycopy(
                    currentChunk,
//                  startingOffset % pageSize,
        			startingOffset & r,
                    result,
                    0,
//                  pageSize - (startingOffset % r));
					pageSize - (startingOffset & r));
                long_array_offset += pageSize - (startingOffset & r);
            } else if (i == last_index) // last sections
                {
                System.arraycopy(
                    currentChunk,
                    0,
                    result,
                    long_array_offset,
                    len - long_array_offset);

            } else {
                System.arraycopy(currentChunk, 0, result, long_array_offset, pageSize);
                long_array_offset += pageSize;
            }
        }
    }

    return result;
}
 
Example #26
Source File: FastLongBuffer.java    From vtd-xml with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return a selected chuck of long buffer as a long array.
 * @return long[]
 * @param startingOffset int
 * @param len int
 */
public long[] getLongArray(int startingOffset, int len) {
    if (size <= 0 || startingOffset < 0) {
        throw (new IllegalArgumentException());
    }
    if ((startingOffset + len) > size) {
        throw (new IndexOutOfBoundsException());
    }

    long[] result = new long[len]; // allocate result array

    int first_index =  (startingOffset >> exp);
    int last_index = ((startingOffset + len) >>exp);

    //if ((startingOffset + len) % pageSize == 0) {
    if (((startingOffset + len) & r) == 0) {
        last_index--;
    }

    if (first_index == last_index) {
        // to see if there is a need to go across buffer boundry
        System.arraycopy(
            (long[]) (bufferArrayList.oa[first_index]),
//            startingOffset % pageSize,
			startingOffset & r,
            result,
            0,
            len);
    } else {
        int long_array_offset = 0;
        for (int i = first_index; i <= last_index; i++) {
            long[] currentChunk = (long[]) bufferArrayList.oa[i];
            if (i == first_index) // first section
                {
                System.arraycopy(
                    currentChunk,
//                  startingOffset % pageSize,
        			startingOffset & r,
                    result,
                    0,
//                  pageSize - (startingOffset % r));
					pageSize - (startingOffset & r));
                long_array_offset += pageSize - (startingOffset & r);
            } else if (i == last_index) // last sections
                {
                System.arraycopy(
                    currentChunk,
                    0,
                    result,
                    long_array_offset,
                    len - long_array_offset);

            } else {
                System.arraycopy(currentChunk, 0, result, long_array_offset, pageSize);
                long_array_offset += pageSize;
            }
        }
    }

    return result;
}
 
Example #27
Source File: FastIntBuffer.java    From vtd-xml with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a single int array representing every int in this buffer instance
 * @return int[]  (null if there isn't anything left in the buffer   
 * @param startingOffset int
 * @param len int
 * @return int[]
 */
public int[] getIntArray(int startingOffset, int len) {
    if (size <= 0 || startingOffset < 0) {
        throw (new IllegalArgumentException());
    }
    if ((startingOffset + len) > size) {
        throw (new IndexOutOfBoundsException());
    }
    int[] result = new int[len]; // allocate result array

//    int first_index = (int) (startingOffset / pageSize);
//    int last_index = (int) ((startingOffset + len) / pageSize);
//    if ((startingOffset + len) % pageSize == 0) {
//        last_index--;
//    }
    int first_index = startingOffset >> exp;
    int last_index = (startingOffset + len)>> exp;
    if (((startingOffset + len) & r) == 0) {
        last_index--;
    }

    if (first_index == last_index) {
        // to see if there is a need to go across buffer boundry
        System.arraycopy(
            (int[]) (bufferArrayList.get(first_index)),
//            startingOffset % pageSize,
            startingOffset & r,
            result,
            0,
            len);
    } else {
        int int_array_offset = 0;
        for (int i = first_index; i <= last_index; i++) {
            int[] currentChunk = (int[]) bufferArrayList.get(i);
            if (i == first_index) // first section
                {
                System.arraycopy(
                    currentChunk,
//                  startingOffset % pageSize,
                    startingOffset & r,
                    result,
                    0,
//                  pageSize - (startingOffset % pageSize));
                    pageSize - (startingOffset & r));
//                int_array_offset += pageSize - (startingOffset) % pageSize;
                int_array_offset += pageSize - (startingOffset & r);
            } else if (i == last_index) // last sections
                {
                System.arraycopy(
                    currentChunk,
                    0,
                    result,
                    int_array_offset,
                    len - int_array_offset);

            } else {
                System.arraycopy(currentChunk, 0, result, int_array_offset, pageSize);
                int_array_offset += pageSize;
            }
        }
    }
    return result;
}
 
Example #28
Source File: FastLongBuffer.java    From vtd-xml with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return a selected chuck of long buffer as a long array.
 * @return long[]
 * @param startingOffset int
 * @param len int
 */
public long[] getLongArray(int startingOffset, int len) {
    if (size <= 0 || startingOffset < 0) {
        throw (new IllegalArgumentException());
    }
    if ((startingOffset + len) > size()) {
        throw (new IndexOutOfBoundsException());
    }

    long[] result = new long[len]; // allocate result array

    int first_index =  (startingOffset >> exp);
    int last_index = ((startingOffset + len) >>exp);

    //if ((startingOffset + len) % pageSize == 0) {
    if (((startingOffset + len) & r) == 0) {
        last_index--;
    }

    if (first_index == last_index) {
        // to see if there is a need to go across buffer boundry
        System.arraycopy(
            (long[]) (bufferArrayList.get(first_index)),
//            startingOffset % pageSize,
			startingOffset & r,
            result,
            0,
            len);
    } else {
        int long_array_offset = 0;
        for (int i = first_index; i <= last_index; i++) {
            long[] currentChunk = (long[]) bufferArrayList.get(i);
            if (i == first_index) // first section
                {
                System.arraycopy(
                    currentChunk,
//                  startingOffset % pageSize,
        			startingOffset & r,
                    result,
                    0,
//                  pageSize - (startingOffset % r));
					pageSize - (startingOffset & r));
                long_array_offset += pageSize - (startingOffset & r);
            } else if (i == last_index) // last sections
                {
                System.arraycopy(
                    currentChunk,
                    0,
                    result,
                    long_array_offset,
                    len - long_array_offset);

            } else {
                System.arraycopy(currentChunk, 0, result, long_array_offset, pageSize);
                long_array_offset += pageSize;
            }
        }
    }

    return result;
}
 
Example #29
Source File: FastIntBuffer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a single int array representing every int in this buffer instance
 * @return int[]  (null if there isn't anything left in the buffer   
 * @param startingOffset int
 * @param len int
 * @return int[]
 */
public int[] getIntArray(int startingOffset, int len) {
    if (size <= 0 || startingOffset < 0) {
        throw (new IllegalArgumentException());
    }
    if ((startingOffset + len) > size) {
        throw (new IndexOutOfBoundsException());
    }
    int[] result = new int[len]; // allocate result array

//    int first_index = (int) (startingOffset / pageSize);
//    int last_index = (int) ((startingOffset + len) / pageSize);
//    if ((startingOffset + len) % pageSize == 0) {
//        last_index--;
//    }
    int first_index = startingOffset >> exp;
    int last_index = (startingOffset + len)>> exp;
    if (((startingOffset + len) & r) == 0) {
        last_index--;
    }

    if (first_index == last_index) {
        // to see if there is a need to go across buffer boundry
        System.arraycopy(
            (int[]) (bufferArrayList.get(first_index)),
//            startingOffset % pageSize,
            startingOffset & r,
            result,
            0,
            len);
    } else {
        int int_array_offset = 0;
        for (int i = first_index; i <= last_index; i++) {
            int[] currentChunk = (int[]) bufferArrayList.get(i);
            if (i == first_index) // first section
                {
                System.arraycopy(
                    currentChunk,
//                  startingOffset % pageSize,
                    startingOffset & r,
                    result,
                    0,
//                  pageSize - (startingOffset % pageSize));
                    pageSize - (startingOffset & r));
//                int_array_offset += pageSize - (startingOffset) % pageSize;
                int_array_offset += pageSize - (startingOffset & r);
            } else if (i == last_index) // last sections
                {
                System.arraycopy(
                    currentChunk,
                    0,
                    result,
                    int_array_offset,
                    len - int_array_offset);

            } else {
                System.arraycopy(currentChunk, 0, result, int_array_offset, pageSize);
                int_array_offset += pageSize;
            }
        }
    }
    return result;
}
 
Example #30
Source File: FastLongBuffer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return a selected chuck of long buffer as a long array.
 * @return long[]
 * @param startingOffset int
 * @param len int
 */
public long[] getLongArray(int startingOffset, int len) {
    if (size <= 0 || startingOffset < 0) {
        throw (new IllegalArgumentException());
    }
    if ((startingOffset + len) > size()) {
        throw (new IndexOutOfBoundsException());
    }

    long[] result = new long[len]; // allocate result array

    int first_index =  (startingOffset >> exp);
    int last_index = ((startingOffset + len) >>exp);

    //if ((startingOffset + len) % pageSize == 0) {
    if (((startingOffset + len) & r) == 0) {
        last_index--;
    }

    if (first_index == last_index) {
        // to see if there is a need to go across buffer boundry
        System.arraycopy(
            (long[]) (bufferArrayList.get(first_index)),
//            startingOffset % pageSize,
			startingOffset & r,
            result,
            0,
            len);
    } else {
        int long_array_offset = 0;
        for (int i = first_index; i <= last_index; i++) {
            long[] currentChunk = (long[]) bufferArrayList.get(i);
            if (i == first_index) // first section
                {
                System.arraycopy(
                    currentChunk,
//                  startingOffset % pageSize,
        			startingOffset & r,
                    result,
                    0,
//                  pageSize - (startingOffset % r));
					pageSize - (startingOffset & r));
                long_array_offset += pageSize - (startingOffset & r);
            } else if (i == last_index) // last sections
                {
                System.arraycopy(
                    currentChunk,
                    0,
                    result,
                    long_array_offset,
                    len - long_array_offset);

            } else {
                System.arraycopy(currentChunk, 0, result, long_array_offset, pageSize);
                long_array_offset += pageSize;
            }
        }
    }

    return result;
}