public void updateHead(Function head) { this.head = head; if (head instanceof ListenableFunction) { EventGeneratingList<Term> headterms = ((ListenableFunction)head).getTerms(); headterms.removeListener(this); headterms.addListener(this); listChanged(); } else if (!(head instanceof ImmutableFunctionalTerm)) { throw new RuntimeException("Unknown type of function: not listenable nor immutable: " + head); } }
@Override public Term getTerm(int index) { return terms.get(index); }
ListenableFunction function = (ListenableFunction) term; EventGeneratingList<Term> innertermlist = function.getTerms(); innertermlist.removeListener(this); terms.clear(); terms.addAll(newterms); ListenableFunction function = (ListenableFunction) term; EventGeneratingList<Term> innertermlist = function.getTerms(); innertermlist.addListener(this);
private void subscribeHeadTerms(Function head) { if (head instanceof ListenableFunction) { EventGeneratingList<Term> headterms = ((ListenableFunction)head).getTerms(); headterms.addListener(this); } else if (!(head instanceof ImmutableFunctionalTerm)) { throw new RuntimeException("Unknown type of function: not listenable nor immutable: " + head); } }
@Override public Function clone() { ArrayList<Term> copyTerms = new ArrayList<Term>(terms.size()); for (Term term: terms) { copyTerms.add(term.clone()); } FunctionalTermImpl clone = new FunctionalTermImpl(getFunctionSymbol(), copyTerms); clone.identifier = identifier; clone.string = string; clone.rehash = rehash; return clone; }
protected FunctionalTermImpl(Predicate functor, List<Term> terms) { super(functor); EventGeneratingList<Term> eventlist = new EventGeneratingLinkedList<Term>(); eventlist.addAll(terms); this.terms = eventlist; registerListeners(eventlist); }
@Override public void setTerm(int index, Term newTerm) { listChanged(); terms.set(index, newTerm); }
@Override public String toString() { 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 ", " } } return sb.toString(); }
ListenableFunction function = (ListenableFunction) term; EventGeneratingList<Term> innertermlist = function.getTerms(); innertermlist.removeListener(this); terms.clear(); terms.addAll(newterms); ListenableFunction function = (ListenableFunction) term; EventGeneratingList<Term> innertermlist = function.getTerms(); innertermlist.addListener(this);
private void registerListeners(EventGeneratingList<? extends Term> functions) { functions.addListener(this); for (Object o : functions) { if (!(o instanceof Function)) { continue; } if (o instanceof ListenableFunction) { ListenableFunction f = (ListenableFunction) o; EventGeneratingList<Term> list = f.getTerms(); list.addListener(this); registerListeners(list); } else if (!(o instanceof ImmutableFunctionalTerm)) { throw new IllegalArgumentException("Unknown type of function: not listenable nor immutable: " + o); } } }
@Override public CQIEImpl clone() { Function copyHead = (Function)head.clone(); List<Function> copyBody = new ArrayList<>(body.size() + 10); for (Function atom : body) { if (atom != null) { copyBody.add((Function) atom.clone()); } } return new CQIEImpl(copyHead, copyBody); }
protected FunctionalTermImpl(Predicate functor, List<Term> terms) { super(functor); EventGeneratingList<Term> eventlist = new EventGeneratingLinkedList<Term>(); eventlist.addAll(terms); this.terms = eventlist; registerListeners(eventlist); }
@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; }
private void setHead(Function head) { // 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; if (head instanceof ListenableFunction) { EventGeneratingList<Term> headterms = ((ListenableFunction)head).getTerms(); headterms.addListener(this); } else if (!(head instanceof ImmutableFunctionalTerm)) { throw new RuntimeException("Unknown type of function: not listenable nor immutable: " + head); } } }
@Override public Function clone() { ArrayList<Term> copyTerms = new ArrayList<Term>(terms.size()); for (Term term: terms) { copyTerms.add(term.clone()); } FunctionalTermImpl clone = new FunctionalTermImpl(getFunctionSymbol(), copyTerms); clone.identifier = identifier; clone.string = string; clone.rehash = rehash; return clone; }
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; subscribeHeadTerms(head); } }
@Override public Term getTerm(int index) { return terms.get(index); }
private void registerListeners(EventGeneratingList<? extends Term> functions) { functions.addListener(this); for (Object o : functions) { if (!(o instanceof Function)) { continue; } else if (o instanceof ListenableFunction) { ListenableFunction f = (ListenableFunction) o; EventGeneratingList<Term> list = f.getTerms(); list.addListener(this); registerListeners(list); } else if (!(o instanceof ImmutableFunctionalTerm)) { throw new IllegalArgumentException("Unknown type of function: not listenable nor immutable: " + o); } } }