Mercurial > hg > blitz_stable
comparison src/org/dancres/blitz/stats/OpStat.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 package org.dancres.blitz.stats; | |
2 | |
3 /** | |
4 A class which tracks the number of times a particular operation has been | |
5 performed against a particular type. | |
6 */ | |
7 public class OpStat implements Stat, StatGenerator { | |
8 | |
9 public static final int TAKES = 1; | |
10 public static final int WRITES = 2; | |
11 public static final int READS = 3; | |
12 | |
13 private String theType; | |
14 private long theCount; | |
15 private int theOp; | |
16 | |
17 private long theId = StatGenerator.UNSET_ID; | |
18 | |
19 public OpStat(String aType, int anOp) { | |
20 theType = aType; | |
21 theOp = anOp; | |
22 } | |
23 | |
24 private OpStat(long anId, String aType, int anOp, long aCount) { | |
25 theId = anId; | |
26 theType = aType; | |
27 theOp = anOp; | |
28 theCount = aCount; | |
29 } | |
30 | |
31 public void setId(long anId) { | |
32 theId = anId; | |
33 } | |
34 | |
35 public long getId() { | |
36 return theId; | |
37 } | |
38 | |
39 public String getType() { | |
40 return theType; | |
41 } | |
42 | |
43 public int getOp() { | |
44 return theOp; | |
45 } | |
46 | |
47 public long getCount() { | |
48 return theCount; | |
49 } | |
50 | |
51 public synchronized void incCount() { | |
52 ++theCount; | |
53 } | |
54 | |
55 public synchronized Stat generate() { | |
56 OpStat myStat = new OpStat(theId, theType, theOp, theCount); | |
57 | |
58 return myStat; | |
59 } | |
60 | |
61 public String getOpTypeAsString() { | |
62 switch(theOp) { | |
63 case TAKES : { | |
64 return "Takes"; | |
65 } | |
66 | |
67 case WRITES : { | |
68 return "Writes"; | |
69 } | |
70 | |
71 case READS : { | |
72 return "Reads"; | |
73 } | |
74 | |
75 default : { | |
76 return "Unknown"; | |
77 } | |
78 } | |
79 } | |
80 | |
81 public String toString() { | |
82 String myOp = getOpTypeAsString(); | |
83 | |
84 return myOp + ":" + theType + " = " + theCount + " (" + theId + ")"; | |
85 } | |
86 } |