1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.monitoring;
19
20 import org.apache.commons.monitoring.counters.Unit;
21
22 import static org.apache.commons.monitoring.counters.Unit.Time.NANOSECOND;
23
24
25
26
27
28
29
30 public class Role implements Comparable<Role> {
31 public static final Role WEB = new Role("web", NANOSECOND);
32 public static final Role JSP = new Role("jsp", NANOSECOND);
33 public static final Role JDBC = new Role("jdbc", NANOSECOND);
34 public static final Role PERFORMANCES = new Role("performances", NANOSECOND);
35 public static final Role FAILURES = new Role("failures", Unit.UNARY);
36
37 private final String name;
38 private final Unit unit;
39
40 public Role(String name, Unit unit) {
41 if (name == null) {
42 throw new IllegalArgumentException("A role name is required");
43 }
44 if (unit == null) {
45 throw new IllegalArgumentException("A role unit is required");
46 }
47 this.name = name;
48 this.unit = unit;
49 }
50
51
52
53
54 public String getName() {
55 return name;
56 }
57
58
59
60
61 public Unit getUnit() {
62 return unit;
63 }
64
65
66
67
68 @Override
69 public int hashCode() {
70 return name.hashCode();
71 }
72
73 @Override
74 public boolean equals( Object o )
75 {
76 if ( this == o )
77 {
78 return true;
79 }
80 if ( o == null || getClass() != o.getClass() )
81 {
82 return false;
83 }
84
85 Role role = (Role) o;
86
87 if ( !name.equals( role.name ) )
88 {
89 return false;
90 }
91
92 return true;
93 }
94
95
96
97
98 public int compareTo(final Role o) {
99 return name.compareTo(o.name);
100 }
101
102 @Override
103 public String toString()
104 {
105 final StringBuilder sb = new StringBuilder( "Role{" );
106 sb.append( "name='" ).append( name ).append( '\'' );
107 sb.append( ", unit=" ).append( unit );
108 sb.append( '}' );
109 return sb.toString();
110 }
111 }