Code reefactoring

This commit is contained in:
2022-01-14 16:10:19 +01:00
parent 45a1765a03
commit ff40222902
13 changed files with 68 additions and 92 deletions

View File

@ -1,7 +1,6 @@
package obitax
import (
"errors"
"fmt"
"log"
)
@ -42,15 +41,11 @@ func (taxonomy *Taxonomy) Length() int {
return len(*taxonomy.nodes)
}
func (taxonomy *Taxonomy) Iterator() *ITaxonSet {
return taxonomy.nodes.Iterator()
}
func (taxonomy *Taxonomy) AddNewTaxa(taxid, parent int, rank string, replace bool, init bool) (*TaxNode, error) {
if !replace {
_, ok := (*taxonomy.nodes)[taxid]
if ok {
return nil, errors.New(fmt.Sprintf("Trying to add taxoon %d already present in the taxonomy", taxid))
return nil, fmt.Errorf("trying to add taxoon %d already present in the taxonomy", taxid)
}
}
@ -66,7 +61,7 @@ func (taxonomy *Taxonomy) Taxon(taxid int) (*TaxNode, error) {
if !ok {
a, aok := taxonomy.alias[taxid]
if !aok {
return nil, errors.New(fmt.Sprintf("Taxid %d is not part of the taxonomy", taxid))
return nil, fmt.Errorf("Taxid %d is not part of the taxonomy", taxid)
}
log.Printf("Taxid %d is deprecated and must be replaced by %d", taxid, a.taxid)
t = a
@ -109,9 +104,9 @@ func (taxonomy *Taxonomy) ReindexParent() error {
for _, taxon := range *taxonomy.nodes {
taxon.pparent, ok = (*taxonomy.nodes)[taxon.parent]
if !ok {
return errors.New(fmt.Sprintf("Parent %d of taxon %d is not defined in taxonomy",
return fmt.Errorf("Parent %d of taxon %d is not defined in taxonomy",
taxon.taxid,
taxon.parent))
taxon.parent)
}
}