Java: Are there any tools that can reorganize X [] [] into List <List <X>>?

I need to reorganize an existing project, which is not so small. It contains a lot of declarations and access to arrays:
(X is not a generic type, it's just a placeholder).
advertisements: X[]and X[][],
access: someArray[i]and someArray[i][j].

I need to rewrite everything in order to use shared lists:
declaration: List<X>and List<List<X>>,
access: someList.get(i)and someList.get(i).get(j).

I could not find a way to automate such refactoring, either in Eclipse or in Netbeans (both the latest versions).

Are there any tools for such refactoring?

EDIT:
The project is very algorithm oriented. The internal implementation of the algorithms will not be affected. But the impact of the outside world must be changed. Most classes are created in such a way that they contain only arrays of results or arrays of arrays.

+3
source share
2 answers

the impact of the outside world needs to be changed

In this case, I would not change it everywhere, but:

  • change only return method types public
  • write a utility method that looks like this:

    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 this method to change the single result of each method public. I.e.

    public List<List<X>> someAlgorithm(...) {
        // algorithm code
        X[][] result = ...;
        return Utils.asList(result); // add only this line
    }
    
+3
source
  • , , , .

  • , (, , ).

, 10 , 10, .

- . , radix. , , .

, , , .

+2

Source: https://habr.com/ru/post/1730611/


All Articles