fr.boreal.model.logicalElements.impl.StoredFunctionalTermImpl Maven / Gradle / Ivy
The newest version!
package fr.boreal.model.logicalElements.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import fr.boreal.model.logicalElements.api.StoredFunctionalTerm;
import fr.boreal.model.logicalElements.api.Substitution;
import fr.boreal.model.logicalElements.api.Term;
public class StoredFunctionalTermImpl implements StoredFunctionalTerm {
private final String funcSymbol;
private final List subTerms;
/////////////////////////////////////////////////
// Constructors
/////////////////////////////////////////////////
public StoredFunctionalTermImpl(String funcSymbol, List subTerms) {
this.funcSymbol = funcSymbol;
this.subTerms = subTerms;
}
/////////////////////////////////////////////////
// Public methods
/////////////////////////////////////////////////
@Override
public Term eval(Substitution s) {
List sub_terms_image = new ArrayList<>();
for (Term t : this.subTerms) {
sub_terms_image.add(s.createImageOf(t));
}
return new StoredFunctionalTermImpl(this.getFuncSymbol(), sub_terms_image);
}
/////////////////////////////////////////////////
// Getters
/////////////////////////////////////////////////
@Override
public String label() {
return this.toString();
}
@Override
public String getFuncSymbol() {
return this.funcSymbol;
}
@Override
public List getSubTerms() {
return this.subTerms;
}
/////////////////////////////////////////////////
// Object methods
/////////////////////////////////////////////////
@Override
public int hashCode() {
return Objects.hash(this.funcSymbol, subTerms);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
} else if (o == null) {
return false;
} else if (o instanceof StoredFunctionalTerm other) {
return this.getFuncSymbol().equals(other.getFuncSymbol())
&& this.getSubTerms().equals(other.getSubTerms());
} else {
return false;
}
}
public String toString() {
return this.funcSymbol + "(" + subTerms.toString().replace("[", "").replace("]", "").replace(" ", "") + ")";
}
}