-3
我正在尋找使用HashMap來存儲Block類中的屬性,以使整個屬性過程更加高效和靈活。我到目前爲止基本上是一個BlockProperty類,它將數據「內部」存儲爲一個字符串,並通過檢查「屬性類型」的值,使用正確的解析器(double,float,int,boolean等)進行解析一個最終數組作爲列表的靜態類。使用HashMap來存儲所有基元類型的屬性
我希望能夠請求某個屬性的類中的值,它會返回其適當的原始類型的值。
屬性類型列表 - 可以通過獲取查找索引和返回索引值的方法以任何順序重新排列。
protected static final String[] type = {"int","float","long","short","boolean","String","double","Object"};
Block Property If-statements。
public Object getAsPrimitiveData()
{
if(!isObjectType)
{
if(propertyType == BlockPropertyTypes.getIndexWithType("String"))
return internalPropertyData;
else if(propertyType == BlockPropertyTypes.getIndexWithType("int"))
return processIntType();
else if(propertyType == BlockPropertyTypes.getIndexWithType("short"))
return processShortType();
else if(propertyType == BlockPropertyTypes.getIndexWithType("long"))
return processLongType();
else if(propertyType == BlockPropertyTypes.getIndexWithType("boolean"))
return processBooleanType();
else if(propertyType == BlockPropertyTypes.getIndexWithType("float"))
return processFloatType();
else
throw new IllegalArgumentException("Property type is invalid.");
}
過程****類型全部調用類似於下面的方法,但針對它們各自的類型進行修改。 (額外輸出用於調試)
public float processFloatType()
{
try
{
return Float.parseFloat(internalPropertyData);
}catch(Exception e)
{
Notifier.printException(e);
Notifier.cwarn("Property Type and Property Data do not match types! " + this.propertyType + " == " + BlockPropertyTypes.getIndexWithType("float") + "?? returning -1;");
return -1;
}
}
郵編:我們不介意這裏的讀者。 –
我的歉意。讓我知道你是否需要更多 –
我們現在需要的是一個實際的問題。 – EJP