woolfel     2004/05/27 19:38:40

  Modified:    src/jorphan/org/apache/jorphan/math StatCalculator.java
  Added:       src/jorphan/org/apache/jorphan/math NumberComparator.java
  Log:
  adding a new class for sorting Number[] arrays. Also added a method

  to get distribution data

  

  peter lin
  
  Revision  Changes    Path
  1.4       +31 -1     
jakarta-jmeter/src/jorphan/org/apache/jorphan/math/StatCalculator.java
  
  Index: StatCalculator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/jorphan/org/apache/jorphan/math/StatCalculator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StatCalculator.java       13 May 2004 13:58:53 -0000      1.3
  +++ StatCalculator.java       28 May 2004 02:38:40 -0000      1.4
  @@ -21,6 +21,8 @@
   import java.io.Serializable;
   import java.util.ArrayList;
   import java.util.Collections;
  +import java.util.HashMap;
  +import java.util.Iterator;
   import java.util.List;
   
   import junit.framework.TestCase;
  @@ -99,6 +101,34 @@
       public Number getPercentPoint(double percent)
       {
           return (Number) values.get((int)(values.size() * percent));
  +    }
  +    
  +    /**
  +     * The method has a limit of 1% as the finest granularity. We do
  +     * this to make sure we get a whole number for iterating.
  +     * @param percentRange
  +     * @return
  +     */
  +    public synchronized HashMap getDistribution(){
  +     HashMap items = new HashMap();
  +     Iterator itr = this.values.iterator();
  +             Long n = new Long(0);
  +             Number[] dis = new Number[0];
  +     while(itr.hasNext()){
  +             Long nx = (Long)itr.next();
  +             if (items.containsKey(nx)){
  +                     dis = (Number[])items.get(nx);
  +                             dis[1] = new Integer(dis[1].intValue() + 1);
  +                             items.put(nx,dis);
  +             } else {
  +                     n = nx;
  +                     dis = new Number[2];
  +                     dis[0] = n;
  +                     dis[1] = new Integer(1);
  +                     items.put(n,dis);
  +             }
  +     }
  +     return items;
       }
       
       public double getMean()
  
  
  
  1.1                  
jakarta-jmeter/src/jorphan/org/apache/jorphan/math/NumberComparator.java
  
  Index: NumberComparator.java
  ===================================================================
  /*
   * Created on May 25, 2004
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.jorphan.math;
  
  import java.util.Comparator;
  
  /**
   * @author pete
   *
   * To change the template for this generated type comment go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  public class NumberComparator implements Comparator {
  
        /**
         * 
         */
        public NumberComparator() {
                super();
        }
  
        /* (non-Javadoc)
         * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
         */
        public int compare(Object val1, Object val2) {
                Number[] n1 = (Number[])val1;
                Number[] n2 = (Number[])val2;
                if (n1[0].longValue() < n2[0].longValue()){
                        return -1;
                } else if (n1[0].longValue() == n2[0].longValue()){
                        return 0;
                } else{
                        return 1;
                }
        }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to