Ticket #20167: NTV2GridShiftFile.patch

File NTV2GridShiftFile.patch, 3.3 KB (added by GerdP, 5 years ago)

my proposal for NTV2GridShiftFile

  • src/org/openstreetmap/josm/data/projection/datum/NTV2GridShiftFile.java

     
    164164    /**
    165165     * Create a tree of Sub Grids by adding each Sub Grid to its parent (where
    166166     * it has one), and returning an array of the top level Sub Grids
    167      * @param subGrid an array of all Sub Grids
     167     * @param subGrids an array of all Sub Grids
    168168     * @return an array of top level Sub Grids with lower level Sub Grids set.
    169169     */
    170     private static NTV2SubGrid[] createSubGridTree(NTV2SubGrid... subGrid) {
     170    private static NTV2SubGrid[] createSubGridTree(NTV2SubGrid... subGrids) {
    171171        int topLevelCount = 0;
    172172        Map<String, List<NTV2SubGrid>> subGridMap = new HashMap<>();
    173         for (int i = 0; i < subGrid.length; i++) {
    174             if ("NONE".equalsIgnoreCase(subGrid[i].getParentSubGridName())) {
     173        for (NTV2SubGrid subGrid : subGrids) {
     174            if ("NONE".equalsIgnoreCase(subGrid.getParentSubGridName())) {
    175175                topLevelCount++;
    176176            }
    177             subGridMap.put(subGrid[i].getSubGridName(), new ArrayList<NTV2SubGrid>());
     177            subGridMap.put(subGrid.getSubGridName(), new ArrayList<>());
    178178        }
    179179        NTV2SubGrid[] topLevelSubGrid = new NTV2SubGrid[topLevelCount];
    180180        topLevelCount = 0;
    181         for (int i = 0; i < subGrid.length; i++) {
    182             if ("NONE".equalsIgnoreCase(subGrid[i].getParentSubGridName())) {
    183                 topLevelSubGrid[topLevelCount++] = subGrid[i];
     181        for (NTV2SubGrid subGrid : subGrids) {
     182            if ("NONE".equalsIgnoreCase(subGrid.getParentSubGridName())) {
     183                topLevelSubGrid[topLevelCount++] = subGrid;
    184184            } else {
    185                 List<NTV2SubGrid> parent = subGridMap.get(subGrid[i].getParentSubGridName());
    186                 parent.add(subGrid[i]);
     185                List<NTV2SubGrid> parent = subGridMap.get(subGrid.getParentSubGridName());
     186                parent.add(subGrid);
    187187            }
    188188        }
    189189        NTV2SubGrid[] nullArray = new NTV2SubGrid[0];
    190         for (int i = 0; i < subGrid.length; i++) {
    191             List<NTV2SubGrid> subSubGrids = subGridMap.get(subGrid[i].getSubGridName());
     190        for (NTV2SubGrid subGrid : subGrids) {
     191            List<NTV2SubGrid> subSubGrids = subGridMap.get(subGrid.getSubGridName());
    192192            if (!subSubGrids.isEmpty()) {
    193193                NTV2SubGrid[] subGridArray = subSubGrids.toArray(nullArray);
    194                 subGrid[i].setSubGridArray(subGridArray);
     194                subGrid.setSubGridArray(subGridArray);
    195195            }
    196196        }
    197197        return topLevelSubGrid;
     
    262262     */
    263263    private static NTV2SubGrid getSubGrid(NTV2SubGrid[] topLevelSubGrid, double lon, double lat) {
    264264        NTV2SubGrid sub = null;
    265         for (int i = 0; i < topLevelSubGrid.length; i++) {
    266             sub = topLevelSubGrid[i].getSubGridForCoord(lon, lat);
     265        for (NTV2SubGrid topLevel : topLevelSubGrid) {
     266            sub = topLevel.getSubGridForCoord(lon, lat);
    267267            if (sub != null) {
    268268                break;
    269269            }