0
有沒有更好的方法來做到這一點?使用嵌套枚舉
試圖爲插口創建一個附魔插件, 我喜歡在每個類中包含3類附魔以及各種各樣的附魔類型 。 第一次使用枚舉,謝謝。
public class EnchantmentType {
public enum Enchantments {
INK(Types.INK, Category.Adrian),
PUFFERFISH(Types.PUFFERFISH, Category.Adrian),
HOLYWATER(Types.HOLYWATER, Category.Adrian),
URCHIN(Types.URCHIN, Category.Adrian),
SEALORD(Types.SEALORD, Category.Adrian),
DYSPEPSIA(Types.DYSPEPSIA, Category.Adrian),
TOXIN(Types.TOXIN, Category.Adrian),
YPHOON(Types.YPHOON, Category.Adrian),
TSUNAMI(Types.TSUNAMI, Category.Adrian),
SPONGE(Types.SPONGE, Category.Adrian),
PRISTINE(Types.PRISTINE, Category.Adrian),
CLEANSE(Types.CLEANSE, Category.Adrian),
STARLIGHT(Types.STARLIGHT,Category.Zephira),
GUST(Types.GUST,Category.Zephira),
GRAVITY(Types.GRAVITY,Category.Zephira),
DETERMINATION(Types.DETERMINATION,Category.Zephira),
COURAGE(Types.COURAGE,Category.Zephira),
FOREGIVENESS(Types.FOREGIVENESS,Category.Zephira),
TORNADO(Types.TORNADO,Category.Zephira),
REDEMPTION(Types.REDEMPTION,Category.Zephira),
PEACEFUL(Types.PEACEFUL,Category.Zephira),
FLEE(Types.FLEE,Category.Zephira),
VIRTUE(Types.VIRTUE,Category.Zephira),
AMBIGUITY(Types.AMBIGUITY,Category.Zephira),
VALERE(Types.VALERE,Category.Zephira),
SANDSTORM(Types.SANDSTORM,Category.Zephira),
REKINDLE(Types.REKINDLE,Category.Zephira),
THERMALS(Types.THERMALS,Category.Zephira),
APPERTITE(Types.APPERTITE, Category.Partial);
Types eType;
Category eCat;
Enchantments(Types eType, EnchantmentType.Category eCat) {
this.eCat = eCat;
this.eType = eType;
}
Category getCategory() {
return this.eCat;
}
Types getType() {
return this.eType;
}
public enum Types {
INK, PUFFERFISH, HOLYWATER, URCHIN, SEALORD, DYSPEPSIA, TOXIN, YPHOON, TSUNAMI, SPONGE, PRISTINE, CLEANSE, STARLIGHT, GUST, GRAVITY, DETERMINATION, COURAGE, FOREGIVENESS, TORNADO, REDEMPTION, PEACEFUL, FLEE, VIRTUE, AMBIGUITY, VALERE, SANDSTORM, REKINDLE, THERMALS, APPERTITE;
}
}
Enchantments eType;
Category eCat;
public EnchantmentType(Enchantment eType) {
this.eType = eType.getType();
this.eCat = eType.getCategory();
}
public enum Category {
Adrian, Zephira, Partial;
}
}
在這樣的尺度下,數據驅動設計是一個不錯的選擇,特別是如果你想擴展它的話。 –
'Types'枚舉似乎是多餘的。 – shmosel
@shmosel我無法同意更多,這就是我發佈的原因。但沒有它,並增加了Enchantments枚舉的另一個參數,我無法找到一個方法來獲得枚舉的名稱,只有它的類別。 –