package output.converter;
import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
import core.Column;
import core.Relation;
import ra.Utils;
/**
*
* @author jsroka
*/
public class RelationConverter extends AbstractSingleValueConverter {
@Override
public boolean canConvert(@SuppressWarnings("rawtypes") Class type) {
return type.equals(Relation.class);
}
@Override
public Object fromString(String string) {
String[] t = string.split("-");
int size = Column.fromString(t[1], Utils.getCaf()).getNumber() - Column.fromString(t[0], Utils.getCaf()).getNumber() + 1;
return new Relation(Utils.getCaf().getSpaceForNewRelation(size));
}
@Override
public String toString(Object obj) {
Relation r = (Relation) obj;
return r.getFirstCol().toString(Utils.getCaf()) + "-" + r.getLastCol().toString(Utils.getCaf());
}
}