Skip to content

Commit

Permalink
Merge branch 'master' into deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
bobjacobsen committed Jan 12, 2019
2 parents 946d2a9 + 8597c05 commit 12286ac
Show file tree
Hide file tree
Showing 179 changed files with 1,222 additions and 673 deletions.
1 change: 1 addition & 0 deletions .classpath
Expand Up @@ -135,5 +135,6 @@
<classpathentry kind="lib" path="lib/webdrivermanager-2.0.1.jar"/>
<classpathentry kind="lib" path="lib/mqtt-client-0.4.0.jar"/>
<classpathentry kind="lib" path="lib/jsplitbutton-1.3.1.jar"/>
<classpathentry kind="lib" path="lib/thumbnailator-0.4.8.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
5 changes: 2 additions & 3 deletions .spotbugs-check.xml
Expand Up @@ -39,7 +39,6 @@
<Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD" />
<Bug pattern="UCF_USELESS_CONTROL_FLOW" />
<Bug pattern="UC_USELESS_CONDITION" />
<Bug pattern="URF_UNREAD_FIELD" />
<Bug pattern="UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" />
<Bug pattern="UW_UNCOND_WAIT" />
<Bug pattern="WA_NOT_IN_LOOP" />
Expand Down Expand Up @@ -87,8 +86,8 @@
<Match>
<!-- JMRI code is often written to trust weird from other classes,
so the question of "malicious" is complicated. The rules in
this category should be restored in small batches -->
<Bug category="MALICIOUS_CODE" />
this category should be restored in small batches
<Bug category="MALICIOUS_CODE" /> -->
</Match>

<!-- items we're unlikely to restore -->
Expand Down
1 change: 1 addition & 0 deletions build.xml
Expand Up @@ -224,6 +224,7 @@
<pathelement location="${libdir}/mqtt-client-0.4.0.jar"/>
<pathelement location="${libdir}/json-schema-validator-0.1.19.jar"/>
<pathelement location="${libdir}/jsplitbutton-1.3.1.jar"/>
<pathelement location="${libdir}/thumbnailator-0.4.8.jar"/>
</path>
<pathconvert property="runtime.class.jars" refid="runtime.class.path"/>

Expand Down
30 changes: 30 additions & 0 deletions java/src/jmri/CollectingReporter.java
@@ -0,0 +1,30 @@
package jmri;

/**
* This is an extension of a reporter device that is capable of collecting
* multiple reports in a collection. The type of collection is not specified
* by the interface, since that may be determined by the application.
* <BR>
* <hr>
* This file is part of JMRI.
* <P>
* JMRI is free software; you can redistribute it and/or modify it under the
* terms of version 2 of the GNU General Public License as published by the Free
* Software Foundation. See the "COPYING" file for a copy of this license.
* </P><P>
* JMRI is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* </P>
*
* @author Paul Bender Copyright (C) 2019
* @see jmri.Reporter
*/
public interface CollectingReporter extends Reporter {

/**
* @return the collection of elements associated with this reporter.
*/
public java.util.Collection getCollection();

}
2 changes: 1 addition & 1 deletion java/src/jmri/NamedBeanBundle_ca.properties
Expand Up @@ -275,7 +275,7 @@ ButtonRead = Read
ButtonWrite = Write
ButtonPrint = Print
ButtonStop = Stop
ButtonStart = Start
ButtonStart = Inicia
ButtonCreate = Create
# jmrit.ConditionalEdit Buttons
ButtonUp = Up
Expand Down
19 changes: 5 additions & 14 deletions java/src/jmri/implementation/AbstractRailComReporter.java
Expand Up @@ -8,6 +8,7 @@
import jmri.InstanceManager;
import jmri.LocoAddress;
import jmri.PhysicalLocationReporter;
import jmri.RailCom;
import jmri.ReporterManager;
import jmri.util.PhysicalLocation;
import org.slf4j.Logger;
Expand Down Expand Up @@ -80,20 +81,10 @@ public int getState() {
@Override
public LocoAddress getLocoAddress(String rep) {
// For now, we assume the current report.
// IdTag.getTagID() is a system-name-ized version of the loco address. I think.
// Matcher.group(1) : loco address (I think)
IdTag cr = (IdTag) this.getCurrentReport();
ReporterManager rm = InstanceManager.getDefault(jmri.ReporterManager.class);
Pattern p = Pattern.compile("" + rm.getSystemPrefix() + rm.typeLetter() + "(\\d+)");
Matcher m = p.matcher(cr.getTagID());
if (m.find()) {
log.debug("Parsed address: " + m.group(1));
// I have no idea what kind of loco address an Ecos reporter uses,
// so we'll default to DCC for now.
return (new DccLocoAddress(Integer.parseInt(m.group(1)), LocoAddress.Protocol.DCC));
} else {
return (null);
}
// IdTags passed by RailCom reporters are actually jmri.RailCom objects
// so we use properties of the RailCom object here.
RailCom cr = (RailCom) this.getCurrentReport();
return cr.getDccLocoAddress();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions java/src/jmri/implementation/AbstractReporter.java
Expand Up @@ -62,7 +62,7 @@ public void setReport(Object r) {
}

// internal data members
private Object _lastReport = null;
private Object _currentReport = null;
protected Object _lastReport = null;
protected Object _currentReport = null;

}
2 changes: 1 addition & 1 deletion java/src/jmri/jmrit/Bundle.properties
Expand Up @@ -62,7 +62,7 @@ MenuItemSetupClock = Set up Fast Clock...
MenuItemAnalogClock = Analog Clock
ButtonRunClock = Run
ButtonPauseClock = Pause
ButtonGo = Go
#ButtonGo = Go

MenuItemAmpMeter = Track Current...

Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrit/Bundle_ca.properties
Expand Up @@ -64,7 +64,7 @@ MenuItemSetupClock = Configura velocitat del rellotge
MenuItemAnalogClock = Rellotge d'agulles
ButtonRunClock = Engega
ButtonPauseClock = Atura
ButtonGo = Inicia
#ButtonGo = Inicia

MenuItemAmpMeter = Corrent de Via...

Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrit/Bundle_cs.properties
Expand Up @@ -194,7 +194,7 @@ TitleCopyLogix = Kop\u00edrovat Logix
RenameTitle = P\u0159ejmenovat {0}
ButtonPauseClock = Pozastavit
ButtonRunClock = Spustit
ButtonGo = Jet
#ButtonGo = Jet
MastBuilderTitle = Stavidel sto\u017e\u00e1r\u016f
StateInitialized = Inicializov\u00e1n
InitDH163 = Init DH163 + Soundtraxx
Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrit/Bundle_da.properties
Expand Up @@ -61,7 +61,7 @@ MenuItemSetupClock = Konfigurer Modeltids Ur...
MenuItemAnalogClock = Analogt Ur
ButtonRunClock = Start
ButtonPauseClock = Pause
ButtonGo = Go
#ButtonGo = Go

MenuItemAmpMeter = Spor Str\u00f8m...

Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrit/Bundle_nl.properties
Expand Up @@ -61,7 +61,7 @@ MenuItemSetupClock = Stel modelklok in...
MenuItemAnalogClock = Analoge Klok
ButtonRunClock = Loop
ButtonPauseClock = Pauseer
ButtonGo = Start
#ButtonGo = Start

MenuItemAmpMeter = Spoorstroom...

Expand Down
15 changes: 9 additions & 6 deletions java/src/jmri/jmrit/logix/Engineer.java
Expand Up @@ -1105,17 +1105,17 @@ public void doRamp() {
_resumePending = true;
float scriptSpeed = 0;
int idxSpeedCmd = Math.max(_idxSkipToSpeedCommand-1, _idxCurrentCommand); // resume speed index
for (int idx = idxSpeedCmd; idx > 0; idx--) {
/* for (int idx = idxSpeedCmd; idx > 0; idx--) {
// backing down to find script speed when script is resumed
ThrottleSetting ts = _commands.get(idx);
if ("SPEED".equals(ts.getCommand().toUpperCase())) {
scriptSpeed = Float.parseFloat(ts.getValue());
break;
}
}
_endSpeed = _speedUtil.modifySpeed(scriptSpeed, _endSpeedType, _isForward);
_endSpeed = _speedUtil.modifySpeed(scriptSpeed, _endSpeedType, _isForward);*/
// is scriptSpeed simply _normalSpeed? thus eliminate above.
log.info("normalSpeed= {}, scriptSpeed= {} speedType= {} endSpeed= {}", _normalSpeed, scriptSpeed, _endSpeedType, _endSpeed);
// log.info("normalSpeed= {}, scriptSpeed= {} speedType= {} endSpeed= {}", _normalSpeed, scriptSpeed, _endSpeedType, _endSpeed);
// However, the ramp up will take time and script may have other speed commands while
// ramping up. So 'scriptSpeed' may not be actual script speed when ramp up distance
// is traveled. Adjust '_endSpeed' to match that 'scriptSpeed'.
Expand All @@ -1142,11 +1142,11 @@ public void doRamp() {
rampDist = _speedUtil.rampLengthForSpeedChange(speed, _endSpeed, _isForward);
advanceToCommandIndex(idx); // don't let script set speeds up to here
}
log.debug("cmd= {}, et= {}, _endSpeed= {}, scriptDist= {}, rampDist= {}", cmd, ts.getTime(), _endSpeed, scriptDist, rampDist);
if (log.isDebugEnabled())
log.debug("cmd= {}, et= {}, _endSpeed= {}, scriptDist= {}, rampDist= {}", cmd, ts.getTime(),
_endSpeed, scriptDist, rampDist);
}
_normalSpeed = scriptSpeed;
log.info("Adjustment: _idxSkipToSpeedCommand= {}, scriptSpeed= {}, endSpeed= {}",
_idxSkipToSpeedCommand, scriptSpeed, _endSpeed);

if (log.isDebugEnabled())
log.debug("Ramp up for \"{}\". curSpeed= {}, endSpeed= {}, resumeIndex= {}, nextSpeedIdx= {}, rampDist= {}",
Expand Down Expand Up @@ -1260,6 +1260,9 @@ public void doRamp() {
advanceToCommandIndex(idx); // skip up to this speed command
}
}
if (log.isDebugEnabled())
log.debug("_normalSpeed= {}, _endSpeed= {}, resumeIndx= {}",
_normalSpeed, _endSpeed, _idxSkipToSpeedCommand+1);
}
}

Expand Down
12 changes: 9 additions & 3 deletions java/src/jmri/jmrit/logix/NXFrame.java
Expand Up @@ -74,7 +74,7 @@ public class NXFrame extends WarrantRoute {
private JPanel _switchPanel;
private JPanel _trainPanel;

public static float INCRE_RATE = 1.08f; // multiplier to increase throttle increments
public static float INCRE_RATE = 1.10f; // multiplier to increase throttle increments


protected NXFrame() {
Expand All @@ -93,6 +93,10 @@ private WarrantPreferences updatePreferences() {

private void init() {
if (log.isDebugEnabled()) log.debug("newInstance");
WarrantFrame f = WarrantTableAction.getWarrantFrame();
if (f != null) { // only edit one warrant at a time.
WarrantTableAction.closeWarrantFrame(f);
}
updatePreferences();
makeMenus();

Expand Down Expand Up @@ -490,7 +494,7 @@ private void makeAndRunWarrant() {
if (log.isDebugEnabled()) {
log.debug("WarrantTableFrame run warrant. msg= " + msg + " Remove warrant " + warrant.getDisplayName());
}
tableFrame.getModel().removeWarrant(warrant);
tableFrame.getModel().removeWarrant(warrant, false);
}

if (msg == null && mode == Warrant.MODE_RUN) {
Expand Down Expand Up @@ -955,8 +959,10 @@ private String makeCommands(Warrant w) {
blockName = bo.getBlock().getDisplayName();
w.addThrottleCommand(new ThrottleSetting((int) noopTime, "NoOp", "Enter Block", blockName,
(hasProfileSpeeds ? _speedUtil.getTrackSpeed(curThrottle, isForward) : 0.0f)));
if (log.isDebugEnabled()) log.debug("{}. Enter block \"{}\" noopTime= {}, speedTime= {} blockLen= {}",
if (log.isDebugEnabled()) {
log.debug("{}. Enter block \"{}\" noopTime= {}, speedTime= {} blockLen= {}",
cmdNum++, blockName, noopTime, speedTime, blockLen);
}
}
}
if (log.isDebugEnabled()) {
Expand Down
9 changes: 6 additions & 3 deletions java/src/jmri/jmrit/logix/OBlock.java
Expand Up @@ -521,7 +521,8 @@ public String allocate(Warrant warrant) {
String msg = null;
if (_warrant != null) {
if (!warrant.equals(_warrant)) {
msg = Bundle.getMessage("AllocatedToWarrant", _warrant.getDisplayName(), getDisplayName());
msg = Bundle.getMessage("AllocatedToWarrant",
_warrant.getDisplayName(), getDisplayName(), _warrant.getTrainName());
} else {
return null;
}
Expand Down Expand Up @@ -563,7 +564,8 @@ public String allocate(String pathName) {
return null;
} else if (_warrant != null) {
// allocated to another warrant
return Bundle.getMessage("AllocatedToWarrant", _warrant.getDisplayName(), getDisplayName());
return Bundle.getMessage("AllocatedToWarrant",
_warrant.getDisplayName(), getDisplayName(), _warrant.getTrainName());
}
if (_pathName != null && !_pathName.equals(pathName)) {
return Bundle.getMessage("AllocatedToPath", pathName, getDisplayName(), _pathName);
Expand Down Expand Up @@ -838,7 +840,8 @@ public void removePath(Path path) {
// @SuppressFBWarnings(value="NP_NULL_ON_SOME_PATH_EXCEPTION", justification="reference to OPath is not null when used")
protected String setPath(String pathName, Warrant warrant) {
if (_warrant != null && !_warrant.equals(warrant)) {
return Bundle.getMessage("AllocatedToWarrant", _warrant.getDisplayName(), getDisplayName());
return Bundle.getMessage("AllocatedToWarrant",
_warrant.getDisplayName(), getDisplayName(), _warrant.getTrainName());
}
pathName = pathName.trim();
OPath path = getPathByName(pathName);
Expand Down
22 changes: 18 additions & 4 deletions java/src/jmri/jmrit/logix/SCWarrant.java
@@ -1,10 +1,9 @@
package jmri.jmrit.logix;

import java.io.StringWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import jmri.DccLocoAddress;
import jmri.DccThrottle;
import jmri.InstanceManager;
import jmri.NamedBean;
Expand All @@ -31,7 +30,7 @@ public class SCWarrant extends Warrant {
private long timeToPlatform = 500;
private float speedFactor = 0.8f;
private boolean forward = true;
private boolean _allowShallowAllocation = false;
private final boolean _allowShallowAllocation = false;
private DccThrottle _throttle = null;
/**
* Create an object with no route defined. The list of BlockOrders is the
Expand Down Expand Up @@ -646,7 +645,7 @@ private void logStackTrace(Exception e) {
* The waiting for event must happen in a separate thread.
* Therefore the main code of runSignalControlledTrain is put in this class.
*******************************************************************************************************************************/
static LinkedBlockingQueue<SCWarrant> waitToRunQ = new LinkedBlockingQueue<SCWarrant>();
static LinkedBlockingQueue<SCWarrant> waitToRunQ = new LinkedBlockingQueue<>();
private class SCTrainRunner implements Runnable {
SCWarrant _warrant = null;
SCTrainRunner(SCWarrant warrant) {
Expand Down Expand Up @@ -859,6 +858,21 @@ public void run() {
}
}

/* What super does currently is fine. But FindBug reports EQ_DOESNT_OVERRIDE_EQUALS
* FindBug wants us to duplicate and override anyway
*/
@Override
public boolean equals(Object obj) {
return super.equals(obj);
}

/* What super does currently is fine. But FindBug reports HE_EQUALS_NO_HASHCODE
* FindBug wants us to duplicate and override anyway
*/
@Override
public int hashCode() {
return super.hashCode();
}

/**
*
Expand Down
43 changes: 41 additions & 2 deletions java/src/jmri/jmrit/logix/Warrant.java
Expand Up @@ -1409,8 +1409,10 @@ public String checkRoute() {
if ((block.getState() & OBlock.OCCUPIED) != 0 && !startBlock.equals(block)) {
return Bundle.getMessage("BlockRougeOccupied", block.getDisplayName());
}
if (!this.equals(block.getWarrant())) {
return Bundle.getMessage("AllocatedToWarrant", block.getWarrant().getDisplayName(), block.getDisplayName());
Warrant w = block.getWarrant();
if (w !=null && !this.equals(w)) {
return Bundle.getMessage("AllocatedToWarrant",
w.getDisplayName(), block.getDisplayName(), w.getTrainName());
}
}
return null;
Expand Down Expand Up @@ -2794,5 +2796,42 @@ private void rampSpeedDelay (long waitTime, String speedType, int endBlockIdx) {
}
}

/**
* {@inheritDoc}
* <p>
* This implementation tests that
* {@link jmri.NamedBean#getSystemName()}
* is equal for this and obj.
* To allow a warrant to run with sections, train name is included to test equality
*
* @param obj the reference object with which to compare.
* @return {@code true} if this object is the same as the obj argument;
* {@code false} otherwise.
*/
@Override
public boolean equals(Object obj) {
if (obj == null) return false; // by contract

if (obj instanceof Warrant) { // NamedBeans are not equal to things of other types
Warrant b = (Warrant) obj;
String trainName = this.getTrainName();
if (trainName == null) {
return (b.getTrainName() == null);
}
return (this.getSystemName().equals(b.getSystemName()) && trainName.equals(b.getTrainName()));
}
return false;
}

/**
* {@inheritDoc}
*
* @return hash code value is based on the system and train names.
*/
@Override
public int hashCode() {
return (getSystemName().concat(getTrainName())).hashCode();
}

private final static Logger log = LoggerFactory.getLogger(Warrant.class);
}

0 comments on commit 12286ac

Please sign in to comment.