1 package org.djutils.logger;
2
3 import java.util.Random;
4
5
6
7
8
9
10
11
12
13
14 public class LogCategory
15 {
16
17 private final String name;
18
19
20 private final int hashCode;
21
22
23 private static Random random = new Random(1L);
24
25
26 public static final LogCategory ALL = new LogCategory("ALL");
27
28
29
30
31 public LogCategory(final String name)
32 {
33 this.name = name == null ? "" : name;
34 this.hashCode = calcHashCode();
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.length() == 0) ? random.nextInt() : prime + this.name.hashCode();
53 return result;
54 }
55
56 @Override
57 @SuppressWarnings("checkstyle:needbraces")
58 public boolean equals(final Object obj)
59 {
60 if (this == obj)
61 return true;
62 if (obj == null)
63 return false;
64 if (getClass() != obj.getClass())
65 return false;
66 LogCategory other = (LogCategory) obj;
67 if (this.hashCode != other.hashCode)
68 return false;
69 return true;
70 }
71
72 @Override
73 public String toString()
74 {
75 return "LogCategory." + this.name;
76 }
77
78 }