Changeset 19307 in josm for trunk


Ignore:
Timestamp:
2025-02-03T20:59:54+01:00 (7 days ago)
Author:
taylor.smock
Message:

Fix most new PMD issues

It would be better to use the newer switch syntax introduced in Java 14 (JEP 361),
but we currently target Java 11+. When we move to Java 17, this should be
reverted and the newer switch syntax should be used.

Location:
trunk
Files:
41 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/TagInfoExtract.java

    r19184 r19307  
    122122                script.new ExternalPresets().run();
    123123                break;
    124             default:
    125                 throw new IllegalStateException("Invalid type " + script.options.mode);
    126124        }
    127125        if (!script.options.noexit) {
  • trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java

    r19050 r19307  
    233233            setHelpId(ht("/Action/ZoomToNext"));
    234234            break;
    235         default:
    236             throw new IllegalArgumentException("Unknown mode: " + mode);
    237235        }
    238236        installAdapters();
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java

    r19297 r19307  
    247247            newCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
    248248            break;
    249         default: throw new AssertionError();
    250249        }
    251250        if (newCursor != null) {
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r19050 r19307  
    6969/**
    7070 * Move is an action that can move all kind of OsmPrimitives (except keys for now).
    71  *
     71 * <p>
    7272 * If an selected object is under the mouse when dragging, move all selected objects.
    7373 * If an unselected object is under the mouse when dragging, it becomes selected
    7474 * and will be moved.
    7575 * If no object is under the mouse, move all selected objects (if any)
    76  *
     76 * <p>
    7777 * On Mac OS X, Ctrl + mouse button 1 simulates right click (map move), so the
    7878 * feature "selection remove" is disabled on this platform.
     
    402402     * Look, whether any object is selected. If not, select the nearest node.
    403403     * If there are no nodes in the dataset, do nothing.
    404      *
     404     * <p>
    405405     * If the user did not press the left mouse button, do nothing.
    406      *
     406     * <p>
    407407     * Also remember the starting position of the movement and change the mouse
    408408     * cursor to movement.
     
    465465            break;
    466466        case SELECT:
    467         default:
    468467            if (!(ctrl && PlatformManager.isPlatformOsx())) {
    469468                // start working with rectangle or lasso
  • trunk/src/org/openstreetmap/josm/command/SplitWayCommand.java

    r19199 r19307  
    367367        }
    368368
    369         MissingMemberStrategy missingMemberStrategy;
     369        MissingMemberStrategy missingMemberStrategy = USER_ABORTED; // default case
    370370        if (relationsNeedingMoreMembers.isEmpty()) {
    371371            // The split can be performed without any extra downloads.
     
    393393                    break;
    394394                case ABORT:
    395                 default:
    396395                    missingMemberStrategy = USER_ABORTED;
    397396                    break;
     
    419418                break;
    420419            case USER_ABORTED:
    421             default:
    422420                return Optional.empty();
    423421            }
  • trunk/src/org/openstreetmap/josm/data/APIDataSet.java

    r16913 r19307  
    2626import org.openstreetmap.josm.data.osm.RelationMember;
    2727import org.openstreetmap.josm.data.osm.Way;
    28 import org.openstreetmap.josm.tools.Logging;
    2928import org.openstreetmap.josm.tools.Utils;
    3029
     
    105104                    case UPDATE: toUpdate.add(osm); break;
    106105                    case DELETE: toDelete.add(osm); break;
    107                     default: Logging.trace("Ignored primitive {0} -> {1}", osm, op);
     106                    // Used to have a default case for logging: Logging.trace("Ignored primitive {0} -> {1}", osm, op);
    108107                }
    109108            }
     
    228227     * Adjusts the upload order for new relations. Child relations are uploaded first,
    229228     * parent relations second.
    230      *
     229     * <p>
    231230     * This method detects cyclic dependencies in new relation. Relations with cyclic
    232231     * dependencies can't be uploaded.
  • trunk/src/org/openstreetmap/josm/data/Bounds.java

    r18871 r19307  
    278278                break;
    279279            case MINLAT_MINLON_MAXLAT_MAXLON:
    280             default:
    281280                this.minLat = initLat(values[0], roundToOsmPrecision);
    282281                this.minLon = initLon(values[1], roundToOsmPrecision);
  • trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java

    r19050 r19307  
    216216            case CANCELED:
    217217                tile.loadingCanceled();
     218                break;
     219            default: // This should be removed when we move to Java 17+
    218220                // do nothing
    219221            }
  • trunk/src/org/openstreetmap/josm/data/osm/SimplePrimitiveId.java

    r18829 r19307  
    167167            case RELATION:
    168168                return "r" + primitive.getUniqueId();
     169            default:
     170                throw new IllegalArgumentException("Unknown primitive type: " + primitive.getType());
    169171        }
    170         throw new IllegalArgumentException("Unknown primitive type: " + primitive.getType());
    171172    }
    172173}
  • trunk/src/org/openstreetmap/josm/data/osm/pbf/Blob.java

    r18877 r19307  
    9898            case zlib:
    9999                return new InflaterInputStream(bais);
    100             default:
    101                 throw new IOException("unknown compression type is not currently supported: " + this.compressionType.name());
    102100        }
     101        throw new IOException("unknown compression type is not currently supported: " + this.compressionType.name());
    103102    }
    104103}
  • trunk/src/org/openstreetmap/josm/data/projection/proj/LambertAzimuthalEqualArea.java

    r16627 r19307  
    122122                ymf = rq / dd;
    123123                break;
    124             default:
    125                 throw new AssertionError(mode);
    126124        }
    127125    }
     
    133131        final double sinphi = Math.sin(phi);
    134132        double q = qsfn(sinphi);
    135         final double sinb, cosb, b, c, x, y;
     133        double sinb, cosb, b, c, x, y;
     134        // Set c, x, y to 0 until we move to Java 17 where we can use a better switch expression.
     135        c = 0;
     136        x = 0;
     137        y = 0;
    136138        switch (mode) {
    137139            case OBLIQUE:
     
    173175                }
    174176                break;
    175             default:
    176                 throw new AssertionError(mode);
    177177        }
    178178        if (Math.abs(c) < EPSILON_LATITUDE) {
     
    192192            case SOUTH_POLE:
    193193                return invprojectNS(x, y);
    194             default:
    195                 throw new AssertionError(mode);
    196         }
     194        }
     195        throw new AssertionError(mode);
    197196    }
    198197
  • trunk/src/org/openstreetmap/josm/data/validation/Test.java

    r18960 r19307  
    4242 * @author frsantos
    4343 */
     44@SuppressWarnings("PMD.UnitTestShouldUseTestAnnotation")
    4445public class Test implements OsmPrimitiveVisitor {
    4546
  • trunk/src/org/openstreetmap/josm/data/validation/routines/DomainValidator.java

    r19229 r19307  
    18681868        case LOCAL_RO:
    18691869            throw new IllegalArgumentException("Cannot update the table: " + table);
    1870         default:
    1871             throw new IllegalArgumentException("Unexpected enum value: " + table);
    18721870        }
    18731871    }
     
    18811879     */
    18821880    public static String[] getTLDEntries(ArrayType table) {
    1883         final String[] array;
     1881        String[] array = null;
    18841882        switch (table) {
    18851883        case COUNTRY_CODE_MINUS:
     
    19071905            array = LOCAL_TLDS;
    19081906            break;
    1909         default:
     1907        }
     1908        if (array == null) {
    19101909            throw new IllegalArgumentException("Unexpected enum value: " + table);
    19111910        }
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/MultiValueCellRenderer.java

    r19050 r19307  
    132132                    decision.getChosenValue(), decision.getKey());
    133133            break;
     134        default:
     135            throw new AssertionError("Unknown decision type in renderToolTipText(): " + decision.getDecisionType());
    134136        }
    135137        setToolTipText(toolTipText);
     
    171173            renderValue(decision);
    172174            return cbDecisionRenderer;
     175
     176        default:
     177            return this;
    173178        }
    174         return this;
    175179    }
    176180}
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictDecisionType.java

    r15729 r19307  
    3131                return tr("Keep");
    3232            case UNDECIDED:
    33             default:
    3433                return tr("Undecided");
    3534        }
     35        return tr("Undecided");
    3636    }
    3737
     
    4343                return tr("Keep this relation member for the target object");
    4444            case UNDECIDED:
    45             default:
    4645                return tr("Not decided yet");
    4746        }
     47        return tr("Not decided yet");
    4848    }
    4949}
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolverColumnModel.java

    r15729 r19307  
    6666                    comp.setBackground(ConflictColors.BGCOLOR_MEMBER_REMOVE.get());
    6767                    break;
     68                default: throw new AssertionError("Unknown decision type: " + model.getDecision(row).getDecision());
    6869                }
    6970            }
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolverModel.java

    r19050 r19307  
    3131/**
    3232 * This model manages a list of conflicting relation members.
    33  *
     33 * <p>
    3434 * It can be used as {@link javax.swing.table.TableModel}.
    3535 */
     
    113113        case 4: /* decision keep */ return RelationMemberConflictDecisionType.KEEP == d.getDecision();
    114114        case 5: /* decision remove */ return RelationMemberConflictDecisionType.REMOVE == d.getDecision();
    115         }
    116         return null;
     115        default: return null;
     116        }
    117117    }
    118118
     
    212212    /**
    213213     * Prepare the default decisions for the current model.
    214      *
     214     * <p>
    215215     * Keep/delete decisions are made if every member has the same role and the members are in consecutive order within the relation.
    216216     * For multiple occurrences those conditions are tested stepwise for each occurrence.
     
    222222    /**
    223223     * Prepare the default decisions for the current model.
    224      *
     224     * <p>
    225225     * Keep/delete decisions are made if every member has the same role and the members are in consecutive order within the relation.
    226226     * For multiple occurrences those conditions are tested stepwise for each occurrence.
     
    383383                    break;
    384384                case UNDECIDED:
     385                default:
    385386                    // FIXME: this is an error
    386387                    break;
     
    419420                break;
    420421            case UNDECIDED:
     422            default:
    421423                // FIXME: handle error
    422424            }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictResolutionDialog.java

    r19050 r19307  
    197197                        options[1]
    198198                );
    199                 switch (ret) {
    200                 case JOptionPane.YES_OPTION:
     199                if (ret == JOptionPane.YES_OPTION) {
    201200                    buttonAction(1, evt);
    202                     break;
    203                 default:
     201                } else {
    204202                    return;
    205203                }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentTableCellRenderer.java

    r19050 r19307  
    2626        case UPDATED: setText(tr("Updated")); break;
    2727        case DELETED: setText(tr("Deleted")); break;
     28        default: throw new IllegalStateException("Unexpected value: " + type);
    2829        }
    2930        setToolTipText(null);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentTableModel.java

    r19050 r19307  
    114114    @Override
    115115    public Object getValueAt(int row, int col) {
    116         switch (col) {
    117         case 0: return data.get(row).getModificationType();
    118         default: return data.get(row).getPrimitive();
     116        if (col == 0) {
     117            return data.get(row).getModificationType();
    119118        }
     119        return data.get(row).getPrimitive();
    120120    }
    121121
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/query/ChangesetQueryDialog.java

    r19050 r19307  
    204204                        return;
    205205                    }
     206                default:
     207                    throw new IllegalStateException("Unexpected value: " + tpQueryPanels.getSelectedIndex());
    206208                }
    207209                setCanceled(false);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r19279 r19307  
    248248        case 2:
    249249            return getWayConnection(rowIndex);
    250         }
    251         // should not happen
    252         return null;
     250        default:
     251            // should not happen
     252            return null;
     253        }
    253254    }
    254255
  • trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java

    r19050 r19307  
    135135                switch (dialog.getUserAction()) {
    136136                    case PROCEED: return true;
    137                     case CANCEL:
    138                     default: return false;
     137                    case CANCEL: return false;
    139138                }
    140139            }
     
    379378        public void cancel() {
    380379            switch (model.getMode()) {
    381             case EDITING_DATA: cancelWhenInEditingModel();
     380            case EDITING_DATA:
     381                cancelWhenInEditingModel();
    382382                break;
    383             case UPLOADING_AND_SAVING: cancelSafeAndUploadTask();
     383            case UPLOADING_AND_SAVING:
     384                cancelSafeAndUploadTask();
    384385                break;
     386            default:
     387                throw new IllegalStateException("Unexpected value: " + model.getMode());
    385388            }
    386389        }
     
    428431                Mode mode = (Mode) evt.getNewValue();
    429432                switch (mode) {
    430                 case EDITING_DATA: setEnabled(true);
    431                     break;
    432                 case UPLOADING_AND_SAVING: setEnabled(false);
    433                     break;
     433                case EDITING_DATA:
     434                    setEnabled(true);
     435                    break;
     436                case UPLOADING_AND_SAVING:
     437                    setEnabled(false);
     438                    break;
     439                default:
     440                    throw new IllegalStateException("Unexpected value: " + mode);
    434441                }
    435442            }
     
    525532                SaveLayersModel.Mode mode = (SaveLayersModel.Mode) evt.getNewValue();
    526533                switch (mode) {
    527                 case EDITING_DATA: setEnabled(true);
    528                     break;
    529                 case UPLOADING_AND_SAVING: setEnabled(false);
    530                     break;
     534                case EDITING_DATA:
     535                    setEnabled(true);
     536                    break;
     537                case UPLOADING_AND_SAVING:
     538                    setEnabled(false);
     539                    break;
     540                default:
     541                    throw new IllegalStateException("Unexpected value: " + mode);
    531542                }
    532543            }
  • trunk/src/org/openstreetmap/josm/gui/io/SaveLayersTable.java

    r19050 r19307  
    2727            Mode mode = (Mode) evt.getNewValue();
    2828            switch (mode) {
    29             case EDITING_DATA: setEnabled(true);
    30             break;
    31             case UPLOADING_AND_SAVING: setEnabled(false);
    32             break;
     29            case EDITING_DATA:
     30                setEnabled(true);
     31                break;
     32            case UPLOADING_AND_SAVING:
     33                setEnabled(false);
     34                break;
     35            default:
     36                throw new IllegalStateException("Unexpected value: " + mode);
    3337            }
    3438        }
  • trunk/src/org/openstreetmap/josm/gui/io/UploadPrimitivesTask.java

    r19136 r19307  
    401401                    switch (strategy.getPolicy()) {
    402402                    case ABORT:
    403                         break; /* do nothing - we return to map editing */
    404403                    case AUTOMATICALLY_OPEN_NEW_CHANGESETS:
    405404                        break; /* do nothing - we return to map editing */
     
    411410                        UploadDialog.getUploadDialog().setVisible(true);
    412411                        break;
     412                    default:
     413                        throw new IllegalStateException("Unexpected value: " + strategy.getPolicy());
    413414                    }
    414415                } else {
  • trunk/src/org/openstreetmap/josm/gui/io/UploadStrategySelectionPanel.java

    r19050 r19307  
    3939/**
    4040 * UploadStrategySelectionPanel is a panel for selecting an upload strategy.
    41  *
     41 * <p>
    4242 * Clients can listen for property change events for the property
    4343 * {@link #UPLOAD_STRATEGY_SPECIFICATION_PROP}.
     
    394394                tfChunkSize.requestFocusInWindow();
    395395                break;
     396            case SINGLE_REQUEST_STRATEGY:
     397            case INDIVIDUAL_OBJECTS_STRATEGY:
    396398            default:
    397399                tfChunkSize.setEnabled(false);
  • trunk/src/org/openstreetmap/josm/gui/layer/CustomizeColor.java

    r15735 r19307  
    2727/**
    2828 * Action to show a dialog for picking a color.
    29  *
     29 * <p>
    3030 * By calling this action, the user can choose a color to customize the painting
    3131 * of a certain {@link GpxLayer} or {@link org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer}.
     
    8484        );
    8585        switch (answer) {
    86         case 0:
     86        case JOptionPane.OK_OPTION:
    8787            colorLayers.forEach(l -> l.setColor(c.getColor()));
    8888            break;
    89         case 1:
     89        case JOptionPane.NO_OPTION:
    9090            return;
    91         case 2:
     91        case JOptionPane.CANCEL_OPTION:
    9292            colorLayers.forEach(l -> l.setColor(null));
    9393            break;
     94        default:
     95            throw new IllegalStateException("Unexpected value: " + answer);
    9496        }
    9597        // TODO: Make the layer dialog listen to property change events so that this is not needed any more.
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java

    r18208 r19307  
    115115        );
    116116        switch (answer) {
    117         case 0:
     117        case JOptionPane.OK_OPTION:
    118118            tracks.forEach(t -> t.setColor(c.getColor()));
    119119            GPXSettingsPanel.putLayerPrefLocal(layer, "colormode", "0"); //set Colormode to none
    120120            break;
    121         case 1:
     121        case JOptionPane.NO_OPTION:
    122122            return;
    123         case 2:
     123        case JOptionPane.CANCEL_OPTION:
    124124            tracks.forEach(t -> t.setColor(null));
    125125            break;
     126        default:
     127            throw new InvalidArgumentException("Unknown choice: " + answer);
    126128        }
    127129        table.repaint();
  • trunk/src/org/openstreetmap/josm/gui/layer/imagery/ColorfulFilter.java

    r18801 r19307  
    106106                    alphaOffset, src.getAlphaRaster() != null);
    107107            return dest;
    108         }
    109 
     108        default: // Fall through
     109        }
    110110        return doFilterRGB(src);
    111111    }
  • trunk/src/org/openstreetmap/josm/gui/layer/imagery/ReprojectionTile.java

    r19075 r19307  
    138138        double scaleMapView = MainApplication.getMap().mapView.getScale();
    139139        ImageWarp.Interpolation interpolation;
    140         switch (Config.getPref().get("imagery.warp.pixel-interpolation", "bilinear")) {
    141             case "nearest_neighbor":
    142                 interpolation = ImageWarp.Interpolation.NEAREST_NEIGHBOR;
    143                 break;
    144             default:
    145                 interpolation = ImageWarp.Interpolation.BILINEAR;
     140        if (Config.getPref().get("imagery.warp.pixel-interpolation", "bilinear").equals("nearest_neighbor")) {
     141            interpolation = ImageWarp.Interpolation.NEAREST_NEIGHBOR;
     142        } else {
     143            interpolation = ImageWarp.Interpolation.BILINEAR;
    146144        }
    147145
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/LineElement.java

    r17744 r19307  
    423423
    424424    private static Float computeWidth(LineType type, Cascade c, Cascade cDef) {
    425         Float width;
    426425        switch (type) {
    427426            case NORMAL:
    428                 width = getWidth(c, WIDTH, getWidth(cDef, WIDTH, null));
    429                 break;
     427                return getWidth(c, WIDTH, getWidth(cDef, WIDTH, null));
    430428            case CASING:
    431429                Float casingWidth = c.get(type.prefix + WIDTH, null, Float.class, true);
     
    438436                if (casingWidth == null)
    439437                    return null;
    440                 width = Optional.ofNullable(getWidth(c, WIDTH, getWidth(cDef, WIDTH, null))).orElse(0f) + 2 * casingWidth;
    441                 break;
     438                return Optional.ofNullable(getWidth(c, WIDTH, getWidth(cDef, WIDTH, null))).orElse(0f) + 2 * casingWidth;
    442439            case LEFT_CASING:
    443440            case RIGHT_CASING:
    444                 width = getWidth(c, type.prefix + WIDTH, null);
    445                 break;
    446             default:
    447                 throw new AssertionError();
    448         }
    449         return width;
     441                return getWidth(c, type.prefix + WIDTH, null);
     442        }
     443        throw new AssertionError();
    450444    }
    451445
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/KeyedItem.java

    r19285 r19307  
    282282        case KEY_VALUE_REQUIRED:
    283283            return tags.containsKey(key) && getValues().contains(tags.get(key));
    284         default:
    285             throw new IllegalStateException();
    286         }
     284        }
     285        throw new IllegalStateException();
    287286    }
    288287
  • trunk/src/org/openstreetmap/josm/io/AbstractReader.java

    r19079 r19307  
    523523
    524524    protected final void parseVersion(PrimitiveData current, int version) throws IllegalDataException {
    525         switch (ds.getVersion()) {
    526         case "0.6":
     525        if (ds.getVersion().equals("0.6")) {
    527526            if (version <= 0 && !current.isNew()) {
    528527                throw new IllegalDataException(
    529528                        tr("Illegal value for attribute ''version'' on OSM primitive with ID {0}. Got {1}.",
    530                         Long.toString(current.getUniqueId()), version));
     529                                Long.toString(current.getUniqueId()), version));
    531530            } else if (version < 0 && current.isNew()) {
    532531                Logging.warn(tr("Normalizing value of attribute ''version'' of element {0} to {2}, API version is ''{3}''. Got {1}.",
     
    534533                version = 0;
    535534            }
    536             break;
    537         default:
    538             // should not happen. API version has been checked before
     535        } else { // should not happen. API version has been checked before
    539536            throw new IllegalDataException(tr("Unknown or unsupported API version. Got {0}.", ds.getVersion()));
    540537        }
  • trunk/src/org/openstreetmap/josm/io/Compression.java

    r16816 r19307  
    103103                return getXZInputStream(in);
    104104            case NONE:
    105             default:
    106105                return in;
    107106        }
     107        return in;
    108108    }
    109109
     
    219219                return new XZCompressorOutputStream(out);
    220220            case NONE:
    221             default:
    222221                return out;
    223222        }
     223        return out;
    224224    }
    225225
  • trunk/src/org/openstreetmap/josm/io/DefaultProxySelector.java

    r19080 r19307  
    254254                return NO_PROXY_LIST;
    255255            return Collections.singletonList(new Proxy(Type.SOCKS, socksProxySocketAddress));
    256         }
    257256        // should not happen
    258         return Collections.emptyList();
     257        default: return Collections.emptyList();
     258        }
    259259    }
    260260}
  • trunk/src/org/openstreetmap/josm/io/OnlineResource.java

    r19101 r19307  
    5757            case ALL:
    5858                return /* ICON() */ "offline_all";
    59             default:
    60                 return null;
    6159        }
     60        return null;
    6261    }
    6362
  • trunk/src/org/openstreetmap/josm/io/OsmChangeReader.java

    r18211 r19307  
    111111            int event = parser.next();
    112112            if (event == XMLStreamConstants.START_ELEMENT) {
    113                 switch (parser.getLocalName()) {
    114                 case "comment":
     113                if (parser.getLocalName().equals("comment")) {
    115114                    text = parser.getAttributeValue(null, "text");
    116115                    jumpToEnd();
    117                     break;
    118                 default:
     116                } else {
    119117                    parseUnknown();
    120118                }
  • trunk/src/org/openstreetmap/josm/io/UploadStrategySpecification.java

    r19050 r19307  
    77 * An UploadStrategySpecification consists of the parameter describing the strategy
    88 * for uploading a collection of {@link org.openstreetmap.josm.data.osm.OsmPrimitive}.
    9  *
     9 * <p>
    1010 * This includes:
    1111 * <ul>
     
    145145            else
    146146                return (int) Math.ceil((double) numObjects / (double) chunkSize);
     147        default: // do nothing
    147148        }
    148149        // should not happen
  • trunk/src/org/openstreetmap/josm/io/audio/AudioPlayer.java

    r17333 r19307  
    344344                            stateChange = State.PAUSED;
    345345                            break;
    346                         default: // Do nothing
    347346                    }
    348347                    command.ok(stateChange);
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r19109 r19307  
    8585/**
    8686 * Helper class to support the application with images.
    87  *
     87 * <p>
    8888 * How to use:
    89  *
     89 * <p>
    9090 * <code>ImageIcon icon = new ImageProvider(name).setMaxSize(ImageSizes.MAP).get();</code>
    9191 * (there are more options, see below)
    92  *
     92 * <p>
    9393 * short form:
    9494 * <code>ImageIcon icon = ImageProvider.get(name);</code>
     
    247247    }
    248248
     249    private enum ImageLocations {
     250        LOCAL,
     251        ARCHIVE
     252    }
     253
    249254    /**
    250255     * Property set on {@code BufferedImage} returned by {@link #makeImageTransparent}.
     
    372377    /**
    373378     * Specify a zip file where the image is located.
    374      *
     379     * <p>
    375380     * (optional)
    376381     * @param archive zip file where the image is located
     
    384389    /**
    385390     * Specify a base path inside the zip file.
    386      *
     391     * <p>
    387392     * The subdir and name will be relative to this path.
    388      *
     393     * <p>
    389394     * (optional)
    390395     * @param inArchiveDir path inside the archive
     
    413418    /**
    414419     * Set the dimensions of the image.
    415      *
     420     * <p>
    416421     * If not specified, the original size of the image is used.
    417422     * The width part of the dimension can be -1. Then it will only set the height but
     
    428433    /**
    429434     * Set the dimensions of the image.
    430      *
     435     * <p>
    431436     * If not specified, the original size of the image is used.
    432437     * @param size final dimensions of the image
     
    476481    /**
    477482     * Limit the maximum size of the image.
    478      *
     483     * <p>
    479484     * It will shrink the image if necessary, but keep the aspect ratio.
    480485     * The given width or height can be -1 which means this direction is not bounded.
    481      *
     486     * <p>
    482487     * 'size' and 'maxSize' are not compatible, you should set only one of them.
    483488     * @param maxSize maximum image size
     
    492497    /**
    493498     * Limit the maximum size of the image.
    494      *
     499     * <p>
    495500     * It will shrink the image if necessary, but keep the aspect ratio.
    496501     * The given width or height can be -1 which means this direction is not bounded.
    497      *
     502     * <p>
    498503     * This function sets value using the most restrictive of the new or existing set of
    499504     * values.
     
    515520    /**
    516521     * Limit the maximum size of the image.
    517      *
     522     * <p>
    518523     * It will shrink the image if necessary, but keep the aspect ratio.
    519524     * The given width or height can be -1 which means this direction is not bounded.
    520      *
     525     * <p>
    521526     * 'size' and 'maxSize' are not compatible, you should set only one of them.
    522527     * @param size maximum image size
     
    561566    /**
    562567     * Decide, if an exception should be thrown, when the image cannot be located.
    563      *
     568     * <p>
    564569     * Set to true, when the image URL comes from user data and the image may be missing.
    565570     *
     
    575580    /**
    576581     * Suppresses warning on the command line in case the image cannot be found.
    577      *
     582     * <p>
    578583     * In combination with setOptional(true);
    579584     * @param suppressWarnings if <code>true</code> warnings are suppressed
     
    667672    /**
    668673     * Load the image in a background thread.
    669      *
     674     * <p>
    670675     * This method returns immediately and runs the image request asynchronously.
    671676     * @param action the action that will deal with the image
     
    712717    /**
    713718     * Load the image in a background thread.
    714      *
     719     * <p>
    715720     * This method returns immediately and runs the image request asynchronously.
    716721     * @param action the action that will deal with the image
     
    884889            extensions = new String[] {".png", ".svg"};
    885890        }
    886         final int typeArchive = 0;
    887         final int typeLocal = 1;
    888         for (int place : new Integer[] {typeArchive, typeLocal}) {
     891        for (ImageLocations place : ImageLocations.values()) {
    889892            for (String ext : extensions) {
    890893
     
    906909
    907910                switch (place) {
    908                 case typeArchive:
     911                case ARCHIVE:
    909912                    if (archive != null) {
    910913                        cacheName = "zip:" + archive.hashCode() + ':' + cacheName;
     
    919922                    }
    920923                    break;
    921                 case typeLocal:
     924                case LOCAL:
    922925                    ImageResource ir = cache.get(cacheName);
    923926                    if (ir != null) return ir;
     
    956959            switch (type) {
    957960            case SVG:
    958                 SVGDiagram svg = null;
     961                SVGDiagram svg;
    959962                synchronized (getSvgUniverse()) {
    960963                    URI uri = getSvgUniverse().loadSVG(is, Utils.fileToURL(cf.getFile()).toString());
     
    970973                }
    971974                return img == null ? null : new ImageResource(img);
    972             default:
    973                 throw new AssertionError("Unsupported type: " + type);
    974975            }
    975976        } catch (IOException e) {
     
    977978            return null;
    978979        }
     980        throw new AssertionError("Unsupported type: " + type);
    979981    }
    980982
     
    10821084     */
    10831085    private static ImageResource getIfAvailableZip(String fullName, File archive, String inArchiveDir, ImageType type) {
     1086        Objects.requireNonNull(type, "ImageType must not be null");
    10841087        try (ZipFile zipFile = new ZipFile(archive, StandardCharsets.UTF_8)) {
    10851088            if (inArchiveDir == null || ".".equals(inArchiveDir)) {
     
    10971100                    switch (type) {
    10981101                    case SVG:
    1099                         SVGDiagram svg = null;
     1102                        SVGDiagram svg;
    11001103                        synchronized (getSvgUniverse()) {
    11011104                            URI uri = getSvgUniverse().loadSVG(is, entryName, true);
     
    11161119                        }
    11171120                        return img == null ? null : new ImageResource(img);
    1118                     default:
    1119                         throw new AssertionError("Unknown ImageType: "+type);
    11201121                    }
    11211122                }
     
    11351136     */
    11361137    private static ImageResource getIfAvailableLocalURL(URL path, ImageType type) {
     1138        Objects.requireNonNull(type, "ImageType must not be null");
    11371139        switch (type) {
    11381140        case SVG:
     
    11741176            }
    11751177            return img == null ? null : new ImageResource(img);
    1176         default:
    1177             throw new AssertionError();
    1178         }
     1178        }
     1179        // Default
     1180        throw new AssertionError();
    11791181    }
    11801182
     
    13791381     * one-step technique (only useful in downscaling cases, where {@code targetWidth} or {@code targetHeight} is
    13801382     * smaller than the original dimensions, and generally only when the {@code BILINEAR} hint is specified).
    1381      *
    1382      * From https://community.oracle.com/docs/DOC-983611: "The Perils of Image.getScaledInstance()"
     1383     * <p>
     1384     * From <a href="https://community.oracle.com/docs/DOC-983611">"The Perils of Image.getScaledInstance()"</a>
    13831385     *
    13841386     * @param img the original image to be scaled
  • trunk/src/org/openstreetmap/josm/tools/ImageWarp.java

    r19075 r19307  
    164164     */
    165165    public static BufferedImage warp(BufferedImage srcImg, Dimension targetDim, PointTransform invTransform, Interpolation interpolation) {
     166        Objects.requireNonNull(interpolation, "interpolation");
    166167        BufferedImage imgTarget = new BufferedImage(targetDim.width, targetDim.height, BufferedImage.TYPE_INT_ARGB);
    167168        Rectangle2D srcRect = new Rectangle2D.Double(0, 0, srcImg.getWidth(), srcImg.getHeight());
     
    175176                Point2D srcCoord = invTransform.transform(i, j);
    176177                if (srcRect.contains(srcCoord)) {
    177                     int rgba;
     178                    // Convert to switch expression when we switch to Java 17+.
     179                    int rgba = 0; // Initialized here so the compiler doesn't complain. Otherwise, BILINEAR needs to have it start at 0.
    178180                    switch (interpolation) {
    179181                        case NEAREST_NEIGHBOR:
     
    189191                            int c10 = getColor(x0 + 1, y0, srcImg, sharedArray);
    190192                            int c11 = getColor(x0 + 1, y0 + 1, srcImg, sharedArray);
    191                             rgba = 0;
     193                            // rgba
    192194                            // loop over color components: blue, green, red, alpha
    193195                            for (int ch = 0; ch <= 3; ch++) {
     
    199201                            }
    200202                            break;
    201                         default:
    202                             throw new AssertionError(Objects.toString(interpolation));
    203203                    }
    204204                    imgTarget.getRaster().setDataElements(i, j, imgTarget.getColorModel().getDataElements(rgba, pixel));
Note: See TracChangeset for help on using the changeset viewer.