Skip to content

Commit e4d064b

Browse files
Add comparators
1 parent 504c00b commit e4d064b

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

src/main/java/com/cloudbees/syslog/Facility.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import javax.annotation.Nonnull;
1919
import javax.annotation.Nullable;
20+
import java.util.Comparator;
2021
import java.util.HashMap;
2122
import java.util.Map;
2223

@@ -27,7 +28,7 @@
2728
*
2829
* @author <a href="mailto:[email protected]">Cyrille Le Clerc</a>
2930
*/
30-
public enum Facility {
31+
public enum Facility implements Comparable<Facility> {
3132

3233
/**
3334
* kernel messages, numerical code 0.
@@ -153,7 +154,7 @@ private Facility(int numericalCode, @Nonnull String label) {
153154
}
154155

155156
/**
156-
* @param label Syslog facility numerical code
157+
* @param numericalCode Syslog facility numerical code
157158
* @return Syslog facility, not {@code null}
158159
* @throws IllegalArgumentException the given numericalCode is not a valid Syslog facility numerical code
159160
*/
@@ -196,4 +197,16 @@ public int numericalCode() {
196197
public String label() {
197198
return label;
198199
}
200+
201+
/**
202+
* Compare on {@link Facility#numericalCode()}
203+
*/
204+
public static Comparator<Facility> comparator() {
205+
return new Comparator<Facility>() {
206+
@Override
207+
public int compare(Facility f1, Facility f2) {
208+
return Integer.compare(f1.numericalCode, f2.numericalCode);
209+
}
210+
};
211+
}
199212
}

src/main/java/com/cloudbees/syslog/Severity.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import javax.annotation.Nonnull;
1919
import javax.annotation.Nullable;
20+
import java.util.Comparator;
2021
import java.util.HashMap;
2122
import java.util.Map;
2223

@@ -123,5 +124,17 @@ public int numericalCode() {
123124
public String label() {
124125
return label;
125126
}
127+
128+
/**
129+
* Compare on {@link Severity#numericalCode()}
130+
*/
131+
public static Comparator<Severity> comparator() {
132+
return new Comparator<Severity>() {
133+
@Override
134+
public int compare(Severity s1, Severity s2) {
135+
return Integer.compare(s1.numericalCode, s2.numericalCode);
136+
}
137+
};
138+
}
126139
}
127140

src/main/java/com/cloudbees/syslog/integration/jul/util/LevelHelper.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
public class LevelHelper {
3737

3838
public final static List<Level> levels = Collections.unmodifiableList(Arrays.asList(Level.OFF, Level.SEVERE, Level.WARNING, Level.INFO, Level.CONFIG,
39-
Level.FINE, Level.FINEST, Level.ALL));
39+
Level.FINE, Level.FINER, Level.FINEST, Level.ALL));
4040

4141
public final static Map<String, Level> levelsByName;
4242
public final static Map<Integer, Level> levelsByValue;
@@ -81,4 +81,16 @@ public static Level findLevel(@Nonnull String name) {
8181
public static Severity toSeverity(@Nullable Level level) {
8282
return julLevelToSyslogSeverity.get(level);
8383
}
84+
85+
/**
86+
* Compare on {@link java.util.logging.Level#intValue()}
87+
*/
88+
public static Comparator<Level> comparator() {
89+
return new Comparator<Level>() {
90+
@Override
91+
public int compare(Level l1, Level l2) {
92+
return Integer.compare(l1.intValue(), l2.intValue());
93+
}
94+
};
95+
}
8496
}

0 commit comments

Comments
 (0)