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
38 @Override
39 public int hashCode()
40 {
41 return this.hashCode;
42 }
43
44
45
46
47
48
49 private int calcHashCode()
50 {
51 final int prime = 31;
52 int result = 1;
53 result = (this.name.length() == 0) ? random.nextInt() : prime + this.name.hashCode();
54 return result;
55 }
56
57
58 @Override
59 @SuppressWarnings("checkstyle:needbraces")
60 public boolean equals(final Object obj)
61 {
62 if (this == obj)
63 return true;
64 if (obj == null)
65 return false;
66 if (getClass() != obj.getClass())
67 return false;
68 LogCategory other = (LogCategory) obj;
69 if (this.hashCode != other.hashCode)
70 return false;
71 return true;
72 }
73
74
75 @Override
76 public String toString()
77 {
78 return "LogCategory." + this.name;
79 }
80
81 }