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

📄 cell.java

📁 一款数独游戏的Java源代码
💻 JAVA
字号:
package entity;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import util.CloneUtil;import util.StatusUtil;/** * @author   yangan */public class Cell {	private Value value;	private Point point;	private Status status;	private List<AbstractCells> cellsList;	private List<Value> cellForbidValues;	private List<Value> cellPermitValues;	public Cell(List<Value> originalPermitValue) {		super();		this.status = Status.NoSure;		cellsList = new ArrayList<AbstractCells>();		cellForbidValues = new ArrayList<Value>();		cellPermitValues = new ArrayList<Value>();		CloneUtil.cloneValueList(cellPermitValues, originalPermitValue);	}	/**	 * @return   Returns the cellsList.	 * @uml.property   name="cellsList"	 */	public List<AbstractCells> getCellsList() {		return cellsList;	}	/**	 * @return   Returns the cellForbidValues.	 * @uml.property   name="cellForbidValues"	 */	public List<Value> getCellForbidValues() {		return cellForbidValues;	}	/**	 * @return   Returns the cellPermitValues.	 * @uml.property   name="cellPermitValues"	 */	public List<Value> getCellPermitValues() {		return cellPermitValues;	}	public void addCellsLink(AbstractCells cells) {		this.getCellsList().add(cells);	}	public void addCellPermitValue(Value value) {		this.getCellPermitValues().add(value);	}	public void removeCellPermitValue(Value value) {		this.getCellPermitValues().remove(value);	}	public void addCellForbidValue(Value value) {		this.getCellForbidValues().add(value);	}	/**	 * @return   Returns the point.	 * @uml.property   name="point"	 */	public Point getPoint() {		return point;	}	/**	 * @param point   The point to set.	 * @uml.property   name="point"	 */	public void setPoint(Point point) {		this.point = point;	}	/**	 * @return   Returns the value.	 * @uml.property   name="value"	 */	public Value getValue() {		return value;	}	/**	 * @param value   The value to set.	 * @uml.property   name="value"	 */	public void setValue(Value value) {		this.value = value;	}	/**	 * @return   Returns the status.	 * @uml.property   name="status"	 */	public Status getStatus() {		return status;	}	/**	 * @param status   The status to set.	 * @uml.property   name="status"	 */	public void setStatus(Status status) {		this.status = status;	}	@Override	public boolean equals(Object obj) {		boolean result = false;		Cell _cell;		if (obj == this) {			result = true;		} else {			if (obj instanceof Cell) {				_cell = (Cell) obj;				if ((_cell.getPoint().equals(this.getPoint()))						&& (_cell.getValue().equals(this.getValue()))) {					result = true;				}			}		}		return result;	}	@Override	public int hashCode() {		int result = 31 * this.getPoint().hashCode()				+ this.getValue().hashCode();		return result;	}	private void removePermitValueFromCells() {		if (this.getStatus().equals(Status.Sure)) {			for (Iterator iter = this.getCellsList().iterator(); iter.hasNext();) {				AbstractCells cells = (AbstractCells) iter.next();				cells.removePermitValue(this.getValue());			}		}	}	public void excute() {		List cellsForbidValue;		for (Iterator iter = this.getCellsList().iterator(); iter.hasNext();) {			AbstractCells cells = (AbstractCells) iter.next();			cellsForbidValue = cells.getForbidValues();			for (Iterator iterator = cellsForbidValue.iterator(); iterator					.hasNext();) {				Value element = (Value) iterator.next();				if (!this.getCellForbidValues().contains(element)) {					this.addCellForbidValue(element.cloneMe());				}			}		}//		for (int i = 0; i < this.getCellPermitValues().size(); i++) {//			Value element = (Value) this.getCellPermitValues().get(i);//			if (element != null) {//				if (this.getCellForbidValues().contains(element)) {//					this.getCellPermitValues().remove(element);//				}//			}//		}		for (Iterator iter = this.getCellForbidValues().iterator(); iter				.hasNext();) {			Value element = (Value) iter.next();			if (this.getCellPermitValues().contains(element)) {				this.getCellPermitValues().remove(element);			}		}		if (this.getCellPermitValues().size() == 1) {			for (Iterator iter = this.getCellPermitValues().iterator(); iter					.hasNext();) {				Value element = (Value) iter.next();				this.setSureValue(element);			}		}	}	private void setPermitAndForbidValues() {		List<Value> tempSavePermit = new ArrayList<Value>();		if (this.getStatus().equals(Status.Sure)) {			for (Iterator iter = this.getCellPermitValues().iterator(); iter					.hasNext();) {				Value element = (Value) iter.next();				if (!element.equals(this.getValue())) {					// this.removeCellPermitValue(element);					tempSavePermit.add(element);					this.addCellForbidValue(element);				}			}		}		for (Iterator iter = tempSavePermit.iterator(); iter.hasNext();) {			Value element = (Value) iter.next();			this.getCellPermitValues().remove(element);		}	}	public void setSureValue(String value) {		this.setSureValue(new Value(value));	}	public void setSureValue(Value value) {		this.setValue(value);		this.setStatus(Status.Sure);		this.setPermitAndForbidValues();		this.removePermitValueFromCells();	}	public String toString() {		StringBuffer result = new StringBuffer();		result.append(this.getPoint());		result.append(this.getStatus());		if (StatusUtil.isSure(this)) {			result.append(this.getValue());		} else {			for (Iterator iter = this.getCellPermitValues().iterator(); iter					.hasNext();) {				Value element = (Value) iter.next();				result.append(element.toString());			}		}		return result.toString() + "\n";	}}

⌨️ 快捷键说明

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