Package output.converter

Source Code of output.converter.RelationConverter

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());
    }
}
TOP

Related Classes of output.converter.RelationConverter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.