Changeset 11809 in josm


Ignore:
Timestamp:
2017-04-01T01:23:56+02:00 (9 months ago)
Author:
Don-vip
Message:

findbugs - BC_UNCONFIRMED_CAST

Location:
trunk/src/org/openstreetmap/josm
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java

    r11713 r11809  
    231231
    232232    private BoundingXYVisitor getBoundingBox() {
    233         BoundingXYVisitor v = "problem".equals(mode) ? new ValidatorBoundingXYVisitor() : new BoundingXYVisitor();
    234 
    235233        switch (mode) {
    236234        case "problem":
    237             return modeProblem((ValidatorBoundingXYVisitor) v);
     235            return modeProblem(new ValidatorBoundingXYVisitor());
    238236        case "data":
    239             return modeData(v);
     237            return modeData(new BoundingXYVisitor());
    240238        case "layer":
    241             return modeLayer(v);
     239            return modeLayer(new BoundingXYVisitor());
    242240        case "selection":
    243241        case "conflict":
    244             return modeSelectionOrConflict(v);
     242            return modeSelectionOrConflict(new BoundingXYVisitor());
    245243        case "download":
    246             return modeDownload(v);
     244            return modeDownload(new BoundingXYVisitor());
    247245        default:
    248             return v;
     246            return new BoundingXYVisitor();
    249247        }
    250248    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/layer/LayerListTransferHandler.java

    r11452 r11809  
    3333    @Override
    3434    public int getSourceActions(JComponent c) {
    35         // we know that the source is a layer list, so don't check c.
    36         LayerListModel tableModel = (LayerListModel) ((JTable) c).getModel();
    37         if (tableModel.getSelectedLayers().isEmpty()) {
    38             return 0;
     35        if (c instanceof JTable) {
     36            LayerListModel tableModel = (LayerListModel) ((JTable) c).getModel();
     37            if (!tableModel.getSelectedLayers().isEmpty()) {
     38                int actions = MOVE;
     39                if (onlyDataLayersSelected(tableModel)) {
     40                    actions |= COPY;
     41                }
     42                return actions /* soon: | LINK*/;
     43            }
    3944        }
    40         int actions = MOVE;
    41         if (onlyDataLayersSelected(tableModel)) {
    42             actions |= COPY;
    43         }
    44         return actions /* soon: | LINK*/;
     45        return NONE;
    4546    }
    4647
     
    5657    @Override
    5758    protected Transferable createTransferable(JComponent c) {
    58         LayerListModel tableModel = (LayerListModel) ((JTable) c).getModel();
    59         return new LayerTransferable(tableModel.getLayerManager(), tableModel.getSelectedLayers());
     59        if (c instanceof JTable) {
     60            LayerListModel tableModel = (LayerListModel) ((JTable) c).getModel();
     61            return new LayerTransferable(tableModel.getLayerManager(), tableModel.getSelectedLayers());
     62        }
     63        return null;
    6064    }
    6165
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/LineElement.java

    r11553 r11809  
    7070    public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, StyledMapRenderer painter,
    7171            boolean selected, boolean outermember, boolean member) {
    72         Way w = (Way) primitive;
    7372        /* show direction arrows, if draw.segment.relevant_directions_only is not set,
    7473        the way is tagged with a direction key
     
    8281        boolean showOneway = !isModifier && !selected &&
    8382                !paintSettings.isUseRealWidth() &&
    84                 paintSettings.isShowOnewayArrow() && w.hasDirectionKeys();
    85         boolean onewayReversed = w.reversedDirection();
     83                paintSettings.isShowOnewayArrow() && primitive.hasDirectionKeys();
     84        boolean onewayReversed = primitive.reversedDirection();
    8685        /* head only takes over control if the option is true,
    8786        the direction should be shown at all and not only because it's selected */
     
    109108        } else if (member || outermember) {
    110109            myColor = paintSettings.getRelationSelectedColor(color.getAlpha());
    111         } else if (w.isDisabled()) {
     110        } else if (primitive.isDisabled()) {
    112111            myColor = paintSettings.getInactiveColor();
    113112            myDashedColor = paintSettings.getInactiveColor();
    114113        }
    115114
    116         painter.drawWay(w, myColor, myLine, myDashLine, myDashedColor, offset, showOrientation,
    117                 showOnlyHeadArrowOnly, showOneway, onewayReversed);
    118 
    119         if ((paintSettings.isShowOrderNumber() || (paintSettings.isShowOrderNumberOnSelectedWay() && selected))
    120                 && !painter.isInactiveMode()) {
    121             int orderNumber = 0;
    122             lastN = null;
    123             for (Node n : w.getNodes()) {
    124                 if (lastN != null) {
    125                     orderNumber++;
    126                     painter.drawOrderNumber(lastN, n, orderNumber, myColor);
    127                 }
    128                 lastN = n;
     115        if (primitive instanceof Way) {
     116            Way w = (Way) primitive;
     117            painter.drawWay(w, myColor, myLine, myDashLine, myDashedColor, offset, showOrientation,
     118                    showOnlyHeadArrowOnly, showOneway, onewayReversed);
     119
     120            if ((paintSettings.isShowOrderNumber() || (paintSettings.isShowOrderNumberOnSelectedWay() && selected))
     121                    && !painter.isInactiveMode()) {
     122                int orderNumber = 0;
     123                lastN = null;
     124                for (Node n : w.getNodes()) {
     125                    if (lastN != null) {
     126                        orderNumber++;
     127                        painter.drawOrderNumber(lastN, n, orderNumber, myColor);
     128                    }
     129                    lastN = n;
     130                }
    129131            }
    130132        }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/RepeatImageElement.java

    r11452 r11809  
    8181    public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, StyledMapRenderer painter,
    8282            boolean selected, boolean outermember, boolean member) {
    83         Way w = (Way) primitive;
    84         painter.drawRepeatImage(w, pattern, painter.isInactiveMode() || w.isDisabled(), offset, spacing, phase, align);
     83        if (primitive instanceof Way) {
     84            Way w = (Way) primitive;
     85            painter.drawRepeatImage(w, pattern, painter.isInactiveMode() || w.isDisabled(), offset, spacing, phase, align);
     86        }
    8587    }
    8688
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmTextField.java

    r8510 r11809  
    151151            // Taken from http://stackoverflow.com/a/24571681/2257172
    152152            int h = getHeight();
    153             ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
     153            if (g instanceof Graphics2D) {
     154                ((Graphics2D) g).setRenderingHint(
     155                        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
     156            }
    154157            Insets ins = getInsets();
    155158            FontMetrics fm = g.getFontMetrics();
  • trunk/src/org/openstreetmap/josm/gui/widgets/MultiSplitPane.java

    r10600 r11809  
    158158        @Override
    159159        public void paint(Graphics g, Divider divider) {
    160             if ((divider == activeDivider()) && !isContinuousLayout()) {
     160            if (g instanceof Graphics2D && divider == activeDivider() && !isContinuousLayout()) {
    161161                Graphics2D g2d = (Graphics2D) g;
    162162                g2d.setColor(Color.black);
  • trunk/src/org/openstreetmap/josm/io/MultiFetchServerObjectReader.java

    r11702 r11809  
    211211     */
    212212    public MultiFetchServerObjectReader append(OsmPrimitive primitive) {
    213         if (primitive != null) {
    214             switch (OsmPrimitiveType.from(primitive)) {
    215                 case NODE: return appendNode((Node) primitive);
    216                 case WAY: return appendWay((Way) primitive);
    217                 case RELATION: return appendRelation((Relation) primitive);
    218                 default: break;
    219             }
     213        if (primitive instanceof Node) {
     214            return appendNode((Node) primitive);
     215        } else if (primitive instanceof Way) {
     216            return appendWay((Way) primitive);
     217        } else if (primitive instanceof Relation) {
     218            return appendRelation((Relation) primitive);
    220219        }
    221220        return this;
  • trunk/src/org/openstreetmap/josm/io/OsmExporter.java

    r11386 r11809  
    6464     */
    6565    public void exportData(File file, Layer layer, boolean noBackup) {
    66         checkOsmDataLayer(layer);
     66        if (!(layer instanceof OsmDataLayer)) {
     67            throw new IllegalArgumentException(
     68                    MessageFormat.format("Expected instance of OsmDataLayer. Got ''{0}''.", layer.getClass().getName()));
     69        }
    6770        save(file, (OsmDataLayer) layer, noBackup);
    68     }
    69 
    70     protected static void checkOsmDataLayer(Layer layer) {
    71         if (!(layer instanceof OsmDataLayer)) {
    72             throw new IllegalArgumentException(MessageFormat.format("Expected instance of OsmDataLayer. Got ''{0}''.", layer
    73                     .getClass().getName()));
    74         }
    7571    }
    7672
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/DNSName.java

    r9344 r11809  
    203203            constraintType = NAME_DIFF_TYPE;
    204204        else {
     205            if (!(inputName instanceof DNSName)) {
     206                throw new IllegalArgumentException("inputName: " + inputName);
     207            }
    205208            String inName =
    206209                (((DNSName) inputName).getName()).toLowerCase(Locale.ENGLISH);
  • trunk/src/org/openstreetmap/josm/tools/template_engine/ContextSwitchTemplate.java

    r10659 r11809  
    2323public class ContextSwitchTemplate implements TemplateEntry {
    2424
    25     private static final TemplateEngineDataProvider EMTPY_PROVIDER = new TemplateEngineDataProvider() {
     25    private static final TemplateEngineDataProvider EMPTY_PROVIDER = new TemplateEngineDataProvider() {
    2626        @Override
    2727        public Object getTemplateValue(String name, boolean special) {
     
    258258    @Override
    259259    public void appendText(StringBuilder result, TemplateEngineDataProvider dataProvider) {
    260         List<OsmPrimitive> primitives = context.getPrimitives((OsmPrimitive) dataProvider);
    261         if (primitives != null && !primitives.isEmpty()) {
    262             template.appendText(result, primitives.get(0));
    263         } else {
    264             template.appendText(result, EMTPY_PROVIDER);
    265         }
     260        if (dataProvider instanceof OsmPrimitive) {
     261            List<OsmPrimitive> primitives = context.getPrimitives((OsmPrimitive) dataProvider);
     262            if (primitives != null && !primitives.isEmpty()) {
     263                template.appendText(result, primitives.get(0));
     264            }
     265        }
     266        template.appendText(result, EMPTY_PROVIDER);
    266267    }
    267268
    268269    @Override
    269270    public boolean isValid(TemplateEngineDataProvider dataProvider) {
    270         List<OsmPrimitive> primitives = context.getPrimitives((OsmPrimitive) dataProvider);
    271         if (primitives != null && !primitives.isEmpty())
    272             return template.isValid(primitives.get(0));
    273         else
    274             return false;
    275     }
    276 
     271        if (dataProvider instanceof OsmPrimitive) {
     272            List<OsmPrimitive> primitives = context.getPrimitives((OsmPrimitive) dataProvider);
     273            if (primitives != null && !primitives.isEmpty()) {
     274                return template.isValid(primitives.get(0));
     275            }
     276        }
     277        return false;
     278    }
    277279}
Note: See TracChangeset for help on using the changeset viewer.