Skip to content

Merging

Rajab Davudov edited this page Jul 9, 2019 · 3 revisions

Merging

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.

Merge Types

Bio Object supports several options for merging tags. Default type is Replace. Please see below:

  • DoNotReplace Does not replace this tag
  • Replace Replaces this tag with provided one
  • ReplaceWithMax Replaces this tag if new value is greater than old value
  • ReplaceWithMin Replaces this tag if new value is smaller than old value
  • ReplaceWithNew Replaces this tag if new value is newer than old value
  • ReplaceWithOld Replaces this tag if new value is older than old value
  • ReplaceByAnd Replaces this tag by anding new and old values
  • ReplaceByOr Replaces this tag by oring new and old values
  • ReplaceByAdd Replaces this tag by adding new and old values. In case of Arrays and Lists and Strings it will be append.
  • ReplaceBySubtract Replaces this tag by substracting new value from old value
  • ReplaceByMultiply Replaces this tag by multiplying new and old values
  • ReplaceByDivide Replaces this tag by dividing old to new value