01: /*
02: * Created on 08.06.2005
03: *
04: * TODO To change the template for this generated file go to
05: * Window - Preferences - Java - Code Style - Code Templates
06: */
07: package de.schlund.pfixxml.perflogging;
08:
09: import java.util.ArrayList;
10: import java.util.HashMap;
11: import java.util.List;
12: import java.util.Map;
13:
14: /**
15: * @author jh
16: *
17: */
18: public class IntervalFactory {
19: private static IntervalFactory instance = new IntervalFactory();
20: private int interval_size = 20;
21: private int increase_factor = 2;
22: private HashMap<String, List<Interval>> interval_category_map;
23:
24: private IntervalFactory() {
25: interval_category_map = new HashMap<String, List<Interval>>();
26: }
27:
28: public static IntervalFactory getInstance() {
29: return instance;
30: }
31:
32: public List<Interval> getIntervalForCategory(String category) {
33: if (!interval_category_map.containsKey(category)) {
34: List<Interval> intervals = createInterval();
35: interval_category_map.put(category, intervals);
36: }
37: return interval_category_map.get(category);
38: }
39:
40: Map<String, List<Interval>> getAllIntervals() {
41: return interval_category_map;
42: }
43:
44: private List<Interval> createInterval() {
45: List<Interval> intervals = new ArrayList<Interval>(
46: interval_size);
47: intervals.add(0, new Interval(0, 1));
48: intervals.add(1, new Interval(1, increase_factor));
49:
50: for (int i = 2; i < interval_size - 1; i++) {
51: long pre_until = (intervals.get(i - 1)).getUntil();
52: intervals.add(i, new Interval(pre_until, pre_until
53: * increase_factor));
54: }
55:
56: intervals.add(interval_size - 1, new Interval((intervals
57: .get(interval_size - 2)).getUntil(), Long.MAX_VALUE));
58:
59: /* for(int i=0; i<interval_size; i++) {
60: System.out.print(i+":->"+intervals.get(i)+"|");
61: System.out.println();
62: }*/
63: return intervals;
64: }
65:
66: }
|