📄 abstractpolicy.java
字号:
package entity;import java.util.ArrayList;import java.util.List;import cells.BlockCells;import cells.HorizonCells;import cells.VerticalCells;/** * @author yangan */public abstract class AbstractPolicy { private List<Value> originalValues; private List<AbstractCells> allCells; private List<Cell> allCellList; private String[] valueAll = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g" }; public AbstractPolicy() { super(); this.allCells = new ArrayList<AbstractCells>(); this.originalValues = new ArrayList<Value>(); this.allCellList = new ArrayList<Cell>(); this.initOriginal(); this.initAllCellList(); this.initAllCells(); } /** * @return Returns the originalValues. * @uml.property name="originalValues" */ public List<Value> getOriginalValues() { return originalValues; } /** * @return Returns the allCellList. * @uml.property name="allCellList" */ public List<Cell> getAllCellList() { return allCellList; } /** * @return Returns the allCells. * @uml.property name="allCells" */ public List<AbstractCells> getAllCells() { return allCells; } public void addCells(AbstractCells cells) { this.getAllCells().add(cells); } public void excute() { for (Cell cell : this.getAllCellList()) { cell.excute(); } for (AbstractCells cells : this.getAllCells()) { cells.excute(); } } public void initAllCells() { this.initHCells(); this.initVCells(); this.initBlockCells(); } public void initOriginal() { Value value; for (int i = 1; i <= this.getValueRange(); i++) { value = new Value(this.valueAll[i - 1]); originalValues.add(value); } } public boolean setValueByIndex(int xIndex, int yIndex, String value) { for (Cell element : this.getAllCellList()) { if ((element.getPoint().getXIndex() == xIndex) && (element.getPoint().getYIndex() == yIndex)) { element.setSureValue(value); return true; } } return false; } public void initAllCellList() { Point point; Cell cell; for (int i = 0; i < this.getValueRange(); i++) { for (int j = 0; j < this.getValueRange(); j++) { point = new Point(i, j); cell = new Cell(this.originalValues); cell.setPoint(point); this.getAllCellList().add(cell); } } } private void initHCells() { AbstractCells hCells; int temp = this.getValueRange(); for (int i = 0; i < temp; i++) { hCells = new HorizonCells(new Point(i, 0), new Point(i, temp - 1), this.getOriginalValues()); hCells.initAllCellByBeginAndEnd(this.getAllCellList()); this.addCells(hCells); } } private void initVCells() { AbstractCells vCells; int temp = this.getValueRange(); for (int i = 0; i < temp; i++) { vCells = new VerticalCells(new Point(0, i), new Point(temp - 1, i), this.getOriginalValues()); vCells.initAllCellByBeginAndEnd(this.getAllCellList()); this.addCells(vCells); } } protected void initBlockCells() { AbstractCells bCells; int range = this.getValueRange(); int step = this.getStep(); int increase = this.getIncrease(); for (int i = 0; i < range; i = i + increase) { for (int j = 0; j < range; j = j + increase) { bCells = new BlockCells(new Point(i, j), new Point(i + step, j + step), this.getOriginalValues()); bCells.initAllCellByBeginAndEnd(this.getAllCellList()); this.addCells(bCells); } } } protected abstract int getValueRange(); protected abstract int getIncrease(); protected abstract int getStep(); public String toString() { StringBuffer result = new StringBuffer(); for (Cell element : this.getAllCellList()) { result.append(element); } return result.toString(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -