CPD Results
The following document contains the results of PMD's CPD 7.3.0.
Duplications
File | Line |
---|---|
nl/tudelft/simulation/dsol/jetty/sse/OtsWebModel.java | 317 |
nl/tudelft/simulation/dsol/jetty/sse/OtsWebServer.java | 350 |
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 scaleX = animationPanel.getRenderableScale().getXScale(animationPanel.getExtent(), animationPanel.getSize()); double scaleY = animationPanel.getRenderableScale().getYScale(animationPanel.getExtent(), animationPanel.getSize()); Bounds2d extent = animationPanel.getExtent(); animationPanel.setExtent(new Bounds2d(extent.getMinX() - dx * scaleX, extent.getMinX() - dx * scaleX + extent.getDeltaX(), extent.getMinY() + dy * scaleY, extent.getMinY() + dy * scaleY + extent.getDeltaY())); } 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 = animationPanel.getRenderableScale().getWorldCoordinates(new Point2D.Double(x, y), animationPanel.getExtent(), animationPanel.getSize()); for (Renderable2dInterface<?> renderable : animationPanel.getElements()) { if (animationPanel.isShowElement(renderable) && renderable.contains(point, animationPanel.getExtent())) { 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 | 542 |
nl/tudelft/simulation/dsol/jetty/sse/OtsWebServer.java | 575 |
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 HTMLAnimationPanel; 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 | 394 |
nl/tudelft/simulation/dsol/jetty/sse/OtsWebServer.java | 427 |
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 | 140 |
nl/tudelft/simulation/dsol/jetty/sse/OtsWebServer.java | 159 |
} /** * 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 DevsRealTimeAnimator) { ((DevsRealTimeAnimator<Duration>) this.simulator).setSpeedFactor(speedFactor); } } /** {@inheritDoc} */ @Override public void notify(final Event event) throws RemoteException { if (event.getType().equals(SimulatorInterface.START_EVENT)) { this.dirtyControls = true; } else if (event.getType().equals(SimulatorInterface.STOP_EVENT)) { this.dirtyControls = true; } } |
File | Line |
---|---|
nl/tudelft/simulation/dsol/jetty/sse/OtsWebModel.java | 476 |
nl/tudelft/simulation/dsol/jetty/sse/OtsWebServer.java | 509 |
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 | 53 |
org/opentrafficsim/web/animation/WebAnimationToggles.java | 82 |
panel.addToggleAnimationButtonText("Link", LinkData.class, "Show/hide links", true); panel.addToggleAnimationButtonText("LinkId", LinkAnimation.Text.class, "Show/hide link Ids", false); panel.addToggleAnimationButtonText("Lane", LaneData.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", StripeData.class, "Show/hide stripes", true); panel.addToggleAnimationButtonText("Shoulder", CrossSectionElementData.class, "Show/hide shoulders", true); panel.addToggleAnimationButtonText("GTU", GtuData.class, "Show/hide GTUs", true); panel.addToggleAnimationButtonText("GTUId", DefaultCarAnimation.Text.class, "Show/hide GTU Ids", false); panel.addToggleAnimationButtonText("Detector", DetectorData.class, "Show/hide detector", true); |
File | Line |
---|---|
org/opentrafficsim/web/animation/WebAnimationToggles.java | 62 |
org/opentrafficsim/web/animation/WebAnimationToggles.java | 91 |
panel.addToggleAnimationButtonText("Detector", DetectorData.class, "Show/hide detector", true); panel.addToggleAnimationButtonText("DetectorId", DetectorData.Text.class, "Show/hide detector Ids", false); panel.addToggleAnimationButtonText("Light", TrafficLightData.class, "Show/hide traffic lights", true); panel.addToggleAnimationButtonText("LightId", TrafficLightAnimation.Text.class, "Show/hide traffic light Ids", false); panel.addToggleAnimationButtonText("Conflict", ConflictData.class, "Show/hide conflicts", false); panel.addToggleAnimationButtonText("Generator", GtuGeneratorPositionData.class, "Show/hide generators", false); panel.addToggleAnimationButtonText("GeneratorQ", GtuGeneratorPositionAnimation.Queue.class, "Show/hide generator queues", false); panel.addToggleAnimationButtonText("Bus", BusStopData.class, "Show/hide bus stops", false); panel.addToggleAnimationButtonText("BusId", BusStopAnimation.Text.class, "Show/hide bus stop Ids", false); } /** * Set the most common animation on, and create the toggles on the left hand side. * @param panel HTMLAnimationPanel; the Animation panel to add the toggle to. */ public static void setTextAnimationTogglesStandard(final HtmlAnimationPanel panel) |
File | Line |
---|---|
nl/tudelft/simulation/dsol/web/animation/HtmlGraphics2d.java | 278 |
nl/tudelft/simulation/dsol/web/animation/HtmlGraphics2d.java | 352 |
protected void addTransformPathFloat(final Path2D.Float path, final 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"); |