package org.bench4q.agent.datacollector.impl;

import java.lang.reflect.Field;

public class BehaviorStatusCodeResult {
	public long count;
	public long contentLength;
	public long minResponseTime;
	public long maxResponseTime;
	public long totalResponseTimeThisTime;
	public String contentType;

	public BehaviorStatusCodeResult(String contentType) {
		this.totalResponseTimeThisTime = 0;
		this.contentType = contentType;
		this.count = 0;
		this.contentLength = 0;
		this.minResponseTime = Long.MAX_VALUE;
		this.maxResponseTime = Long.MIN_VALUE;
	}

	public static boolean isSuccess(int statusCode) {
		return statusCode == 200;
	}

	public boolean equals(Object expectedObj) {
		Field[] fields = this.getClass().getDeclaredFields();
		boolean equal = true;
		try {
			for (Field field : fields) {
				field.setAccessible(true);
				if (field.getName().equals("contentType")) {
					field.get(expectedObj).equals(field.get(this));
					continue;
				}
				if (field.getLong(this) != field.getLong(expectedObj)) {
					System.out.println(field.getName()
							+ " is diferent, this is " + field.getLong(this)
							+ ", and the expected is "
							+ field.getLong(expectedObj));
					equal = false;
				}

			}
		} catch (Exception e) {
			e.printStackTrace();
			equal = false;

		}
		return equal;
	}
}