Collector.java 1.1 KB
package se.lil.jm;

import java.util.ArrayList;

class Collector {
	ArrayList<LongDelta> listLong = new ArrayList<LongDelta>();
	
	public void updateValue(Long ts, String name, Long value) {
		LongDelta myDelta = null;
		for(int x = 0; x<listLong.size() && myDelta == null; x++) {
			if(name.equals(listLong.get(x).name)) {
				myDelta = listLong.get(x);
			}
		}
		if(myDelta != null) {
			myDelta.update(ts, value);
		} else {
			myDelta = new LongDelta(ts, value);
			listLong.add(myDelta);
		}
	}
	
	public long getCurrentValue(String name) {
		LongDelta myDelta = null;
		for(int x = 0; x<listLong.size() && myDelta == null; x++) {
			if(name.equals(listLong.get(x).name)) {
				myDelta = listLong.get(x);
			}
		}
		if(myDelta != null)
			return myDelta.getCurrentValue();
		else
			return 0;
	}
	
	public double getPerSecValue(String name) throws Throwable {
		LongDelta myDelta = null;
		for(int x = 0; x<listLong.size() && myDelta == null; x++) {
			if(name.equals(listLong.get(x).name)) {
				myDelta = listLong.get(x);
			}
		}
		if(myDelta != null)
			return myDelta.getPerSecondValue();
		else
			return 0;
	}
}