indexrecord.java

来自「Disk simulation program. Simulates file-」· Java 代码 · 共 61 行

JAVA
61
字号
public class IndexRecord
{
    public static final int SECTOR_NUMBER_LENGTH = 7;
    private int keyLength;
    private char[] key;
    private char[] sectorNumber;

    public IndexRecord(int keyLength, char[] data)
    {
        this.keyLength = keyLength;
        this.key = new char[this.keyLength];
        this.sectorNumber = new char[SECTOR_NUMBER_LENGTH];

        System.arraycopy(data, 0, this.key, 0, this.keyLength);
        System.arraycopy(data, this.keyLength, this.sectorNumber, 0, SECTOR_NUMBER_LENGTH);

        this.key[this.keyLength - 1] = '\0';
        this.sectorNumber[this.sectorNumber.length - 1] = '\0';

    }

    public IndexRecord(int keyLength, char[] key, char[] sectorNumber)
    {
        this.keyLength = keyLength;
        this.key = new char[this.keyLength];
        this.sectorNumber = new char[SECTOR_NUMBER_LENGTH];
        System.arraycopy(key, 0, this.key, 0, Math.min(this.keyLength, key.length));
        System.arraycopy(sectorNumber, 0, this.sectorNumber, 0, Math.min(SECTOR_NUMBER_LENGTH, sectorNumber.length));
        this.key[this.keyLength - 1] = '\0';
        this.sectorNumber[this.sectorNumber.length - 1] = '\0';
    }

    public char[] getKey()
    {
        return key;
    }

    public void setKey(char[] key)
    {
        this.key = key;
    }

    public char[] getSectorNumber()
    {
        return sectorNumber;
    }

    public void setSectorNumber(char[] sectorNumber)
    {
        this.sectorNumber = sectorNumber;
    }

    public char[] getData()
    {
        char[] data = new char[this.keyLength + SECTOR_NUMBER_LENGTH];
        System.arraycopy(this.key, 0, data, 0, this.keyLength);
        System.arraycopy(this.sectorNumber, 0, data, this.keyLength, SECTOR_NUMBER_LENGTH);
        return data;
    }
}

⌨️ 快捷键说明

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