Project

General

Profile

« Previous | Next » 

Revision 22abd4ac

Added by Andreas Müller over 7 years ago

ref #6089 Remove all calls and methods for taxonomicChildrenCount and taxonomicParentCache

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/Taxon.java
615 615
        this.relationsFromThisTaxon.remove(rel);
616 616
        Taxon fromTaxon = rel.getFromTaxon();
617 617
        Taxon toTaxon = rel.getToTaxon();
618
        // check if this removes the taxonomical parent. If so, also remove shortcut to the higher taxon
619
        if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) ){
620
            if (fromTaxon != null && fromTaxon.equals(this)){
621
                this.taxonomicParentCache = null;
622
            }else if (toTaxon != null && toTaxon.equals(this)){
623
                this.setTaxonomicChildrenCount(computeTaxonomicChildrenCount());
624
            }
625
        }
618

  
626 619
        //delete Relationship from other related Taxon
627 620
        if (fromTaxon != this){
628 621
            rel.setToTaxon(null);  //remove this Taxon from relationship
......
672 665
                    if (toTaxon!=null){
673 666
                        toTaxon.addTaxonRelation(rel);
674 667
                    }
675
                    // check if this sets the taxonomical parent. If so, remember a shortcut to this taxon
676
                    if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) && toTaxon!=null ){
677
                        this.taxonomicParentCache = toTaxon;
678
                    }
679 668
                }else if (this.equals(toTaxon)){
680 669
                    relationsToThisTaxon.add(rel);
681 670
                    // also add relation to other taxon object
682 671
                    if (fromTaxon!=null){
683 672
                        fromTaxon.addTaxonRelation(rel);
684 673
                    }
685
                    if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) && fromTaxon!=null ){
686
                        this.taxonomicChildrenCount++;
687
                    }
688

  
689 674
                }
690 675
            }else if (toTaxon == null || fromTaxon == null){
691 676
                if (toTaxon == null){
......
694 679
                    if (fromTaxon!= null){
695 680
                        fromTaxon.addTaxonRelation(rel);
696 681
                    }
697
                    if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) && fromTaxon!=null ){
698
                        this.taxonomicChildrenCount++;
699
                    }
700 682
                }else if (fromTaxon == null && toTaxon != null){
701 683
                    fromTaxon = this;
702 684
                    relationsFromThisTaxon.add(rel);
703
                    if (toTaxon!=null){
704
                        toTaxon.addTaxonRelation(rel);
705
                    }
706
                    if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) && toTaxon!=null ){
707
                        this.taxonomicParentCache = toTaxon;
708
                    }
685
                    toTaxon.addTaxonRelation(rel);
709 686
                }
710 687
            }
711 688
        }
712 689
    }
713 690

  
714
    /* (non-Javadoc)
715
     * @see eu.etaxonomy.cdm.model.common.IRelated#addRelationship(eu.etaxonomy.cdm.model.common.RelationshipBase)
716
     */
691

  
717 692
    @Override
718 693
    @Deprecated //for inner use by RelationshipBase only
719 694
    public void addRelationship(RelationshipBase rel){
......
806 781
        }
807 782
    }
808 783

  
809
    /**
810
     * Creates a new {@link TaxonRelationship taxon relationship} (with {@link TaxonRelationshipType taxon relationship type}
811
     * "taxonomically included in") instance where <i>this</i> taxon plays the target
812
     * role (parent) and adds it to the set of
813
     * {@link #getRelationsToThisTaxon() "taxon relationships to"} belonging to <i>this</i> taxon.
814
     * The taxon relationship will also be added to the set of
815
     * {@link #getRelationsFromThisTaxon() "taxon relationships from"} belonging to the second taxon
816
     * (child) involved in the created relationship.<P>
817
     * Since the taxon relationship concerns the modifications
818
     * of the number of {@link #getTaxonomicChildrenCount() childrens} for <i>this</i> taxon and
819
     * of the {@link #getTaxonomicParent() parent taxon} for the child taxon will be stored.
820
     * The {@link name.Rank rank} of the taxon name used as a parent taxon must be higher
821
     * than the rank of the taxon name used as a child taxon.
822
     *
823
     * @param child			the taxon which plays the source role (child) in the new taxon relationship
824
     * @param citation		the reference source for the new taxon relationship
825
     * @param microcitation	the string with the details describing the exact localisation within the reference
826
     * @see    	   			#setTaxonomicParent(Taxon, Reference, String)
827
     * @see    	   			#addTaxonRelation(Taxon, TaxonRelationshipType, Reference, String)
828
     * @see    	   			#addTaxonRelation(TaxonRelationship)
829
     * @see    	   			#getTaxonRelations()
830
     * @see    	   			#getRelationsFromThisTaxon()
831
     * @see    	   			#getRelationsToThisTaxon()
832
     * @see    	   			#getTaxonomicParent()
833
     * @see    	   			#getTaxonomicChildrenCount()
834
     */
835
    @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
836
    public void addTaxonomicChild(Taxon child, Reference citation, String microcitation){
837
        if (child == null){
838
            throw new NullPointerException("Child Taxon is 'null'");
839
        }else{
840
            child.setTaxonomicParent(this, citation, microcitation);
841
        }
842
    }
843

  
844
    /**
845
     * Removes one {@link TaxonRelationship taxon relationship} with {@link TaxonRelationshipType taxon relationship type}
846
     * "taxonomically included in" and with the given child taxon playing the
847
     * source role from the set of {@link #getRelationsToThisTaxon() "taxon relationships to"} belonging
848
     * to <i>this</i> taxon. The taxon relationship will also be removed from the set
849
     * of {@link #getRelationsFromThisTaxon() "taxon relationships from"} belonging to the child taxon.
850
     * Furthermore the inherited RelatedFrom and RelatedTo attributes of the
851
     * taxon relationship will be nullified.<P>
852
     * Since the taxon relationship concerns the classification modifications
853
     * of the number of {@link #getTaxonomicChildrenCount() childrens} for <i>this</i> taxon and
854
     * of the {@link #getTaxonomicParent() parent taxon} for the child taxon will be stored.
855
     *
856
     * @param  child	the taxon playing the source role in the relationship to be removed
857
     * @see    	    	#removeTaxonRelation(TaxonRelationship)
858
     * @see    			#getRelationsToThisTaxon()
859
     * @see    			#getRelationsFromThisTaxon()
860
     * @see    	    	#getTaxonomicParent()
861
     * @see    	    	#getTaxonomicChildrenCount()
862
     * @see    			eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedFrom()
863
     * @see    			eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedTo()
864
     *
865
     */
866
    @Deprecated //will be removed in future versions. Use classification/TaxonNode instead
867
    public void removeTaxonomicChild(Taxon child){
868
        Set<TaxonRelationship> taxRels = this.getTaxonRelations();
869
        for (TaxonRelationship taxRel : taxRels ){
870
            if (taxRel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())
871
                && taxRel.getFromTaxon().equals(child)){
872
                this.removeTaxonRelation(taxRel);
873
            }
874
        }
875
    }
876

  
877
    /**
878
     * Returns the taxon which is the next higher taxon (parent) of <i>this</i> taxon
879
     * within the classification and which is stored in the
880
     * TaxonomicParentCache attribute. Each taxon can have only one parent taxon.
881
     * The child taxon and the parent taxon play the source respectively the
882
     * target role in one {@link TaxonRelationship taxon relationship} with
883
     * {@link TaxonRelationshipType taxon relationship type} "taxonomically included in".
884
     * The {@link name.Rank rank} of the taxon name used as a parent taxon must be higher
885
     * than the rank of the taxon name used as a child taxon.
886
     *
887
     * @see  #setTaxonomicParent(Taxon, Reference, String)
888
     * @see  #getTaxonomicChildren()
889
     * @see  #getTaxonomicChildrenCount()
890
     * @see  #getRelationsFromThisTaxon()
891
     */
892
    @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
893
    public Taxon getTaxonomicParent() {
894
        return this.taxonomicParentCache;
895
    }
896

  
897
    /**
898
     * Sets the taxononomic parent of <i>this</i> taxon to null.
899
     * Note that this method does not handle taxonomic relationships.
900
     */
901
    @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
902
    public void nullifyTaxonomicParent() {
903
        this.taxonomicParentCache = null;
904
    }
905

  
906
    /**
907
     * Replaces both the taxonomic parent cache with the given new parent taxon
908
     * and the corresponding taxon relationship with a new {@link TaxonRelationship taxon relationship}
909
     * (with {@link TaxonRelationshipType taxon relationship type} "taxonomically included in") instance.
910
     * In the new taxon relationship <i>this</i> taxon plays the source role (child).
911
     * This method creates and adds the new taxon relationship to the set of
912
     * {@link #getRelationsFromThisTaxon() "taxon relationships from"} belonging to <i>this</i> taxon.
913
     * The taxon relationship will also be added to the set of
914
     * {@link #getRelationsToThisTaxon() "taxon relationships to"} belonging to the second taxon
915
     * (parent) involved in the new relationship.<P>
916
     * Since the taxon relationship concerns the classification modifications
917
     * of the {@link #getTaxonomicParent() parent taxon} for <i>this</i> taxon and of the number of
918
     * {@link #getTaxonomicChildrenCount() childrens} for the child taxon will be stored.
919
     *
920
     * @param newParent		the taxon which plays the target role (parent) in the new taxon relationship
921
     * @param citation		the reference source for the new taxon relationship
922
     * @param microcitation	the string with the details describing the exact localisation within the reference
923
     * @see    	   			#removeTaxonRelation(TaxonRelationship)
924
     * @see    	   			#getTaxonomicParent()
925
     * @see    	   			#addTaxonRelation(Taxon, TaxonRelationshipType, Reference, String)
926
     * @see    	   			#addTaxonRelation(TaxonRelationship)
927
     * @see    	   			#getTaxonRelations()
928
     * @see    	   			#getRelationsFromThisTaxon()
929
     * @see    	   			#getRelationsToThisTaxon()
930
     * @see    	   			#getTaxonomicChildrenCount()
931
     */
932
    @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
933
    public void setTaxonomicParent(Taxon newParent, Reference citation, String microcitation){
934
        //remove previously existing parent relationship!!!
935
        Taxon oldParent = this.getTaxonomicParent();
936
        Set<TaxonRelationship> taxRels = this.getTaxonRelations();
937
        for (TaxonRelationship taxRel : taxRels ){
938
            if (taxRel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) && taxRel.getToTaxon().equals(oldParent)){
939
                this.removeTaxonRelation(taxRel);
940
            }
941
        }
942
        //add new parent
943
        if (newParent != null){
944
            addTaxonRelation(newParent, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(),citation,microcitation);
945
        }
946
    }
947

  
948
    /**
949
     * Returns the set of taxa which have <i>this</i> taxon as next higher taxon
950
     * (parent) within the classification. Each taxon can have several child
951
     * taxa. The child taxon and the parent taxon play the source respectively
952
     * the target role in one {@link TaxonRelationship taxon relationship} with
953
     * {@link TaxonRelationshipType taxon relationship type} "taxonomically included in".
954
     * The {@link name.Rank rank} of the taxon name used as a parent taxon must be higher
955
     * than the rank of the taxon name used as a child taxon.
956
     *
957
     * @see  #getTaxonomicParent()
958
     * @see  #addTaxonomicChild(Taxon, Reference, String)
959
     * @see  #getTaxonomicChildrenCount()
960
     * @see  #getRelationsToThisTaxon()
961
     */
962
    @Transient
963
    @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
964
    public Set<Taxon> getTaxonomicChildren() {
965
        Set<Taxon> taxa = new HashSet<Taxon>();
966
        Set<TaxonRelationship> rels = this.getRelationsToThisTaxon();
967
        for (TaxonRelationship rel: rels){
968
            TaxonRelationshipType tt = rel.getType();
969
            TaxonRelationshipType incl = TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN();
970
            if (tt.equals(incl)){
971
                taxa.add(rel.getFromTaxon());
972
            }
973
        }
974
        return taxa;
975
    }
976

  
977
    /**
978
     * Returns the number of taxa which have <i>this</i> taxon as next higher taxon
979
     * (parent) within the classification and the number of which is stored in
980
     * the TaxonomicChildrenCount attribute. Each taxon can have several child
981
     * taxa. The child taxon and the parent taxon play the source respectively
982
     * the target role in one {@link TaxonRelationship taxon relationship} with
983
     * {@link TaxonRelationshipType taxon relationship type} "taxonomically included in".
984
     * The {@link name.Rank rank} of the taxon name used as a parent taxon must be higher
985
     * than the rank of the taxon name used as a child taxon.
986
     *
987
     * @see  #getTaxonomicChildren()
988
     * @see  #getRelationsToThisTaxon()
989
     */
990
    @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
991
    public int getTaxonomicChildrenCount(){
992
        return taxonomicChildrenCount;
993
    }
994

  
995
    /**
996
     * @see  #getTaxonomicChildrenCount()
997
     */
998
    @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
999
    public void setTaxonomicChildrenCount(int taxonomicChildrenCount) {
1000
        this.taxonomicChildrenCount = taxonomicChildrenCount;
1001
    }
1002

  
1003
    /**
1004
     * Returns the boolean value indicating whether <i>this</i> taxon has at least one
1005
     * taxonomic child taxon within the classification (true) or not (false).
1006
     *
1007
     * @see  #getTaxonomicChildrenCount()
1008
     * @see  #getTaxonomicChildren()
1009
     */
1010
    @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
1011
    @Transient
1012
    public boolean hasTaxonomicChildren(){
1013
        return this.taxonomicChildrenCount > 0;
1014
    }
1015

  
1016
    @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
1017
    private int computeTaxonomicChildrenCount(){
1018
        int count = 0;
1019
        for (TaxonRelationship rel: this.getRelationsToThisTaxon()){
1020
            if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())){
1021
                count++;
1022
            }
1023
        }
1024
        return count;
1025
    }
1026

  
1027

  
1028 784
    /**
1029 785
     * Returns the boolean value indicating whether <i>this</i> taxon is a misaplication
1030 786
     * (misapplied name) for at least one other taxon.

Also available in: Unified diff