⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 intarray.java

📁 Sunflow是一个照片级的渲染系统
💻 JAVA
字号:
package org.sunflow.util;

public final class IntArray {
    private int[] array;
    private int size;

    public IntArray() {
        array = new int[10];
        size = 0;
    }

    public IntArray(int capacity) {
        array = new int[capacity];
        size = 0;
    }

    /**
     * Append an integer to the end of the array.
     * 
     * @param i
     */
    public final void add(int i) {
        if (size == array.length) {
            int[] oldArray = array;
            array = new int[(size * 3) / 2 + 1];
            System.arraycopy(oldArray, 0, array, 0, size);
        }
        array[size] = i;
        size++;
    }

    /**
     * Write a value to the specified index. Assumes the array is already big
     * enough.
     * 
     * @param index
     * @param value
     */
    public final void set(int index, int value) {
        array[index] = value;
    }

    /**
     * Read value from the array.
     * 
     * @param index index into the array
     * @return value at the specified index
     */
    public final int get(int index) {
        return array[index];
    }

    /**
     * Returns the number of elements added to the array.
     * 
     * @return current size of the array
     */
    public final int getSize() {
        return size;
    }

    /**
     * Return a copy of the array, trimmed to fit the size of its contents
     * exactly.
     * 
     * @return a new array of exactly the right length
     */
    public final int[] trim() {
        if (size < array.length) {
            int[] oldArray = array;
            array = new int[size];
            System.arraycopy(oldArray, 0, array, 0, size);
        }
        return array;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -