public void updateHead(Function head) { this.head = head; EventGeneratingList<Term> headterms = (EventGeneratingLinkedList<Term>) head.getTerms(); headterms.removeListener(this); headterms.addListener(this); listChanged(); }
/** * Check whether the function contains a particular term argument or not. * * @param t * the term in question. * @return true if the function contains the term, or false otherwise. */ public boolean containsTerm(Term t) { for (int i = 0; i < terms.size(); i++) { Term t2 = terms.get(i); if (t2.equals(t)) return true; } return false; }
public void updateTerms(List<Term> newterms) { for (Term term : terms) { if (term instanceof FunctionalTermImpl) { FunctionalTermImpl function = (FunctionalTermImpl) term; EventGeneratingList<Term> innertermlist = (EventGeneratingList<Term>) function.getTerms(); innertermlist.removeListener(this); } } terms.clear(); terms.addAll(newterms); for (Term term : terms) { if (term instanceof FunctionalTermImpl) { FunctionalTermImpl function = (FunctionalTermImpl) term; EventGeneratingList<Term> innertermlist = (EventGeneratingList<Term>) function.getTerms(); innertermlist.addListener(this); } } listChanged(); }
protected CQIEImpl(Function head, List<Function> body) { // The syntax for CQ may contain no body, thus, this condition will // check whether the construction of the link list is possible or not. if (body != null) { EventGeneratingList<Function> eventbody = new EventGeneratingLinkedList<Function>(); eventbody.addAll(body); this.body = eventbody; registerListeners(eventbody); // TODO possible memory leak!!! we should also de-register when objects are removed } // The syntax for CQ may also contain no head, thus, this condition // will check whether we can look for the head terms or not. if (head != null) { this.head = head; EventGeneratingList<Term> headterms = (EventGeneratingList<Term>) head.getTerms(); headterms.addListener(this); } }
private void registerListeners(EventGeneratingList<? extends Term> functions) { functions.addListener(this); for (Object o : functions) { if (!(o instanceof Function)) { continue; } Function f = (Function) o; EventGeneratingList<Term> list = (EventGeneratingList<Term>) f.getTerms(); list.addListener(this); registerListeners(list); } }
@Override public FunctionalTermImpl clone() { ArrayList<Term> copyTerms = new ArrayList<Term>(terms.size()); for (Term term: terms) { copyTerms.add(term.clone()); } FunctionalTermImpl clone = new FunctionalTermImpl(functor, copyTerms); clone.identifier = identifier; clone.string = string; clone.rehash = rehash; return clone; }
@Override public Term getTerm(int index) { return terms.get(index); }
@Override public void setTerm(int index, Term newTerm) { listChanged(); terms.set(index, newTerm); }
@Override public String toString() { /* expensive, so only compute the string if necessary */ if (string == null) { StringBuilder sb = new StringBuilder(); sb.append(head.toString()); sb.append(SPACE); sb.append(INV_IMPLIES); sb.append(SPACE); Iterator<Function> bit = body.iterator(); while (bit.hasNext()) { Function atom = bit.next(); sb.append(atom.toString()); if (bit.hasNext()) { // if there is a next atom. sb.append(COMMA); sb.append(SPACE); // print ", " } } string = sb.toString(); } return string; }
protected FunctionalTermImpl(Predicate functor, List<Term> terms) { this.functor = functor; EventGeneratingList<Term> eventlist = new EventGeneratingLinkedList<Term>(); eventlist.addAll(terms); this.terms = eventlist; registerListeners(eventlist); }
private void registerListeners(EventGeneratingList<? extends Term> functions) { functions.addListener(this); for (Object o : functions) { if (!(o instanceof Function)) { continue; } Function f = (Function) o; EventGeneratingList<Term> list = (EventGeneratingList<Term>) f.getTerms(); list.addListener(this); registerListeners(list); } }
@Override public CQIEImpl clone() { Function copyHead = (Function)head.clone(); List<Function> copyBody = new ArrayList<Function>(body.size() + 10); for (Function atom : body) { if (atom != null) { copyBody.add((Function) atom.clone()); } } CQIEImpl newquery = new CQIEImpl(copyHead, copyBody); newquery.rehash = this.rehash; newquery.string = this.string; newquery.hash = this.hash; return newquery; }
protected CQIEImpl(Function head, Function[] body) { // The syntax for CQ may contain no body, thus, this condition will // check whether the construction of the link list is possible or not. if (body != null) { EventGeneratingList<Function> eventbody = new EventGeneratingLinkedList<Function>(); Collections.addAll(eventbody, body); this.body = eventbody; registerListeners(eventbody); // TODO possible memory leak!!! we should also de-register when objects are removed } // The syntax for CQ may also contain no head, thus, this condition // will check whether we can look for the head terms or not. if (head != null) { this.head = head; EventGeneratingList<Term> headterms = (EventGeneratingList<Term>) head.getTerms(); headterms.addListener(this); } }