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

import java.util.Collection;
import java.util.HashSet;

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 BibliographicPhenotypesValueObject( PhenotypeAssociation phenotypeAssociation ) {
        super();
        this.geneName = phenotypeAssociation.getGene().getName();
        for ( Characteristic cha : phenotypeAssociation.getPhenotypes() ) {
            this.phenotypesValues.add( cha.getValue() );
        }
    }

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

        Collection<BibliographicPhenotypesValueObject> bibliographicPhenotypesValueObjects = new HashSet<BibliographicPhenotypesValueObject>();

        for ( PhenotypeAssociation phenotypeAssociation : phenotypeAssociations ) {

            BibliographicPhenotypesValueObject bibli = new BibliographicPhenotypesValueObject( phenotypeAssociation );
            bibliographicPhenotypesValueObjects.add( bibli );
        }

        return bibliographicPhenotypesValueObjects;
    }

    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;
    }

}

@@ -104,19 +104,67 @@
 til.Hash
-Set
+Map;%0Aimport java.util.HashSet;%0Aimport java.util.Map
 ;%0A%0Aimpor
@@ -734,32 +734,50 @@
   %7D%0A%0A    public 
+static Collection%3C
 BibliographicPhe
@@ -794,18 +794,100 @@
 ueObject
-( 
+%3E phenotypeAssociations2BibliographicPhenotypesValueObjects(%0A            Collection%3C
 Phenotyp
@@ -890,32 +890,33 @@
 otypeAssociation
+%3E
  phenotypeAssoci
@@ -920,29 +920,31 @@
 ociation
+s
  ) %7B%0A
+%0A
         
 super();
@@ -935,33 +935,169 @@
         
-super
+Map%3CString, BibliographicPhenotypesValueObject%3E bibliographicPhenotypesValueObject = new HashMap%3CString, BibliographicPhenotypesValueObject%3E
 ();%0A
+%0A
         
 this.gen
@@ -1092,66 +1092,236 @@
     
-this.geneName = phenotypeAssociation.getGene().getName();%0A
+for ( PhenotypeAssociation phenotypeAssociation : phenotypeAssociations ) %7B%0A%0A            String geneName = phenotypeAssociation.getGene().getName();%0A%0A            Collection%3CString%3E phenotypesValues = new HashSet%3CString%3E();%0A%0A    
     
@@ -1348,16 +1348,27 @@
 stic cha
+racteristic
  : pheno
@@ -1399,24 +1399,29 @@
 types() ) %7B%0A
+%0A    
             
@@ -1412,37 +1412,32 @@
                 
-this.
 phenotypesValues
@@ -1445,16 +1445,27 @@
 add( cha
+racteristic
 .getValu
@@ -1479,18 +1479,16 @@
         
-%7D%0A
     %7D%0A%0A 
@@ -1494,34 +1494,22 @@
     
-public static Collection%3CB
+        if ( b
 ibli
@@ -1541,260 +1541,136 @@
 ject
-%3E phenotypeAssociations2BibliographicPhenotypesValueObjects(%0A            Collection%3CPhenotypeAssociation%3E phenotypeAssociations ) %7B%0A%0A        Collection%3CBibliographicPhenotypesValueObject%3E bibliographicPhenotypesValueObjects = new HashSet%3CBibliographicP
+.get( geneName ) != null ) %7B%0A%0A                bibliographicPhenotypesValueObject.get( geneName ).getPhenotypesValues().addAll( p
 heno
@@ -1675,32 +1675,26 @@
 notypesValue
-Object%3E(
+s 
 );%0A%0A        
@@ -1697,85 +1697,26 @@
     
-for ( PhenotypeAssociation phenotypeAssociation : phenotypeAssociations ) %7B%0A%0A
+    %7D else %7B%0A%0A    
     
@@ -1810,32 +1810,67 @@
 ct( 
-phenotypeAssociation );%0A
+geneName,%0A                        phenotypesValues );%0A%0A    
     
@@ -1915,23 +1915,46 @@
 ject
-s.add( bibli );
+.put( geneName, bibli );%0A            %7D
 %0A   
@@ -2010,17 +2010,25 @@
 ueObject
-s
+.values()
 ;%0A    %7D%0A
@@ -2422,10 +2422,162 @@
 %0A    %7D%0A%0A
+    public void addPhenotypesValues( Collection%3CString%3E addedPhenotypesValues ) %7B%0A        this.phenotypesValues.addAll( addedPhenotypesValues );%0A    %7D%0A%0A
 %7D%0A

fix a special case found in findPhenotypesForBibliographicReference