English 中文(简体)
Java 阵列: 识别矢量中含有常数的元素
原标题:Java Arrays: Identify elements of a vector with constants

我有一个字符串数组( 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.

最佳回答

您可以使用标记界面 :

public interface QueryType {
}

然后您的 enums 可以执行此接口 :

public enum ModelQueries implements QueryType {
   ...
}

public enum ComponentQueries implements QueryType {
   ...
}

诸如此类。

您的 getObject 方法可以接受类型 的参数。 您是否正在寻找类似的东西? 请告诉我如果我没有正确理解您的问题 。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签