我有3个枚举。我需要所有枚举实现我的方法
<noscript>
<meta http-equiv=refresh content='0; url=http://your.domain/noscript'>
</noscript>
当我实现BaseEnum时,我需要这个:
public interface BaseEnum {
public String getFontName();
public File getLocation();
}
但我有这个:
public enum TestEnum implements BaseEnum{
NEW(0),
NEW2(1);
private int value;
TestEnum (int value) {
this.value = value;
}
//I need
@Override
public String getFontName() {
return fontName;
}
@Override
public File getLocation() {
return location;
}
}
我喜欢this article
我想创建转换器
public enum ServerStatus implements BaseEnum{
NEW(0) {
@Override
public String getFontName() {
return null;
}
@Override
public File getLocation() {
return null;
}
},
NEW2(1) {
@Override
public String getFontName() {
return null;
}
@Override
public File getLocation() {
return null;
}
};
private int value;
ServerStatus(int value) {
this.value = value;
}
}
但我需要知道T需要方法而且我想要
public class StatusConverter<T> implements AttributeConverter<T,Integer> {
@Override
public Integer convertToDatabaseColumn(T t) {
return null;
}
@Override
public T convertToEntityAttribute(Integer integer) {
return null;
}
}
编辑:
implements AttributeConverter<T extends BaseEnum,Integer>
我的枚举
public interface BaseEnum<T> {
Integer getValue();
T parce(int id);
}
和转换器:
public enum ServerStatus implements BaseEnum<ServerStatus> {
NEW(0),
NEW2(1);
private int value;
ServerStatus(int value) {
this.value = value;
}
@Override
public Integer getValue() {
return value;
}
@Override
public ServerStatus parce(int id) {
ServerStatus status = null; // Default
for (ServerStatus item : ServerStatus.values()) {
if (item.getValue() == id) {
status = item;
break;
}
}
return status;
}
}