-
Notifications
You must be signed in to change notification settings - Fork 1
Trimming
Trimming means to remove tags from Bio Object instance. There are several methods of trimming.
This method removes all keys which are not found in the dictionary. 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.trim() ;
undefine_tag will be removed after trimming. trim()
checks only Bio Object tags it doesn't check inner Bio Objects.
<?xml version="1.0" encoding="UTF-8"?>
<car type="Car" code="28201">
<fuel-efficiency type="Double">17.8</fuel-efficiency>
<producer type="String">Ford</producer>
<year-of-production type="Integer">2019</year-of-production>
</car>
trimAll()
doesn't same this as trim()
but also goes deeper to trim inner Bio Objects recursively.
Engine e = new Engine() ;
e.set(Engine.CAPACITY, 4000);
e.set("undefined_tag", "Hello Engine") ;
Car c = new Car() ;
c.set(Car.ENGINE, e) ;
c.set(Car.PRODUCER, "Ford") ;
c.set(Car.FUEL_EFFICIENCY, 17.8) ;
c.set("undefined_tag", "Hello World") ;
c.trim() ;
System.out.println(c.toXml());
Here undefined_tag inside c
will be removed but undefined_tag inside e
will remain.
<?xml version="1.0" encoding="UTF-8"?>
<car type="Car" code="28201">
<engine type="Engine" code="20998">
<capacity type="Integer">4000</capacity>
<engine-type type="EngineType">vee</engine-type>
<horse-power type="Integer">250</horse-power>
<number-of-cylinders type="Integer">6</number-of-cylinders>
<undefined-tag type="String">Hello Engine</undefined-tag>
</engine>
<fuel-efficiency type="Double">17.8</fuel-efficiency>
<producer type="String">Ford</producer>
<year-of-production type="Integer">2019</year-of-production>
</car>
c.trimAll() ;
System.out.println(c.toXml());
We result in following XML:
<?xml version="1.0" encoding="UTF-8"?>
<car type="Car" code="28201">
<engine type="Engine" code="20998">
<capacity type="Integer">4000</capacity>
<engine-type type="EngineType">vee</engine-type>
<horse-power type="Integer">250</horse-power>
<number-of-cylinders type="Integer">6</number-of-cylinders>
</engine>
<fuel-efficiency type="Double">17.8</fuel-efficiency>
<producer type="String">Ford</producer>
<year-of-production type="Integer">2019</year-of-production>
</car>
Now both undefined tags are removed.
This method removes all keys which are annotated with specific trim key. It is useful during different serializations such as to file and for network. If you want to trim some tags for file and trim other tags for network, you can specify different trim keys for each tag as following:
@BioTag(type="String", trimKeys="network")
public static final String INFO_FOR_FILE = "info_for_file" ;
@BioTag(type="String", trimKeys={"file","log_file"})
public static final String INFO_FOR_NETWORK = "info_for_network" ;
Here info_file_file will be removed/trimmed if we call c.trim("network")
and info_for_network will be removed if we call c.trim("file")
Note that a tag can have more than one trim keys.
This method is an opposite of trim(key)
as it keeps annotated tags and removes rest. Coming back to previous example:
@BioTag(type="String", inverseTrimKeys={"file","log_file"})
public static final String INFO_FOR_FILE = "info_for_file" ;
@BioTag(type="String", inverseTrimKeys="network")
public static final String INFO_FOR_NETWORK = "info_for_network" ;
Here info_file_file will be kept and rest will be removed if we call c.inverseTrim("file")
and info_for_network will be kept and rest will be removed if we call c.inverseTrim("network")