package org.centralperf.model;

import java.io.Serializable;
import java.util.Iterator;

public class RunDetailGraphRc implements Serializable{
	
	private static final long serialVersionUID = -5234221824650236119L;
	
	private long nbHttp1xx;
	private long nbHttp2xx;
	private long nbHttp3xx;
	private long nbHttp4xx;
	private long nbHttp5xx;
	private long nbHttpErr;
	private long nbSamples;

	public RunDetailGraphRc(Iterator<Object[]> datas) {
		Object[] row =null;
		while ( datas.hasNext() ) {
			row = (Object[]) datas.next();
			String codeValue = row[0] != null ? row[0].toString() : null;
			String codeValueCount = row[1] != null ? row[1].toString() : null;
			if(codeValue != null && codeValueCount != null)
				this.setNbHttpXXX(codeValue, Long.parseLong(codeValueCount));
		}
	}
	
	public void setNbHttpXXX(String codeFirstChar, long count){
		if(codeFirstChar.length() > 0){
			switch (codeFirstChar.charAt(0)) {
				case '1':this.nbHttp1xx=count;break;
				case '2':this.nbHttp2xx=count;break;
				case '3':this.nbHttp3xx=count;break;
				case '4':this.nbHttp4xx=count;break;
				case '5':this.nbHttp5xx=count;break;
				default: this.nbHttpErr=count;break;
			}
		}
		nbSamples=nbHttp1xx+nbHttp2xx+nbHttp3xx+nbHttp4xx+nbHttp5xx+nbHttpErr;
	}
	
	public long getNbHttp1xx() {return this.nbHttp1xx;}
	public long getNbHttp2xx() {return this.nbHttp2xx;}
	public long getNbHttp3xx() {return this.nbHttp3xx;}
	public long getNbHttp4xx() {return this.nbHttp4xx;}
	public long getNbHttp5xx() {return this.nbHttp5xx;}
	public long getNbHttpErr() {return this.nbHttpErr;}
	public long getNbSamples() {return this.nbSamples;}
	
	public float getHttp1xxRatio() {return (this.nbHttp1xx*100/this.nbSamples);}
	public float getHttp2xxRatio() {return (this.nbHttp2xx*100/this.nbSamples);}
	public float getHttp3xxRatio() {return (this.nbHttp3xx*100/this.nbSamples);}
	public float getHttp4xxRatio() {return (this.nbHttp4xx*100/this.nbSamples);}
	public float getHttp5xxRatio() {return (this.nbHttp5xx*100/this.nbSamples);}
	public float getHttpErrRatio() {return (this.nbHttpErr*100/this.nbSamples);}
	
	@Override
	public String toString() {
		return "SAMPLES["+this.nbSamples+"] 1xx["+this.nbHttp1xx+"] 2xx["+this.nbHttp2xx+"] 3xx["+this.nbHttp3xx+"] 4xx["+this.nbHttp4xx+"] 5xx["+this.nbHttp5xx+"] Err["+this.nbHttpErr+"]";
	}
}

@@ -1658,32 +1658,54 @@
 atio() %7Breturn (
+this.nbSamples != 0 ? 
 this.nbHttp1xx*1
@@ -1713,32 +1713,36 @@
 0/this.nbSamples
+ : 0
 );%7D%0A%09public floa
@@ -1771,24 +1771,45 @@
 eturn (this.
+nbSamples != 0 ?this.
 nbHttp2xx*10
@@ -1816,32 +1816,36 @@
 0/this.nbSamples
+ : 0
 );%7D%0A%09public floa
@@ -1874,24 +1874,45 @@
 eturn (this.
+nbSamples != 0 ?this.
 nbHttp3xx*10
@@ -1919,32 +1919,36 @@
 0/this.nbSamples
+ : 0
 );%7D%0A%09public floa
@@ -1977,24 +1977,45 @@
 eturn (this.
+nbSamples != 0 ?this.
 nbHttp4xx*10
@@ -2022,32 +2022,36 @@
 0/this.nbSamples
+ : 0
 );%7D%0A%09public floa
@@ -2080,24 +2080,45 @@
 eturn (this.
+nbSamples != 0 ?this.
 nbHttp5xx*10
@@ -2129,24 +2129,28 @@
 is.nbSamples
+ : 0
 );%7D%0A%09public 
@@ -2183,24 +2183,45 @@
 eturn (this.
+nbSamples != 0 ?this.
 nbHttpErr*10
@@ -2236,16 +2236,20 @@
 bSamples
+ : 0
 );%7D%0A%09%0A%09@

Fix an error where there are not yet any samples