Skip to content
Permalink
Browse files

Retire CTCJythonAccessInstanceManager; add @override to FrmTRL_Rules

  • Loading branch information...
dsand47 committed May 21, 2019
1 parent 7a6f817 commit def741de921b5a15945562c971fa8567e0a619b7

This file was deleted.

@@ -56,11 +56,11 @@ private void handleCTCDebugSystemReload(PropertyChangeEvent e) {
}
}

@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "There's only one!")
public boolean _mCTCDebug_TrafficLockingRuleTriggeredDisplayLoggingEnabled = false;
private void handleLogging(PropertyChangeEvent e) {
if (e.getPropertyName().equals("KnownState")) { // NOI18N
CTCJythonAccessInstanceManager._mCTCDebug_TrafficLockingRuleTriggeredDisplayLoggingEnabled = (int)e.getNewValue() == Sensor.ACTIVE;
if (CTCJythonAccessInstanceManager._mCTCDebug_TrafficLockingRuleTriggeredDisplayLoggingEnabled) _mLockedRoutesManager.dump();
_mCTCDebug_TrafficLockingRuleTriggeredDisplayLoggingEnabled = (int)e.getNewValue() == Sensor.ACTIVE;
if (_mCTCDebug_TrafficLockingRuleTriggeredDisplayLoggingEnabled) _mLockedRoutesManager.dump();
}
}

@@ -17,7 +17,7 @@

public class TrafficLocking {
private final static Logger log = LoggerFactory.getLogger(TrafficLocking.class);

private static class TrafficLockingRecord {
private final SwitchIndicatorsRoute _mSwitchIndicatorsRoute;
private final SignalDirectionIndicatorsInterface _mOSSignalDirectionIndicatorsInterfaceInterface1;
@@ -37,7 +37,7 @@
private final NBHSensor _mOptionalSensor1;
private final NBHSensor _mOptionalSensor2;
private final boolean _mRuleEnabled;

public TrafficLockingRecord(String userIdentifier,
String parameter,
NBHSensor switchIndicator1,
@@ -81,7 +81,7 @@ public TrafficLockingRecord(String userIdentifier,
_mOptionalSensor2 = new NBHSensor("TrafficLocking", userIdentifier, parameter + " optionalSensor2", optionalSensor2, true); // NOI18N
_mRuleEnabled = !ruleEnabled.equals(Bundle.getMessage("TLE_RuleDisabled")); // NOI18N Any problem, default is ENABLED!
}

public boolean isEnabled() { return _mRuleEnabled; }
public boolean isValid(int directionRequested) {
if (!_mRuleEnabled) return false; // If disabled, treat as invalid so we skip this rule and try the next rule.
@@ -98,7 +98,7 @@ public boolean isValid(int directionRequested) {
if (!_mSwitchIndicatorsRoute.isRouteSelected()) return false;
if (!isOptionalSensorActive(_mOptionalSensor1)) return false;
if (!isOptionalSensorActive(_mOptionalSensor2)) return false;

// Check for any opposing direction or running time O.S. sections. If so, return "false" immediately:
ArrayList<SignalDirectionIndicatorsInterface> sidiCheckList = new ArrayList<>();
sidiCheckList.add(_mOSSignalDirectionIndicatorsInterfaceInterface1);
@@ -118,8 +118,8 @@ public boolean isValid(int directionRequested) {
}
return true;
}
// Put all non null and valid OCCUPANCY NBHSensor's in a HashSet and return it (the "ROUTE"!) for use by LockedRoutesManager.

// Put all non null and valid OCCUPANCY NBHSensor's in a HashSet and return it (the "ROUTE"!) for use by LockedRoutesManager.
public HashSet<Sensor> getOccupancySensors() {
HashSet<Sensor> returnValue = new HashSet<>();
if (_mOccupancyExternalSensor1 != null && _mOccupancyExternalSensor1.valid()) returnValue.add(_mOccupancyExternalSensor1.getBean());
@@ -134,39 +134,39 @@ public boolean isValid(int directionRequested) {
returnValue.remove(null); // Safety: Remove null entry if it exists (There will ONLY be one in a set!)
return returnValue;
}

// Quick and Dirty Routine: If it doesn't exist, it's lit. If it exists, ACTIVE = lit. Can't use CTCMain.getSensorKnownState() because of this.
private boolean isOptionalSensorActive(NBHSensor sensor) {
if (sensor.valid()) return sensor.getKnownState() == Sensor.ACTIVE;
return true; // Doesn't exist.
}

}

private final ArrayList<TrafficLockingRecord> _mLeftTrafficLockingRulesArrayList = new ArrayList<>();
private final ArrayList<TrafficLockingRecord> _mRightTrafficLockingRulesArrayList = new ArrayList<>();
private final String _mUserIdentifier;
private final String _mLeftTrafficLockingRulesSSVList;
private final String _mRightTrafficLockingRulesSSVList;
private final LockedRoutesManager _mLockedRoutesManager;

public TrafficLocking(String userIdentifier, String leftTrafficLockingRulesSSVList, String rightTrafficLockingRulesSSVList, LockedRoutesManager lockedRoutesManager)
{
_mUserIdentifier = userIdentifier; // Squirrel it
_mUserIdentifier = userIdentifier; // Squirrel it
_mLeftTrafficLockingRulesSSVList = leftTrafficLockingRulesSSVList; // away for later
_mRightTrafficLockingRulesSSVList = rightTrafficLockingRulesSSVList; // "fileReadComplete"
_mLockedRoutesManager = lockedRoutesManager;
}

public void removeAllListeners() {} // None done.

// Since the user may specify "forward referenced" O/S sections (i.e. an entry references an O.S. section that hasn't been read in and created yet),
// we delay processing of everything until after the file has been completely read in. Here we do the real work:
// we delay processing of everything until after the file has been completely read in. Here we do the real work:
public void fileReadComplete(HashMap<Integer, CodeButtonHandler> cbHashMap, HashMap<Integer, SignalDirectionIndicatorsInterface> sidiHashMap, HashMap<Integer, SwitchDirectionIndicators> swdiHashMap) {
addAllTrafficLockingEntries(_mUserIdentifier, _mLeftTrafficLockingRulesSSVList, "leftTrafficLockingRulesSSVList", cbHashMap, sidiHashMap, swdiHashMap, _mLeftTrafficLockingRulesArrayList); // NOI18N
addAllTrafficLockingEntries(_mUserIdentifier, _mRightTrafficLockingRulesSSVList, "rightTrafficLockingRulesSSVList", cbHashMap, sidiHashMap, swdiHashMap, _mRightTrafficLockingRulesArrayList); // NOI18N
}

private void addAllTrafficLockingEntries( String userIdentifier,
String trafficLockingRulesSSVList,
String parameter,
@@ -217,7 +217,7 @@ public TrafficLockingInfo valid(int presentSignalDirectionLever) {
if (presentSignalDirectionLever == CTCConstants.LEFTTRAFFIC) return validForTraffic(presentSignalDirectionLever, _mLeftTrafficLockingRulesArrayList);
return validForTraffic(presentSignalDirectionLever, _mRightTrafficLockingRulesArrayList);
}

private TrafficLockingInfo validForTraffic(int presentSignalDirectionLever, ArrayList<TrafficLockingRecord> trafficLockingEntryArrayList) {
TrafficLockingInfo returnValue = new TrafficLockingInfo(true); // ASSUME valid return status
if (trafficLockingEntryArrayList.isEmpty()) return returnValue; // No rules, OK all of the time.
@@ -227,7 +227,7 @@ private TrafficLockingInfo validForTraffic(int presentSignalDirectionLever, Arra
if (trafficLockingEntryArrayList.get(index).isEnabled()) { anyEnabled = true; break; }
}
if (!anyEnabled) return returnValue; // None enabled, always allow.

for (int index = 0; index < trafficLockingEntryArrayList.size(); index++) {
TrafficLockingRecord trafficLockingRecord = trafficLockingEntryArrayList.get(index);
if (trafficLockingRecord.isValid(presentSignalDirectionLever)) {
@@ -236,28 +236,28 @@ private TrafficLockingInfo validForTraffic(int presentSignalDirectionLever, Arra
String ruleNumber = Integer.toString(index+1);
returnValue._mLockedRoute = _mLockedRoutesManager.checkRouteAndAllocateIfAvailable(trafficLockingRecord.getOccupancySensors(), _mUserIdentifier, "Rule #" + ruleNumber);
if (returnValue._mLockedRoute != null) { // OK:
if (CTCJythonAccessInstanceManager._mCTCDebug_TrafficLockingRuleTriggeredDisplayLoggingEnabled) log.info("Rule {} valid", ruleNumber);
if (jmri.InstanceManager.getDefault(CTCMain.class)._mCTCDebug_TrafficLockingRuleTriggeredDisplayLoggingEnabled) log.info("Rule {} valid", ruleNumber);
return returnValue;
}
}
}
returnValue._mReturnStatus = false;
return returnValue;
}

private NBHSensor getSwitchDirectionIndicatorSensor(int uniqueID, String switchAlignment, HashMap<Integer, SwitchDirectionIndicators> swdiHashMap) {
if (uniqueID < 0) return null;
boolean isNormalAlignment = !switchAlignment.equals(Bundle.getMessage("TLE_Reverse")); // NOI18N
SwitchDirectionIndicators switchDirectionIndicators = swdiHashMap.get(uniqueID);
if (switchDirectionIndicators == null) return null; // Safety, technically shouldn't happen....
return switchDirectionIndicators.getProperIndicatorSensor(isNormalAlignment);
}

private int getUniqueID(String aString) {
return ProjectsCommonSubs.getIntFromStringNoThrow(aString, -1); // If a problem, -1!
}

/*
/*
private NBHSensor getOSSectionOccupancySensor(int uniqueID, HashMap<Integer, CodeButtonHandler> cbHashMap) {
if (uniqueID < 0) return null;
CodeButtonHandler codeButtonHandler = cbHashMap.get(uniqueID);
@@ -167,6 +167,7 @@ private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
setTitle(Bundle.getMessage("TitleDlgTRLRules"));
addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}

0 comments on commit def741d

Please sign in to comment.
You can’t perform that action at this time.