1 package org.opentrafficsim.base.logger;
2
3 import java.util.Random;
4
5
6
7
8
9
10
11
12
13 public class LogCategory
14 {
15
16 private final String name;
17
18
19 private final int hashCode;
20
21
22 private static Random random = new Random(1L);
23
24
25 public static final LogCategory ALL = new LogCategory("ALL");
26
27
28
29
30 public LogCategory(final String name)
31 {
32 this.name = name == null ? "" : name;
33 this.hashCode = calcHashCode();
34 }
35
36
37 @Override
38 public int hashCode()
39 {
40 return this.hashCode;
41 }
42
43
44
45
46
47
48 private int calcHashCode()
49 {
50 final int prime = 31;
51 int result = 1;
52 result = (this.name == null || this.name.length() == 0) ? random.nextInt() : prime + this.name.hashCode();
53 return result;
54 }
55
56
57 @Override
58 @SuppressWarnings("checkstyle:needbraces")
59 public boolean equals(final Object obj)
60 {
61 if (this == obj)
62 return true;
63 if (obj == null)
64 return false;
65 if (getClass() != obj.getClass())
66 return false;
67 LogCategory other = (LogCategory) obj;
68 if (this.hashCode != other.hashCode)
69 return false;
70 return true;
71 }
72
73 }