Java中的磁盘优化扫描算法

Java中的磁盘优化扫描算法,java,Java,我目前正在尝试创建一个名为arrangeBySCAN的方法,该方法接受previous、current和sequence数组的参数。此方法的目的是根据磁盘优化中的扫描格式排列.properties文件的输入 然而,我得到了一个错误: 非法辩论例外 在以下代码行中: int scanArray1[] = Arrays.copyOfRange(tmp, 0, currentIndex); //line 17 我不是一个经验丰富的程序员,任何帮助都将不胜感激 以下是代码 private in

我目前正在尝试创建一个名为arrangeBySCAN的方法,该方法接受previous、current和sequence数组的参数。此方法的目的是根据磁盘优化中的扫描格式排列.properties文件的输入
然而,我得到了一个错误:

非法辩论例外

在以下代码行中:

int scanArray1[] = Arrays.copyOfRange(tmp, 0, currentIndex); //line 17
我不是一个经验丰富的程序员,任何帮助都将不胜感激

以下是代码

    private int[] arrangeBySCAN(int previous, int current, int sequence[]){
        int direction = previous - current;
        int seqLength = sequence.length;
        int tmp[] = new int[seqLength];
        // If direction is less than 0, it is increasing
        // If direction is greater than 0, it is decreasing
        if (direction < 0) {
            Arrays.sort(tmp);
        }
        else if (direction > 0){
            Arrays.sort(tmp);
            Collections.reverse(Arrays.asList(tmp));
        }
        // Find the index position of the current cylinder after sorting
        int currentIndex = Arrays.asList(tmp).indexOf(current);
        // Split the sequence into two parts, taking the index of the current cylinder as reference
        int scanArray1[] = Arrays.copyOfRange(tmp, 0, currentIndex);
        int scanArray2[] = Arrays.copyOfRange(tmp, currentIndex, tmp.length);
        // Reverse first sequence
        Collections.reverse(Arrays.asList(scanArray1));

        // Append the first sequence onto the second sequence
        int scanArray[] = new int[scanArray1.length + scanArray2.length];
        System.arraycopy(scanArray1, 0, scanArray, 0, scanArray1.length);
        System.arraycopy(scanArray2, 0, scanArray, currentIndex ,scanArray2.length);
        return scanArray;
    }
private int[]arrangeBySCAN(int-previous、int-current、int-sequence[]){
int方向=先前-当前;
int seqLength=序列长度;
int tmp[]=新的int[seqLength];
//如果方向小于0,则它将增大
//如果方向大于0,则它将减小
如果(方向<0){
数组排序(tmp);
}
否则,如果(方向>0){
数组排序(tmp);
Collections.reverse(Arrays.asList(tmp));
}
//排序后查找当前圆柱体的索引位置
int currentIndex=Arrays.asList(tmp).indexOf(current);
//将序列分为两部分,以当前圆柱体的索引为参考
int scanArray1[]=Arrays.copyOfRange(tmp,0,currentIndex);
int scanArray2[]=Arrays.copyOfRange(tmp,currentIndex,tmp.length);
//反向第一序列
Collections.reverse(Arrays.asList(scanArray1));
//将第一个序列附加到第二个序列上
int scanArray[]=新的int[scanArray1.length+scanArray2.length];
System.arraycopy(扫描阵列1,0,扫描阵列,0,扫描阵列1.length);
System.arraycopy(scanArray2,0,scanArray,currentIndex,scanArray2.length);
返回扫描阵列;
}

由于
currentIndex
为-1,因此出现
IllegalArgumentException
。您得到的异常很可能有一条消息说“0>-1”
currentIndex
为-1,因为您从未在
tmp
数组中放入任何内容,因此
indexOf
返回-1,除非
current
恰好为0