/* 
 *      //\\
 *    ////\\\\	  Project Bayanihan
 *   o |.[].|o 
 *  -->|....|->-  Worldwide Volunteer Computing Using Java
 *  o o.o.o.o\<\  
 * -->->->->->-   Copyright 1999, Luis F. G. Sarmenta.
 *   <\<\<\<\<\   All rights reserved.
 * 
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for NON-COMMERCIAL purposes and without
 * fee is hereby granted provided that this copyright notice
 * and disclaimer appear in all copies.
 *
 * LUIS F. G. SARMENTA MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
 * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. LUIS F. G. SARMENTA
 * SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT
 * OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 * ----------------------------------------------------------------------------|
 */
package bayanihan.apps.ftsim;

import java.util.*;
import bayanihan.util.*;

/**
 * A group of result entries that have matching results.
 */
public class ResultGroup2 extends ResultGroup
{
   //////////////////
   // Constructors //
   //////////////////

   /**
    * This no-arg constructor does not create any data.  You must
    * set the data yourself by calling setData().
    */
   public ResultGroup2()
   {
      // super;
   }
   
   public ResultGroup2( CredResultEntry resEntry )
   {
      super( resEntry );
   }

   //////////////////////
   // Accessor methods //
   //////////////////////
   
   public MatchProb getMatchProb( double f, double h )
   {
//      if ( recomputeMatchProb )
//      {
         int m = results.size();
         
         if ( m == 0 )
         {
            this.matchProb.set( m, 1.0 - f, f );
         }
         else
         {
            double allGoodProb = 1.0;
            double allBadProb = 1.0;
      
            for ( int i = 0; i < m; i++ )
            {
               CredResultEntry credResEntry = 
                  (CredResultEntry)results.elementAt( i );
               
               double cred = credResEntry.getCred( f, h );
               
               allGoodProb *= cred;
               allBadProb *= ( 1 - cred );
            }

            this.matchProb.set( m, allGoodProb, allBadProb );
         }
         
//         this.recomputeMatchProb = false;
//      }
      
      return this.matchProb;
   }
}


