Java的:是否有一些工具,有哪些能够重构X [] []列出&LT;名单,LT; X&GT;&GT ;? [英] Java: Are there some tools out there which are able to refactor X[][] to List<List<X>>?
问题描述
我要重构现有的项目,这是不小。它含有大量的阵列声明和访问:结果
的(X为不可以泛型类型,它只是一个占位符)的。结果
声明: X []
和 X [] []
,结果
访问:的someArray [I]
和的someArray [I] [J]
我不得不重写所有使用泛型列表:结果
声明:列表&LT; X&GT;
和列表&LT;名单&LT; X&GT;&GT;
,结果
访问: someList.get(我)
和 someList.get(I)。获得(J)
我也找不到这样使自动化重构的可能,无论是在Eclipse中,也不在Netbeans的(都是最新的版本)。
是否有一些工具可以做这样的重构?
编辑:结果
该项目是非常的算法为主。内部实现的算法将不被感动。但暴露于外界必须改变。大多数类是以这样的方式进行,他们只持有阵列的一些结果数组或数组。
暴露于外界必须改变
块引用>在这种情况下,我不avise处处改变它,而是:
- 更改只返回类型的
公共
方法写一个实用方法,它看起来像:
公共静态列表&LT;名单,LT; X&GT;&GT; asList(X [] []×){
清单&LT; X []&GT;清单= Arrays.asList(X);
清单&LT;名单,LT; X&GT;&GT; newList =新的ArrayList&LT;名单,LT; X&GT;&GT;(则为list.size());
为(X [] xArray:名单){
newList.add(Arrays.asList(xArray));
}
返回列表;
}
使用该方法来改变每个
公共
方法的只有的结果。即。公开名单&LT;名单,LT; X&GT;&GT; someAlgorithm(...){
//算法code
X [] []导致= ...;
返回Utils.asList(结果); //只添加这行
}
I have to refactor an existing project, which is not that small. It contains a lot of arrays declarations and accesses:
(X is not a generic type, it's just a placeholder).
declarations:X[]
andX[][]
,
access:someArray[i]
andsomeArray[i][j]
.I have to rewrite everything to use generic Lists:
declaration:List<X>
andList<List<X>>
,
access:someList.get(i)
andsomeList.get(i).get(j)
.I couldn't find a possibility to automatize such refactoring, neither in Eclipse, nor in Netbeans (both newest versions).
Are there some tools available to do such refactoring?
EDIT:
The project is very algorithm-oriented. Internal implementation of algorithms will not be touched. But the exposure to the external world must be changed. Most classes are made in such a way, that they only hold some result arrays or arrays of arrays.解决方案exposure to the external world must be changed
In that case I'd avise not to change it everywhere, but to :
- change only return types of the
public
methodswrite an utility method, which looks like:
public static List<List<X>> asList(X[][] x) { List<X[]> list = Arrays.asList(x); List<List<X>> newList = new ArrayList<List<X>>(list.size()); for (X[] xArray : list) { newList.add(Arrays.asList(xArray)); } return list; }
use that method to change the only result of each
public
method. I.e.public List<List<X>> someAlgorithm(...) { // algorithm code X[][] result = ...; return Utils.asList(result); // add only this line }
这篇关于Java的:是否有一些工具,有哪些能够重构X [] []列出&LT;名单,LT; X&GT;&GT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!