-
Notifications
You must be signed in to change notification settings - Fork 1
Merging
Rajab Davudov edited this page Jul 9, 2019
·
3 revisions
Bio Objects can be merge by calling merge(BioObject object). Default merge is done by replacing key with value from provided object. But you can also define merge type in tag definition by mergeBy attribute.
Car c1 = new Car() ;
c1.set(Car.YEAR_OF_PRODUCTION, 2019) ;
Car c2 = new Car() ;
c2.set(Car.YEAR_OF_PRODUCTION, 2015) ;
c1.merge(c2) ;
System.out.println(c1) ;Result is
<?xml version="1.0" encoding="UTF-8"?>
<car type="Car" code="28201">
<year-of-production type="Integer">2015</year-of-production>
</car>
If we define tag as following:
@BioTag(type="Integer", mergeBy = MergeType.ReplaceWithMax)
public static final String YEAR_OF_PRODUCTION = "year_of_production" ;then YEAR_OF_PRODUCTION will be replaced only if new value is greater than old one.
Bio Object supports several options for merging tags. Default type is Replace. Please see below:
-
DoNotReplaceDoes not replace this tag -
ReplaceReplaces this tag with provided one -
ReplaceWithMaxReplaces this tag if new value is greater than old value -
ReplaceWithMinReplaces this tag if new value is smaller than old value -
ReplaceWithNewReplaces this tag if new value is newer than old value -
ReplaceWithOldReplaces this tag if new value is older than old value -
ReplaceByAndReplaces this tag by anding new and old values -
ReplaceByOrReplaces this tag by oring new and old values -
ReplaceByAddReplaces this tag by adding new and old values. In case of Arrays and Lists and Strings it will be append. -
ReplaceBySubtractReplaces this tag by substracting new value from old value -
ReplaceByMultiplyReplaces this tag by multiplying new and old values -
ReplaceByDivideReplaces this tag by dividing old to new value