我有一个字符串数组( String[ < <
> ), 包含多个代表 XPath 查询的字符串对象。 这些查询是在设计时预先确定的。 此数组将传递给一个执行查询的对象, 然后返回一个有结果的 Map< String, ArrayList< String> & gt;
。
地图是这样绘制的:
{Query that originated the result, Results vector}
由于我必须取得这些结果,然后与他们一起进行一些工作,我需要了解个别询问,例如:
ArrayList<String> firstQueryResults = xpathResults.getObject(modelQueries[0]);
... logic pertaining only to the first query results ...
以整数取回结果(在第一个查询中为“0”), 对我来说似乎并不好, 所以我想知道是否有可能通过类似 enum 的常数来辨别结果, 以便更清楚:
... = xpathResults.getObject(QueryDictionary.MODEL_PACKAGE);
... = xpathResults.getObject(QueryDictionary.COMPONENT_PACKAGE);
OR
... = xpathResults.getObject(ModelQueries.PACKAGE);
... = xpathResults.getObject(ComponentQueries.PACKAGE);
I thought of using maps (i.e. Map<String, String>
as in Map {ID, Query}
) but I have still to reference the queries via an hardcoded string (e.g. "Package").
I also thought of using enums
but i have several query sets (Model, Component, ...) and I also need to get all the query in a set in a String[]
form in order to pass them to the object who performs the queries.