sdr 0.7

net.cscott.sdr.calls
Class PredicateList

java.lang.Object
  extended by net.cscott.sdr.calls.PredicateList

public abstract class PredicateList
extends Object

This class contains all the predicates known to the system.


Field Summary
static Predicate ALL
          Check that all dancers have the specified tag.
static Predicate AND
          Short-circuit boolean conjunction.
static Predicate ARE
          Check that the tagged dancers also have some other tag.
static Predicate BREAKPOINT
          Another synonym for TRUE, used to set breakpoints during debugging.
static Predicate EQUAL_CALL
          Check the identify of a call provided as an argument.
static Predicate EQUAL_NUM
          Numerical equality.
static Predicate EQUAL_STR
          Case-insensitive string equality.
static Predicate FALSE
          Always false.
static Predicate FORMATION
          Check that the current dance state matches the specified formation (actually Matcher).
static Predicate GREATER
          Numerical "greater than" comparison.
static Predicate LESS
          Numerical "less than" comparison.
static Predicate MATCH
          Case-insensitive regular expression string match.
static Predicate NOT
          Boolean negation.
static Predicate OR
          Short-circuit boolean disjunction.
static Predicate PROGRAM_AT_LEAST
          Check the current dance program level.
static Predicate TBONED
          Check whether the tagged dancers are t-boned.
static Predicate TRUE
          Always true.
 
Constructor Summary
PredicateList()
           
 
Method Summary
static Predicate valueOf(String s)
          Return the Predicate function with the given (case-insensitive) name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRUE

public static final Predicate TRUE
Always true.

Tests:
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.SQUARED_SET); undefined;
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf('(Expr true)');
(Expr true)
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
true

FALSE

public static final Predicate FALSE
Always false.

Tests:
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.SQUARED_SET); undefined;
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf('(Expr false)');
(Expr false)
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
false

BREAKPOINT

public static final Predicate BREAKPOINT
Another synonym for TRUE, used to set breakpoints during debugging.


NOT

public static final Predicate NOT
Boolean negation.

Tests:
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.SQUARED_SET); undefined;
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf('(Expr not (Expr false))');
(Expr not (Expr false))
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
true
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf('(Expr not (Expr true))');
(Expr not (Expr true))
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
false

EQUAL_NUM

public static final Predicate EQUAL_NUM
Numerical equality.

Tests:
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.SQUARED_SET); undefined;
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf('(Expr equal num \'"1 1/2" \'1 1/2)');
(Expr equal num '1 1/2 '1 1/2)
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
true
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf('(Expr equal num \'"1 1/2" \'2)');
(Expr equal num '1 1/2 '2)
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
false

GREATER

public static final Predicate GREATER
Numerical "greater than" comparison.

Tests:
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.SQUARED_SET); undefined;
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf('(Expr greater \'"1 1/2" \'"1 1/2")');
(Expr greater '1 1/2 '1 1/2)
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
false
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr greater '2 '1 1/2)");
(Expr greater '2 '1 1/2)
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
true

LESS

public static final Predicate LESS
Numerical "less than" comparison.

Tests:
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.SQUARED_SET); undefined;
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf('(Expr less \'"1 1/2" \'"1 1/2")');
(Expr less '1 1/2 '1 1/2)
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
false
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr less '1 1/2 '2)");
(Expr less '1 1/2 '2)
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
true

EQUAL_STR

public static final Predicate EQUAL_STR
Case-insensitive string equality.

Tests:
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.SQUARED_SET); undefined;
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf('(Expr equal str \'"abc" \'ABC)');
(Expr equal str 'abc 'ABC)
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
true
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf('(Expr equal str \'"abc" \'xyz)');
(Expr equal str 'abc 'xyz)
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
false

MATCH

public static final Predicate MATCH
Case-insensitive regular expression string match.

Tests:
js> ds = new DanceState(new DanceProgram(Program.PLUS), Formation.SQUARED_SET); undefined;
js> function test(str, pat) {
  >   let c = net.cscott.sdr.calls.ast.AstNode.valueOf(
  >           "(Expr MATCH '"+str+" '\""+pat+"\")");
  >    return PredicateList.valueOf(c.atom).evaluate(ds, c.args)
  > }
js> test('ABC', 'DEF')
false
js> test('BOY', 'BOY')
true
js> // match is case-insensitive
js> test('boy', 'BOY') && test('BOY', 'boy')
true
js> // regular expressions
js> test('boy', 'b.y')
true
js> test('buoys', 'b.*s')
true

AND

public static final Predicate AND
Short-circuit boolean conjunction.

Tests:
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.SQUARED_SET); undefined;
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf('(Expr and (Expr true) (Expr true) (Expr false))');
(Expr and (Expr true) (Expr true) (Expr false))
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
false
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf('(Expr and (Expr true) (Expr true) (Expr true))');
(Expr and (Expr true) (Expr true) (Expr true))
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
true
js> // short-circuits
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf('(Expr and (Expr false) (Expr bogus))');
(Expr and (Expr false) (Expr bogus))
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
false

OR

public static final Predicate OR
Short-circuit boolean disjunction.

Tests:
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.SQUARED_SET); undefined;
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf('(Expr or (Expr false) (Expr false) (Expr false))');
(Expr or (Expr false) (Expr false) (Expr false))
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
false
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf('(Expr or (Expr false) (Expr false) (Expr true))');
(Expr or (Expr false) (Expr false) (Expr true))
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
true
js> // short-circuits
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf('(Expr or (Expr true) (Expr bogus))');
(Expr or (Expr true) (Expr bogus))
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
true

PROGRAM_AT_LEAST

public static final Predicate PROGRAM_AT_LEAST
Check the current dance program level.

Tests:
js> ds = new DanceState(new DanceProgram(Program.PLUS), Formation.SQUARED_SET); undefined;
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr PROGRAM AT LEAST 'BASIC)");
(Expr PROGRAM AT LEAST 'BASIC)
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
true
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr PROGRAM AT LEAST 'A2)");
(Expr PROGRAM AT LEAST 'A2)
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
false

TBONED

public static final Predicate TBONED
Check whether the tagged dancers are t-boned.

Tests:
js> importPackage(net.cscott.sdr.util); // for Fraction
js> FormationList = FormationList.js(this); undefined;
js> SD = StandardDancer; undefined
js> // rotate the formation 1/2 just to get rid of the original tags
js> f = FormationList.RH_OCEAN_WAVE; f.toStringDiagram()
^    v    ^    v
js> d = [d for (d in Iterator(f.sortedDancers()))]; undefined
js> f = f.move(d[1], f.location(d[1]).turn
  >                 (Fraction.ONE_QUARTER, false)) ; f.toStringDiagram()
^    <    ^    v
js> f = f.move(d[3], f.location(d[3]).turn
  >                 (Fraction.ONE_QUARTER, false)) ; f.toStringDiagram()
^    <    ^    <
js> // label those dancers
js> f= f.mapStd([SD.COUPLE_1_BOY, SD.COUPLE_1_GIRL,
  >              SD.COUPLE_3_BOY, SD.COUPLE_3_GIRL]); f.toStringDiagram()
1B^  1G<  3B^  3G<
js> ds = new DanceState(new DanceProgram(Program.PLUS), f); undefined;
js> function test(sel) {
  >   let c = net.cscott.sdr.calls.ast.AstNode.valueOf(
  >           "(Expr TBONED '"+sel+")");
  >    return PredicateList.valueOf(c.atom).evaluate(ds, c.args)
  > }
js> test('BOY')
false
js> test('GIRL')
false
js> test('CENTER')
true
js> test('END')
true
js> test('HEAD')
true

ARE

public static final Predicate ARE
Check that the tagged dancers also have some other tag.


ALL

public static final Predicate ALL
Check that all dancers have the specified tag.


EQUAL_CALL

public static final Predicate EQUAL_CALL
Check the identify of a call provided as an argument. Used in a hack to implement "boys trade".


FORMATION

public static final Predicate FORMATION
Check that the current dance state matches the specified formation (actually Matcher).

Tests:
js> ds = new DanceState(new DanceProgram(Program.PLUS), Formation.SQUARED_SET); undefined;
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr FORMATION 'STATIC SQUARE)");
(Expr FORMATION 'STATIC SQUARE)
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
true
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr FORMATION 'COUPLE)");
(Expr FORMATION 'COUPLE)
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
true
js> c = net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr FORMATION 'RH MINIWAVE)");
(Expr FORMATION 'RH MINIWAVE)
js> PredicateList.valueOf(c.atom).evaluate(ds, c.args)
false
Constructor Detail

PredicateList

public PredicateList()
Method Detail

valueOf

public static Predicate valueOf(String s)
Return the Predicate function with the given (case-insensitive) name.

Throws:
IllegalArgumentException - if no predicate with the given name is found.

sdr 0.7

Copyright © 2006-2009 C. Scott Ananian