@Override public ImmutableFunctionalTerm getImmutableFunctionalTerm(Function functionalTerm) { if (GroundTermTools.isGroundTerm(functionalTerm)) { return new GroundFunctionalTermImpl(functionalTerm); } else { return new NonGroundFunctionalTermImpl(functionalTerm); } }
public static GroundTerm castIntoGroundTerm(Term term) throws NonGroundTermException{ if (term instanceof GroundTerm) return (GroundTerm) term; if (term instanceof Function) { Function functionalTerm = (Function) term; // Recursive FunctionSymbol functionSymbol = Optional.of(functionalTerm.getFunctionSymbol()) .filter(p -> p instanceof FunctionSymbol) .map(p -> (FunctionSymbol)p) .orElseThrow(() -> new NonGroundTermException(term + "is not using a function symbol but a" + functionalTerm.getFunctionSymbol().getClass())); return new GroundFunctionalTermImpl(castIntoGroundTerms(functionalTerm.getTerms()), functionSymbol); } throw new NonGroundTermException(term + " is not a ground term"); }
@Override public ImmutableFunctionalTerm getImmutableFunctionalTerm(FunctionSymbol functor, ImmutableList<? extends ImmutableTerm> terms) { if (functor instanceof OperationPredicate) { return getImmutableExpression((OperationPredicate)functor, terms); } if (GroundTermTools.areGroundTerms(terms)) { return new GroundFunctionalTermImpl((ImmutableList<? extends GroundTerm>)terms, functor); } else { // Default constructor return new NonGroundFunctionalTermImpl(functor, terms); } }
@Override public ImmutableFunctionalTerm getImmutableFunctionalTerm(Predicate functor, ImmutableList<ImmutableTerm> terms) { if (functor instanceof OperationPredicate) { return getImmutableExpression((OperationPredicate)functor, terms); } if (GroundTermTools.areGroundTerms(terms)) { return new GroundFunctionalTermImpl(functor, terms); } else { // Default constructor return new NonGroundFunctionalTermImpl(functor, terms); } }
public static GroundTerm castIntoGroundTerm(Term term) throws NonGroundTermException{ if (term instanceof GroundTerm) return (GroundTerm) term; if (term instanceof Function) { Function functionalTerm = (Function) term; // Recursive return new GroundFunctionalTermImpl(functionalTerm.getFunctionSymbol(), castIntoGroundTerms(functionalTerm.getTerms())); } throw new NonGroundTermException(term + " is not a ground term"); }