classDiagram startrek. table(starship,[name,type]). table(crewman,['fname','lname',species]). table(commander,[rank]). table(lieutenant,[specialty]). subtable(crewman,[commander,lieutenant]). assoc(assgnnt,starship,onBoard,BLACK_DIAMOND,crewman,hasCrew,BLANK). | ![]() |
![]() |
DTable Q1 = new DTable("Q1", "vname", "vposting");
st.crewman.select(c->c.species.equals("vulcan"))
.forEach(v ->v.onBoard().forEach(d->Q1.add(v.fname,d.name)));
Q1.print();
st.post.select(p->p.name.equals("Deep Space 9")).hasCrew()
.select(c->(c instanceof Allegory.startrek.medical)).print();
System.out.println("version 2");
st.medical.select(m->m.onBoard()
.select(mm->mm.name.equals("Deep Space 9")).exists()).print();
st.post.select(p->p.name.equals("Enterprise-A")).hasCrew().print();
postTable dt = st.post.select(p->p.hasCrew().select(c->c.lname.equals("troi")).exists());
postTable wr = st.post.select(p->p.hasCrew().select(c->c.lname.equals("riker")).exists());
postTable both = dt.intersect(wr);
both.print();
st.medical.select(m->m.specialty.equals("chief")).onBoard().print();
System.out.println("version 2");
st.post.select(
p->p.hasCrew()
.select(c->((c instanceof medical) && ((medical) c).specialty.equals("chief"))).exists())
.print();
st.post.select(p->p.name.equals("Enterprise-A")).hasCrew().fname().print();
st.crewman.select(c->c.species.equals("vulcan"))
.forEach(v->v.onBoard()
.reject(p->p.kind.equals("star ship"))
.error(er,"C1: %v is not onboard a starship", e->e.name));
crewmanTable onds9 = st.post.select(p->p.name.equals("Deep Space 9")).hasCrew();
if (onds9.exists(p->p.species.equals("klingon"))) {
if (onds9.notExists(p->p.species.equals("trill")))
er.add("C2: a klingon works on ds9, but no trills");
}
LinkedList<T> | tuples() | return list of all tuples of this table (and subtables) |
stream<T> | stream() | produce a stream of all tuples of this table (and subtables) |
boolean | contains(T t) | does this table contain tuple t |
int | count() size() | return number of tuples in this table (and subtables) |
boolean | isEmpty() notExists() | is table empty of tuples (same as count()==0) |
boolean | isNotEmpty() exists() | does table have tuples (same as count()>0) |
TBL | unique() | return table with unique tuples, deleting replicas |
TBL | intersect(TBL x) | return in a table tuples common to table this and table x |
T | getTupleEH(String id) | return tuple referenced by this identifier; throw exception if no such tuple exists |
TBL | select(Predicate<T>) | return table of tuples that satisfy the given predicate |
TBL | reject(Predicate<T>) | return table of tuples that do NOT satisfy the given predicate |
TBL | sort(Comparator<T>) | create a new table that sorts this table by the given comparator |
TBL | duplicates() | create a new table with the duplicate tuples of this table; no duplicate is itself replicated |
boolean | equals(TBL t) | return true if this table and table t have the same set of tuples |
void | forEach(Consumer<T>) | apply consumer function to each tuple in this table |
boolean | anyMatch(Predicate<T>) | return true if any tuple of this table satisfies given predicate |
boolean | allMatch(Predicate<T>) | return true if all tuples of this table satisfy the given predicate. |
boolean | noMatch(Predicate<T>) | return true if NO tuple of this table satisfies the given predicate. |
void | print() | print to System.out the tuples of this table and all subtables |
void | print(PrintStream) | print to PrintStream the tuples of this table and all subtables |
void | printLocal(PrintStream) | print only tuples of this table and NOT subtables |
void | groupBy(Function<T,String>, Consumer<TBL> action) | partition the tuples of this table into groups by the (grouper) function; apply action to each subtable (typically adding an aggregated tuple to a table). |
void | error(ErrorReport, FormatString, Function<T,String>...) | add an error to ErrorReport object formatted by the FormatString whose arguments are provided by a sequence of functions to be applied to each tuple of 'this' table. |
T | getFirst() | return first tuple of 'this' table |
TBL<L> | assoc() | return table of L tuples that are connected to 'this' table via association 'assoc' |
void | add(T) | add tuple t to this table |
void | addFirst(T) | add tuple to the head (top) of this table |
void | addLast(T) | add tuple to the tail (bottom) of this table |
void | deleteAll() | delete all tuples in this table |
boolean | delete(T) | delete tuple from this table or a subtable; only one tuple is deleted. Returns true if a tuple was deleted; false otherwise |
boolean | cascadingDelete(T) | delete this tuple and any tuples that reference it. Returns true if the given tuple was deleted |
void | deleteEH(T) | same as delete, but throw an exception if given tuple was not deleted |
void | cascadingDeleteEH(T) | same as cascadingDelete, but throw an exception if given tuple was not deleted |
int | compareTo(T) | compare the id of this tuple with the given tuple |
void | print(PrintStream) | print this tuple on given PrintStream |
void | print() | print this tuple on System.out |
void | println() | print this tuple with return on System.out |
void | print(Object...) | print objects on single line separated by a space |
void | println(Object...) | print objects on single line separated by a space, ending with new line |
String | toString() | convert this tuple to a string |
TBL<L> | assoc() | follow this tuple via association "assoc" to produce a table of tuples of type L, where L is the name of associated class) |
T<L> | link2assoc() | if association "assoc" has a 1 cardinality, this operation retrieves the corresponding tuple in TBL<L> where L is the name of the associated class. |
T t = (computation that returns a tuple of type T in table TBL);
t.s = "don"; // update string field s with value "don"
t.i = 15; // update int field i with value 15
t.f = 3.1415; // update float field f with value 3.1415
t.b = true; // update bool field f to true