holder.java
来自「一个简单的数据库」· Java 代码 · 共 83 行
JAVA
83 行
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package bufferedManager;/** * * @author outlaw */public class Holder { boolean[] holds; int size; int availableNumber; public Holder(int size) { this.size=size; holds=new boolean[size]; for(int i=0;i<size;i++) holds[i]=false; availableNumber=size; } public int getAvailableNumber() { return availableNumber; } public boolean isFull() { if(getAvailableNumber()==0) return true; return false; } public void setHold(int index) { holds[index]=true; availableNumber--; } public void setNotHold(int index) { holds[index]=false; availableNumber++; } public boolean isHold(int index) { return holds[index]; } public int[] getAvailablePos() { int[] pos=new int[availableNumber]; for(int i=0,j=0;i<size;i++) { if(holds[i]==false) pos[j++]=i; } return pos; } public int[] getNotAvailablePos() { int[] pos=new int[size-availableNumber]; for(int i=0,j=0;i<size;i++) { if(holds[i]) pos[j++]=i; } return pos; } public boolean[] getHolders() { return holds; } public int getFirstAvailablePos() { for(int i=0;i<holds.length;i++) { if(!holds[i]) return i; } return -1; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?