Language agnostic 具有状态的谓词的适当术语
谓词(一个布尔值函数的对象,用于测试其输入的条件)通常被认为是无状态的 对于具有状态测试功能的对象,最合适的名称是什么? e、 g.在Java中,下面的Language agnostic 具有状态的谓词的适当术语,language-agnostic,vocabulary,Language Agnostic,Vocabulary,谓词(一个布尔值函数的对象,用于测试其输入的条件)通常被认为是无状态的 对于具有状态测试功能的对象,最合适的名称是什么? e、 g.在Java中,下面的CountTrigger类仅在第n次根据与所需值匹配的值进行测试时返回true,否则返回false interface QuasiPredicate<T> // what should this be renamed to? { public boolean test(T value); } class Cou
CountTrigger
类仅在第n次根据与所需值匹配的值进行测试时返回true,否则返回false
interface QuasiPredicate<T> // what should this be renamed to?
{
public boolean test(T value);
}
class CountTrigger<T> implements QuasiPredicate<T>
{
// for simplicity, ignore synchronization + null-value issues
private int remainingTriggers = 0;
final private T testValue;
public CountTrigger(T testValue, int count)
{
this.remainingTriggers = count;
this.testValue = testValue;
}
@Override public boolean test(T value)
{
if (!this.testValue.equals(value))
return false;
if (this.remainingTriggers == 0)
return false;
if (--this.remainingTriggers == 0)
return true;
}
}
interface QuasiPredicate//应该将其重命名为什么?
{
公共布尔检验(T值);
}
类CountTrigger实现准预测
{
//为简单起见,请忽略同步+空值问题
private int remainingTriggers=0;
最终私有T测试值;
公共计数触发器(T测试值,int计数)
{
this.remainingTriggers=count;
this.testValue=testValue;
}
@覆盖公共布尔测试(T值)
{
如果(!this.testValue.equals(value))
返回false;
if(this.remainingTriggers==0)
返回false;
如果(--this.remainingTriggers==0)
返回true;
}
}
考虑到它是一个接口,并且接口是实现的
而不是扩展的
,那么我看不出对象实现谓词的问题
如果要将
public CountTrigger(T testValue,int count)
也放在接口中,那么可能需要一个不同的名称。也许是IFiniteRule或另一个合适的同义词。可以问;-) 考虑到它是一个接口,并且接口是实现的
而不是扩展的
,那么我看不出对象实现谓词的问题
如果要将
public CountTrigger(T testValue,int count)
也放在接口中,那么可能需要一个不同的名称。也许是IFiniteRule或另一个合适的同义词。可以问;-) FWIW,我会完全避免使用“谓词”这个名称。我同意,这就是我问的原因。:-)预状态如何?;)FWIW,我会完全避免使用“谓词”这个名称。我同意,这就是我问的原因。:-)预状态如何?;)