@Override public CQIE getCQIE(Function head, List<Function> body) { return new CQIEImpl(head, body); }
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) { this.body = new EventGeneratingLinkedList<>(body); registerListeners(this.body); // TODO possible memory leak!!! we should also de-register when objects are removed } setHead(head); }
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; subscribeHeadTerms(head); } }
public void updateBody(List<Function> body) { this.body.clear(); this.body.addAll(body); // TODO: what about listeners? listChanged(); }
@Override public int hashCode() { if (rehash) { string = toString(); hash = string.hashCode(); rehash = false; } return hash; }
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); } } }
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); } }
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 int hashCode() { return toString().hashCode(); }
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); } } }
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) { this.body = new EventGeneratingLinkedList<>(body); registerListeners(this.body); // TODO possible memory leak!!! we should also de-register when objects are removed } setHead(head); }
@Override public CQIE getCQIE(Function head, Function... body) { return new CQIEImpl(head, body); }
@Override public CQIE getCQIE(Function head, List<Function> body) { return new CQIEImpl(head, body); }
@Override public CQIE getCQIE(Function head, Function... body) { return new CQIEImpl(head, body); }
@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); }
@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 = null; newquery.hash = this.hash; return newquery; }