Java的:是否有一些工具,有哪些能够重构X [] []列出<名单,LT; X>&GT ;? [英] Java: Are there some tools out there which are able to refactor X[][] to List<List<X>>?

查看:91
本文介绍了Java的:是否有一些工具,有哪些能够重构X [] []列出<名单,LT; X>&GT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要重构现有的项目,这是不小。它含有大量的阵列声明和访问:结果
(X为不可以泛型类型,它只是一个占位符)的。结果
声明: X [] X [] [] ,结果
访问:的someArray [I] 的someArray [I] [J]

我不得不重写所有使用泛型列表:结果
声明:列表< X> 列表<名单< X>> ,结果
访问: someList.get(我) someList.get(I)。获得(J)

我也找不到这样使自动化重构的可能,无论是在Eclipse中,也不在Netbeans的(都是最新的版本)。

是否有一些工具可以做这样的重构?

编辑:结果
该项目是非常的算法为主。内部实现的算法将不被感动。但暴露于外界必须改变。大多数类是以这样的方式进行,他们只持有阵列的一些结果数组或数组。


解决方案

  

暴露于外界必须改变


在这种情况下,我不avise处处改变它,而是:


  • 更改只返回类型的公共方法

  • 写一个实用方法,它看起来像:

     公共静态列表<名单,LT; X>> asList(X [] []×){
        清单< X []>清单= Arrays.asList(X);
        清单<名单,LT; X>> newList =新的ArrayList<名单,LT; X>>(则为list.size());
        为(X [] xArray:名单){
            newList.add(Arrays.asList(xArray));
        }
        返回列表;
    }


  • 使用该方法来改变每个公共方法的只有的结果。即。

     公开名单<名单,LT; X>> 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[] and X[][],
access: someArray[i] and someArray[i][j].

I have to rewrite everything to use generic Lists:
declaration: List<X> and List<List<X>>,
access: someList.get(i) and someList.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 methods
  • write 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆