CPD Results

The following document contains the results of PMD's CPD 6.21.0.

Duplications

File Line
nl\tudelft\simulation\dsol\jetty\sse\OTSWebModel.java 316
nl\tudelft\simulation\dsol\jetty\sse\OTSWebServer.java 349
                    answer = controlButtonResponse(getSimulator() != null, started);
                    break;
                }

                case "animate":
                {
                    answer = animationPanel.getDrawingCommands();
                    break;
                }

                case "arrowDown":
                {
                    animationPanel.pan(HTMLGridPanel.DOWN, 0.1);
                    break;
                }

                case "arrowUp":
                {
                    animationPanel.pan(HTMLGridPanel.UP, 0.1);
                    break;
                }

                case "arrowLeft":
                {
                    animationPanel.pan(HTMLGridPanel.LEFT, 0.1);
                    break;
                }

                case "arrowRight":
                {
                    animationPanel.pan(HTMLGridPanel.RIGHT, 0.1);
                    break;
                }

                case "pan":
                {
                    if (parts.length == 3)
                    {
                        int dx = Integer.parseInt(parts[1]);
                        int dy = Integer.parseInt(parts[2]);
                        double scale =
                                Renderable2DInterface.Util.getScale(animationPanel.getExtent(), animationPanel.getSize());
                        Rectangle2D.Double extent = (Rectangle2D.Double) animationPanel.getExtent();
                        extent.setRect((extent.getMinX() - dx * scale), (extent.getMinY() + dy * scale), extent.getWidth(),
                                extent.getHeight());
                    }
                    break;
                }

                case "introspect":
                {
                    if (parts.length == 3)
                    {
                        int x = Integer.parseInt(parts[1]);
                        int y = Integer.parseInt(parts[2]);
                        List<Locatable> targets = new ArrayList<Locatable>();
                        try
                        {
                            Point2D point = Renderable2DInterface.Util.getWorldCoordinates(new Point2D.Double(x, y),
                                    animationPanel.getExtent(), animationPanel.getSize());
                            for (Renderable2DInterface<?> renderable : animationPanel.getElements())
                            {
                                if (animationPanel.isShowElement(renderable)
                                        && renderable.contains(point, animationPanel.getExtent(), animationPanel.getSize()))
                                {
                                    if (renderable.getSource() instanceof GTU)
                                    {
                                        targets.add(renderable.getSource());
                                    }
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            this.simulator.getLogger().always().warn(exception, "getSelectedObjects");
File Line
nl\tudelft\simulation\dsol\jetty\sse\OTSWebModel.java 538
nl\tudelft\simulation\dsol\jetty\sse\OTSWebServer.java 571
                setSpeedFactor(speedFactor);
                // System.out.println("speed factor changed to " + speedFactor);
            }
            catch (NumberFormatException exception)
            {
                answer = "<message>Error: " + exception.getMessage() + "</message>";
            }
        }

        // System.out.println(answer);

        response.setContentType("text/xml");
        response.setHeader("Cache-Control", "no-cache");
        response.setContentLength(answer.length());
        response.setStatus(HttpServletResponse.SC_OK);
        response.getWriter().write(answer);
        response.flushBuffer();
        baseRequest.setHandled(true);
    }

    /**
     * @param active boolean; is the simulation active?
     * @param started boolean; has the simulation been started?
     * @return XML message to send to the server
     */
    private String controlButtonResponse(final boolean active, final boolean started)
    {
        if (!active)
        {
            return "<controls>\n" + "<oneEventActive>false</oneEventActive>\n" + "<allEventsActive>false</allEventsActive>\n"
                    + "<startStop>start</startStop>\n" + "<startStopActive>false</startStopActive>\n"
                    + "<resetActive>false</resetActive>\n" + "</controls>\n";
        }
        if (started)
        {
            return "<controls>\n" + "<oneEventActive>false</oneEventActive>\n" + "<allEventsActive>false</allEventsActive>\n"
                    + "<startStop>stop</startStop>\n" + "<startStopActive>true</startStopActive>\n"
                    + "<resetActive>false</resetActive>\n" + "</controls>\n";
        }
        else
        {
            return "<controls>\n" + "<oneEventActive>true</oneEventActive>\n" + "<allEventsActive>true</allEventsActive>\n"
                    + "<startStop>start</startStop>\n" + "<startStopActive>true</startStopActive>\n"
                    + "<resetActive>false</resetActive>\n" + "</controls>\n";
        }
    }

    /**
     * Return the toggle button info for the toggle panel.
     * @param panel the HTMLAnimationPanel
     * @return the String that can be parsed by the select.html iframe
     */
    private String getToggles(final HTMLAnimationPanel panel)
    {
        String ret = "<toggles>\n";
        for (ToggleButtonInfo toggle : panel.getToggleButtons())
        {
            if (toggle instanceof ToggleButtonInfo.Text)
            {
                ret += "<text>" + toggle.getName() + "</text>\n";
            }
            else if (toggle instanceof ToggleButtonInfo.LocatableClass)
            {
                ret += "<class>" + toggle.getName() + "," + toggle.isVisible() + "</class>\n";
            }
            else if (toggle instanceof ToggleButtonInfo.Gis)
            {
                ret += "<gis>" + toggle.getName() + "," + ((ToggleButtonInfo.Gis) toggle).getLayerName() + ","
                        + toggle.isVisible() + "</gis>\n";
            }
        }
        ret += "</toggles>\n";
        return ret;
    }

    /**
     * Returns the simulation speed.
     * @param simTime double; simulation time
     * @return simulation speed
     */
    private double getSimulationSpeed(final double simTime)
    {
        long now = System.currentTimeMillis();
        if (this.lastWallTIme < 0 || this.lastWallTIme == now)
        {
            this.lastWallTIme = now;
            this.prevSimTime = simTime;
            return Double.NaN;
        }
        double speed = (simTime - this.prevSimTime) / (0.001 * (now - this.lastWallTIme));
        this.prevSimTime = simTime;
        this.lastWallTIme = now;
        return speed;
    }
}
File Line
nl\tudelft\simulation\dsol\jetty\sse\OTSWebModel.java 390
nl\tudelft\simulation\dsol\jetty\sse\OTSWebServer.java 423
                            this.simulator.getLogger().always().warn(exception, "getSelectedObjects");
                        }
                        if (targets.size() > 0)
                        {
                            Object introspectedObject = targets.get(0);
                            Property[] properties = new BeanIntrospector().getProperties(introspectedObject);
                            SortedMap<String, Property> propertyMap = new TreeMap<>();
                            for (Property property : properties)
                                propertyMap.put(property.getName(), property);
                            answer = "<introspection>\n";
                            for (Property property : propertyMap.values())
                            {
                                answer += "<property><field>" + property.getName() + "</field><value>" + property.getValue()
                                        + "</value></property>\n";
                            }
                            answer += "<introspection>\n";
                        }
                        else
                        {
                            answer = "<none />";
                        }
                    }
                    break;
                }

                case "zoomIn":
                {
                    if (parts.length == 1)
                        animationPanel.zoom(0.9);
                    else
                    {
                        int x = Integer.parseInt(parts[1]);
                        int y = Integer.parseInt(parts[2]);
                        animationPanel.zoom(0.9, x, y);
                    }
                    break;
                }

                case "zoomOut":
                {
                    if (parts.length == 1)
                        animationPanel.zoom(1.1);
                    else
                    {
                        int x = Integer.parseInt(parts[1]);
                        int y = Integer.parseInt(parts[2]);
                        animationPanel.zoom(1.1, x, y);
                    }
                    break;
                }

                case "zoomAll":
                {
                    animationPanel.zoomAll();
                    break;
                }

                case "home":
                {
                    animationPanel.home();
                    break;
                }

                case "toggleGrid":
                {
                    animationPanel.setShowGrid(!animationPanel.isShowGrid());
                    break;
                }

                case "getTime":
                {
                    double now = Math.round(getSimulator().getSimulatorTime().si * 1000) / 1000d;
File Line
nl\tudelft\simulation\dsol\jetty\sse\OTSWebModel.java 139
nl\tudelft\simulation\dsol\jetty\sse\OTSWebServer.java 158
    }

    /**
     * Try to start the simulator, and return whether the simulator has been started.
     * @return whether the simulator has been started or not
     */
    protected boolean startSimulator()
    {
        if (getSimulator() == null)
        {
            System.out.println("SIMULATOR == NULL");
            return false;
        }
        try
        {
            System.out.println("START THE SIMULATOR");
            getSimulator().start();
        }
        catch (SimRuntimeException exception)
        {
            getSimulator().getLogger().always().warn(exception, "Problem starting Simulator");
        }
        if (getSimulator().isStartingOrRunning())
        {
            return true;
        }
        this.dirtyControls = false; // undo the notification
        return false;
    }

    /**
     * Try to stop the simulator, and return whether the simulator has been stopped.
     * @return whether the simulator has been stopped or not
     */
    protected boolean stopSimulator()
    {
        if (getSimulator() == null)
        {
            return true;
        }
        try
        {
            System.out.println("STOP THE SIMULATOR");
            getSimulator().stop();
        }
        catch (SimRuntimeException exception)
        {
            getSimulator().getLogger().always().warn(exception, "Problem stopping Simulator");
        }
        if (!getSimulator().isStartingOrRunning())
        {
            return true;
        }
        this.dirtyControls = false; // undo the notification
        return false;
    }

    /**
     * @param speedFactor double; the new speed factor
     */
    protected void setSpeedFactor(final double speedFactor)
    {
        if (this.simulator instanceof DEVSRealTimeClock)
        {
            ((DEVSRealTimeClock<?, ?, ?>) this.simulator).setSpeedFactor(speedFactor);
        }
    }

    /** {@inheritDoc} */
    @Override
    public void notify(final EventInterface event) throws RemoteException
File Line
nl\tudelft\simulation\dsol\jetty\sse\OTSWebModel.java 472
nl\tudelft\simulation\dsol\jetty\sse\OTSWebServer.java 505
                    double simTime = getSimulator().getSimulatorTime().si;
                    double speed = getSimulationSpeed(simTime);
                    String speedText = "";
                    if (!Double.isNaN(speed))
                    {
                        speedText = String.format("% 5.2fx  ", speed);
                    }
                    answer = speedText;
                    break;
                }

                case "getToggles":
                {
                    answer = getToggles(animationPanel);
                    break;
                }

                // we expect something of the form toggle|class|Node|true or toggle|gis|streets|false
                case "toggle":
                {
                    if (parts.length != 4)
                        System.err.println("wrong toggle commmand: " + message);
                    else
                    {
                        String toggleName = parts[1];
                        boolean gis = parts[2].equals("gis");
                        boolean show = parts[3].equals("true");
                        if (gis)
                        {
                            if (show)
                                animationPanel.showGISLayer(toggleName);
                            else
                                animationPanel.hideGISLayer(toggleName);
                        }
                        else
                        {
                            if (show)
                                animationPanel.showClass(toggleName);
                            else
                                animationPanel.hideClass(toggleName);
                        }
                    }
                    break;
                }

                default:
                {
                    System.err.println("OTSWebModel: Got unknown message from client: " + command);
File Line
org\opentrafficsim\web\animation\WebAnimationToggles.java 56
org\opentrafficsim\web\animation\WebAnimationToggles.java 83
        panel.addToggleAnimationButtonText("Link", OTSLink.class, "Show/hide links", true);
        panel.addToggleAnimationButtonText("LinkId", LinkAnimation.Text.class, "Show/hide link Ids", false);
        panel.addToggleAnimationButtonText("Lane", Lane.class, "Show/hide lanes", true);
        panel.addToggleAnimationButtonText("LaneId", LaneAnimation.Text.class, "Show/hide lane Ids", false);
        panel.addToggleAnimationButtonText("LaneCenter", LaneAnimation.CenterLine.class, "Show/hide lane center lines", false);
        panel.addToggleAnimationButtonText("Stripe", Stripe.class, "Show/hide stripes", true);
        panel.addToggleAnimationButtonText("Shoulder", Shoulder.class, "Show/hide shoulders", true);
        panel.addToggleAnimationButtonText("GTU", GTU.class, "Show/hide GTUs", true);
        panel.addToggleAnimationButtonText("GTUId", DefaultCarAnimation.Text.class, "Show/hide GTU Ids", false);
        panel.addToggleAnimationButtonText("Sensor", SingleSensor.class, "Show/hide sensors", true);
File Line
nl\tudelft\simulation\dsol\web\animation\HTMLGraphics2D.java 278
nl\tudelft\simulation\dsol\web\animation\HTMLGraphics2D.java 352
    protected void addTransformPathFloat(Path2D.Float path, boolean fill)
    {
        if (fill)
            this.commands.append("<transformPath>FILL");
        else
            this.commands.append("<transformPath>DRAW");
        addAffineTransform();
        addColor(this.color);
        if (fill)
        {
            if (path.getWindingRule() == Path2D.WIND_EVEN_ODD)
                this.commands.append(",WIND_EVEN_ODD");
            else
                this.commands.append(",WIND_NON_ZERO");
        }
        else
        {
            if (this.stroke instanceof BasicStroke)
                this.commands.append("," + ((BasicStroke) this.stroke).getLineWidth());
            else
                this.commands.append(", 0.1");
        }
File Line
nl\tudelft\simulation\dsol\jetty\sse\TestDemoServer.java 373
nl\tudelft\simulation\dsol\jetty\sse\TestDemoServer.java 390
                answer.append("<doubleScalar key='" + pds.getExtendedKey() + "' name='" + pds.getShortName() + "' description='"
                        + pds.getDescription() + "'><value>" + val + "</value>\n");
                for (String unit : units)
                {
                    Unit<?> unitValue = pds.getUnitParameter().getOptions().get(unit);
                    if (unitValue.equals(pds.getUnitParameter().getValue()))
                        answer.append("<unit chosen='true'>" + unit + "</unit>\n");
                    else
                        answer.append("<unit chosen='false'>" + unit + "</unit>\n");
                }
                answer.append("</doubleScalar>\n");