-
Notifications
You must be signed in to change notification settings - Fork 1
Setters and Getters
Rajab Davudov edited this page Apr 5, 2019
·
8 revisions
Bio Object provides default set and casted get methods already. For example:
Car c = new Car() ;
c.set(Car.PRODUCER, "Ford") ;
c.set(Car.YEAR_OF_PRODUCTION, 2019) ;
c.set(Car.FUEL_EFFICIENCY, 17.8) ;
c.set("undefined_tag", "Hello world") ;
c.getString(Car.PRODUCER) ;
c.getInt(Car.YEAR_OF_PRODUCTION) ;
c.getDouble(Car.FUEL_EFFICIENCY) ;
c.get("undefined_tag") ;
or you can still write standard setter/getters as following:
@BioObj
public class Car extends BioObject {
@BioTag(type="Integer")
public static final String YEAR_OF_PRODUCTION = "year_of_production" ;
@BioTag(type="String")
public static final String PRODUCER = "producer" ;
@BioTag(type="Integer")
public static final String ENGINE = "engine" ;
@BioTag(type="Integer")
public static final String CYLINDERS = "cylinders" ;
@BioTag(type="Double")
public static final String FUEL_EFFICIENCY = "fuel_efficiency" ;
public void setProducer(String producer) {
set(PRODUCER, producer) ;
}
public String getProducer() {
return getString(Vehicle.PRODUCER) ;
}
public void setYearOfProduction(int yearOfProduction) {
set(YEAR_OF_PRODUCTION, yearOfProduction) ;
}
public in getYearOfProduction() {
return getInt(Vehicle.YEAR_OF_PRODUCTION) ;
}
}
You can use remove()
for removing tags from a Bio Object.
c.remove(Car.PRODUCER) ;
c.remove(Car.YEAR_OF_PRODUCTION) ;
c.remove("undefined_tag", "Hello world") ;
Or you can call clear()
or empty()
c.clear() ;
c.empty().set(Car.PRODUCER, "Ford") ;
The only difference is empty()
returns current Bio Object instance or this.