Initial commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package com.mzh.library.entity;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public enum Role {
|
||||
ADMINISTRATOR("administrator", "Administrator"),
|
||||
LIBRARIAN("librarian", "Librarian"),
|
||||
READER("reader", "Reader");
|
||||
|
||||
private final String code;
|
||||
private final String displayName;
|
||||
|
||||
Role(String code, String displayName) {
|
||||
this.code = code;
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public static Role fromCode(String code) {
|
||||
if (code == null || code.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("Role code is required");
|
||||
}
|
||||
|
||||
String normalized = code.trim().toLowerCase(Locale.ROOT);
|
||||
for (Role role : values()) {
|
||||
if (role.code.equals(normalized)) {
|
||||
return role;
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Unsupported role code: " + code);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user