package ubic.gemma.model.genome.gene.phenotype.valueObject;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

import ubic.gemma.model.association.phenotype.PhenotypeAssociation;
import ubic.gemma.model.common.description.Characteristic;

public class BibliographicPhenotypesValueObject {

    private String geneName = "";
    private Collection<String> phenotypesValues = new HashSet<String>();

    public BibliographicPhenotypesValueObject() {
        super();
    }

    public BibliographicPhenotypesValueObject( String geneName, Collection<String> phenotypesValues ) {
        super();
        this.geneName = geneName;
        this.phenotypesValues = phenotypesValues;
    }

    public static Collection<BibliographicPhenotypesValueObject> phenotypeAssociations2BibliographicPhenotypesValueObjects(
            Collection<PhenotypeAssociation> phenotypeAssociations ) {

        Map<String, BibliographicPhenotypesValueObject> bibliographicPhenotypesValueObject = new HashMap<String, BibliographicPhenotypesValueObject>();

        for ( PhenotypeAssociation phenotypeAssociation : phenotypeAssociations ) {

            String geneName = phenotypeAssociation.getGene().getName();

            Collection<String> phenotypesValues = new HashSet<String>();

            for ( Characteristic characteristic : phenotypeAssociation.getPhenotypes() ) {

                phenotypesValues.add( characteristic.getValue() );
            }

            if ( bibliographicPhenotypesValueObject.get( geneName ) != null ) {

                bibliographicPhenotypesValueObject.get( geneName ).getPhenotypesValues().addAll( phenotypesValues );

            } else {

                BibliographicPhenotypesValueObject bibli = new BibliographicPhenotypesValueObject( geneName,
                        phenotypesValues );

                bibliographicPhenotypesValueObject.put( geneName, bibli );
            }
        }

        return bibliographicPhenotypesValueObject.values();
    }

    public String getGeneName() {
        return this.geneName;
    }

    public void setGeneName( String geneName ) {
        this.geneName = geneName;
    }

    public Collection<String> getPhenotypesValues() {
        return this.phenotypesValues;
    }

    public void setPhenotypesValues( Collection<String> phenotypesValues ) {
        this.phenotypesValues = phenotypesValues;
    }

    public void addPhenotypesValues( Collection<String> addedPhenotypesValues ) {
        this.phenotypesValues.addAll( addedPhenotypesValues );
    }

}

@@ -108,59 +108,11 @@
 Hash
-Map;%0Aimport java.util.HashSet;%0Aimport java.util.Map
+Set
 ;%0A%0Ai
@@ -698,26 +698,8 @@
 lic 
-static Collection%3C
 Bibl
@@ -732,92 +732,10 @@
 ject
-%3E phenotypeAssociations2BibliographicPhenotypesValueObjects(%0A            Collection%3C
+( 
 Phen
@@ -750,17 +750,16 @@
 ociation
-%3E
  phenoty
@@ -771,31 +771,29 @@
 ociation
-s
  ) %7B%0A
-%0A
         
 Map%3CStri
@@ -788,161 +788,25 @@
     
-Map%3CString, BibliographicPhenotypesValueObject%3E bibliographicPhenotypesValueObject = new HashMap%3CString, BibliographicPhenotypesValueObject%3E
+super
 ();%0A
-%0A
         
 for 
@@ -805,236 +805,66 @@
     
-for ( PhenotypeAssociation phenotypeAssociation : phenotypeAssociations ) %7B%0A%0A            String geneName = phenotypeAssociation.getGene().getName();%0A%0A            Collection%3CString%3E phenotypesValues = new HashSet%3CString%3E();%0A%0A    
+this.geneName = phenotypeAssociation.getGene().getName();%0A
     
@@ -891,27 +891,16 @@
 stic cha
-racteristic
  : pheno
@@ -931,25 +931,24 @@
 types() ) %7B%0A
-%0A
             
@@ -939,36 +939,37 @@
 ) %7B%0A            
-    
+this.
 phenotypesValues
@@ -977,27 +977,16 @@
 add( cha
-racteristic
 .getValu
@@ -996,24 +996,26 @@
  );%0A        
+%7D%0A
     %7D%0A%0A     
@@ -1017,22 +1017,34 @@
     
-        if ( b
+public static Collection%3CB
 ibli
@@ -1076,136 +1076,260 @@
 ject
-.get( geneName ) != null ) %7B%0A%0A                bibliographicPhenotypesValueObject.get( geneName ).getPhenotypesValues().addAll( p
+%3E phenotypeAssociations2BibliographicPhenotypesValueObjects(%0A            Collection%3CPhenotypeAssociation%3E phenotypeAssociations ) %7B%0A%0A        Collection%3CBibliographicPhenotypesValueObject%3E bibliographicPhenotypesValueObjects = new HashSet%3CBibliographicP
 heno
@@ -1330,34 +1330,40 @@
 cPhenotypesValue
-s 
+Object%3E(
 );%0A%0A            
@@ -1362,26 +1362,85 @@
     
-    %7D else %7B%0A%0A    
+for ( PhenotypeAssociation phenotypeAssociation : phenotypeAssociations ) %7B%0A%0A
     
@@ -1534,67 +1534,32 @@
 ct( 
-geneName,%0A                        phenotypesValues );%0A%0A    
+phenotypeAssociation );%0A
     
@@ -1604,46 +1604,23 @@
 ject
-.put( geneName, bibli );%0A            %7D
+s.add( bibli );
 %0A   
@@ -1680,17 +1680,9 @@
 ject
-.values()
+s
 ;%0A  
@@ -2084,158 +2084,6 @@
  %7D%0A%0A
-    public void addPhenotypesValues( Collection%3CString%3E addedPhenotypesValues ) %7B%0A        this.phenotypesValues.addAll( addedPhenotypesValues );%0A    %7D%0A%0A
 %7D%0A

revert to old version from a fix made in special case found in findPhenotypesForBibliographicReference