This repository has been archived by the owner on Aug 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Home
KIMB-technologies edited this page Jul 10, 2018
·
5 revisions
Example Class to Export:
import eu.kimb_technologies.usf.Atom;
import eu.kimb_technologies.usf.USFInteger;
import eu.kimb_technologies.usf.USFList;
import eu.kimb_technologies.usf.USFSaveable;
public class Position implements USFSaveable {
private int xPos;
private int yPos;
public Position() {
this.xPos = -1;
this.yPos = -1;
}
public Position(int xPos, int yPos) {
this.xPos = xPos;
this.yPos = yPos;
}
public int getY() {
return yPos;
}
public int getX() {
return xPos;
}
@Override
public Atom toAtom() {
USFList list = new USFList();
list.add( new USFInteger( this.xPos ) );
list.add( new USFInteger( this.yPos ) );
return list;
}
@Override
public void fromAtom(Atom atom) t {
try {
USFList list = ((USFList) atom);
this.xPos = ((USFInteger) list.get(0)).getValue();
this.yPos = ((USFInteger) list.get(1)).getValue();
} catch( Exception e ) {
System.out.println("Error on loading a position!");
}
}
}
Now you can export and import this way:
Position pos = new Position(12,33);
System.out.println( USFParser.toUSF( pos ) );
// [12,33]
USFParser.saveToFile("/home/user/example.usf", pos);
// will create file /home/user/example.usf with content [12,33]
// creating "default" object
Position posImport = new Position();
// importing saved data
posImport.fromAtom( USFParser.loadFromFile("/home/user/example.usf") );
// or just:
posImport.fromAtom( USFParser.parse("[12,33]") );
Exporting and Importing a Model from MVC-Pattern.
- Each model class has to implement the
USFSaveavle
-Interface - E.g. the model class to export