Skip to content

Clonning

Rajab Davudov edited this page Mar 13, 2019 · 1 revision

clone()

Bio Object supports clone() where it will return a new instance with same values.

equals()

Equality method is overridden inside Bio Object in order to check each tag value against compared Bio Object. If any tag is not equal then equality will fail.

Also if tag is missing in compared Bio Object equality will fail. But compared Bio Object may contain additional tags it will not affect equality.

Car c = new Car() ;
c.set(Car.PRODUCER, "Ford") ;
c.set(Car.YEAR_OF_PRODUCTION, 2017) ;
c.set(Car.FUEL_EFFICIENCY, 17.8) ;

Car clonned = (Car) c.clone() ;
System.out.println(clonned.equals(c)) ;
true

If add new tag to clonned or change equality will fail.

Car clonned = (Car) c.clone() ;
clonned.set(Car.YEAR_OF_PRODUCTION, 2015) ;
System.out.println(clonned.equals(c)) ;
false

setImmutable()

This method sets object to be immutable. No further set, remove or clear will be possible.

Car c = new Car() ;
c.set(Car.PRODUCER, "Ford") ;
c.set(Car.YEAR_OF_PRODUCTION, 2017) ;
c.set(Car.FUEL_EFFICIENCY, 17.8) ;

c.setImmutable();
c.set(Car.YEAR_OF_PRODUCTION, 2018) ;

will throw an com.linkedlogics.bio.exception.ImmutableException exception.

Exception in thread "main" com.linkedlogics.bio.exception.ImmutableException: bio object is immutable
	at com.linkedlogics.bio/com.linkedlogics.bio.BioObject.validateKeyAndObject(BioObject.java:173)
	at com.linkedlogics.bio/com.linkedlogics.bio.BioObject.put(BioObject.java:191)
	at com.linkedlogics.bio/com.linkedlogics.bio.BioObject.set(BioObject.java:200)
	at com.linkedlogics.bio/com.linkedlogics.bio.test.car.BioFormattingTest.main(BioFormattingTest.java:23)
Clone this wiki locally