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

📄 booleanexpression.java

📁 PIY(Program It Yourself)是一个基于Java的应用程序开发环境
💻 JAVA
字号:
package piy;

import java.io.Serializable;

/**
* A boolean expression links two BooleanComparable objects together with an AND
* or an OR.  If only one of the objects is non-null, it just returns the other
* expression evaluated.  If both of the objects are null, it returns false;
*
* @author David Vivash
* @version 1.0, 30/4/01
*/
public class BooleanExpression extends BooleanComparable implements Serializable {
	
	public BooleanExpression() {
		setNegate(false);
	}	
	
	//Stores the two things to evaluate
	private BooleanComparable first = null, second = null;
	
	//If the two statements, first and second, should be evaluated with AND, this is set to true
	//If the two statements, first and second, should be evaluated with OR, this is set to false
	private boolean compareWithAnd = true;

	public void setFirst(BooleanComparable first) { this.first = first; }
	public void setSecond(BooleanComparable second) { this.second = second; }

	public BooleanComparable getFirst() { return first; }
	public BooleanComparable getSecond() { return second; }

	public boolean getAnd() { return compareWithAnd; }
	public void setAnd(boolean val) { compareWithAnd = val; }

	public boolean evaluate() {
		if ((first == null) && (second == null)) return false;
				
		if (first == null) return second.evaluate() ^ getNegate();

		if (second == null) return first.evaluate() ^ getNegate();
	
		if (compareWithAnd) return ( first.evaluate() && second.evaluate() ) ^ getNegate();

		return ( first.evaluate() || second.evaluate() ) ^ getNegate();
	}
}

⌨️ 快捷键说明

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