![JAR search and dependency download from the Maven repository](/logo.png)
com.laamella.sexpression.model.Atom Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of s-expressions Show documentation
Show all versions of s-expressions Show documentation
S-Expression support for Java
package com.laamella.sexpression.model;
import com.laamella.sexpression.visitor.PrinterVisitor;
import com.laamella.sexpression.visitor.Visitor;
import java.util.function.Consumer;
public class Atom implements SExpression {
public final String value;
public Atom(CharSequence value) {
this.value = value.toString();
}
@Override
public String toString() {
StringBuilder output = new StringBuilder();
try {
PrinterVisitor.TO_STRING.accept(this, output);
} catch (Exception e) {
return e.getMessage();
}
return output.toString();
}
@Override
public R visit(Visitor visitor, A arg) throws Exception {
return visitor.accept(this, arg);
}
@Override
public Otherwise whenList(Consumer action) {
return new Otherwise(true);
}
@Override
public Otherwise whenAtom(Consumer action) {
action.accept(this);
return new Otherwise(false);
}
@Override
public Otherwise whenComment(Consumer action) {
return new Otherwise(true);
}
@Override
public boolean isAtom() {
return true;
}
@Override
public boolean isList() {
return false;
}
@Override
public boolean isComment() {
return false;
}
@Override
public Atom toAtom() {
return this;
}
@Override
public AtomList toList() {
throw new IllegalStateException();
}
@Override
public Comment toComment() {
throw new IllegalStateException();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy