Skip to content
Permalink
Browse files

Normalize Turnouts + Lights

  • Loading branch information...
icklesteve committed Dec 29, 2018
1 parent fc2acc3 commit 9a94c32a51b62cdef9699d8f63ade959d02a6f21
@@ -1,5 +1,8 @@
package jmri.jmrix.can.cbus;

import javax.annotation.CheckForNull;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import jmri.JmriException;
import jmri.Light;
import jmri.jmrix.can.CanSystemConnectionMemo;
@@ -31,6 +34,27 @@ public String getSystemPrefix() {
return prefix;
}

/**
* {@inheritDoc}
* Overriden to normalize System Name
*/
@Override
@Nonnull
public Light provideLight(@Nonnull String key) {
String name = normalizeSystemName(key);
Light t = getLight(name);
if (t == null) {
if (name.startsWith(getSystemPrefix() + typeLetter())) {
return newLight(name, null);
} else if (name.length() > 0) {
return newLight(makeSystemName(name), null);
} else {
throw new IllegalArgumentException("\"" + name + "\" is invalid");
}
}
return t;
}

/**
* Internal method to invoke the factory, after all the logic for returning
* an existing method has been invoked.
@@ -60,6 +84,9 @@ protected Light createNewLight(String systemName, String userName) {
return l;
}

/**
* {@inheritDoc}
*/
@Override
public boolean allowMultipleAdditions(String systemName) {
return false;
@@ -95,6 +122,9 @@ public String getNextValidAddress(String curAddress, String prefix) throws JmriE
return curAddress;
}

/**
* {@inheritDoc}
*/
@Override
public NameValidity validSystemNameFormat(String systemName) {
String addr = systemName.substring(getSystemPrefix().length() + 1); // get only the address part
@@ -138,6 +168,9 @@ void validateSystemNameFormat(String address) throws IllegalArgumentException {
}
}

/**
* {@inheritDoc}
*/
@Override
public boolean validSystemNameConfig(String systemName) {
String addr = systemName.substring(getSystemPrefix().length() + 1);
@@ -150,6 +183,31 @@ public boolean validSystemNameConfig(String systemName) {
return true;
}

/**
* {@inheritDoc}
*/
@Override
@CheckForNull
public Light getBySystemName(@Nonnull String key ) {
String name = normalizeSystemName(key);
return _tsys.get(name);
}

/**
* {@inheritDoc}
*
* Forces upper case and trims leading and trailing whitespace.
* Does not check for valid prefix, hence doesn't throw NamedBean.BadSystemNameException.
*/
@CheckReturnValue
@Override
public @Nonnull
String normalizeSystemName(@Nonnull String inputName) {
// does not check for valid prefix, hence doesn't throw NamedBean.BadSystemNameException
return inputName.toUpperCase().trim();
}


/**
* {@inheritDoc}
*/
@@ -1,5 +1,7 @@
package jmri.jmrix.can.cbus;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import jmri.JmriException;
import jmri.Turnout;
import jmri.jmrix.can.CanSystemConnectionMemo;
@@ -31,6 +33,27 @@ public String getSystemPrefix() {
return prefix;
}

/**
* {@inheritDoc}
* Overriden to normalize System Name
*/
@Override
public Turnout provideTurnout(@Nonnull String key) {
String name = normalizeSystemName(key);
Turnout result = getTurnout(name);
if (result == null) {
if (name.startsWith(getSystemPrefix() + typeLetter())) {
result = newTurnout(name, null);
} else {
result = newTurnout(makeSystemName(name), null);
}
}
return result;
}

/**
* {@inheritDoc}
*/
@Override
protected Turnout createNewTurnout(String systemName, String userName) {
String addr = systemName.substring(getSystemPrefix().length() + 1);
@@ -54,11 +77,17 @@ protected Turnout createNewTurnout(String systemName, String userName) {
return t;
}

/**
* {@inheritDoc}
*/
@Override
public boolean allowMultipleAdditions(String systemName) {
return false;
}

/**
* {@inheritDoc}
*/
@Override
public String createSystemName(String curAddress, String prefix) throws JmriException {
// first, check validity
@@ -80,6 +109,9 @@ public String createSystemName(String curAddress, String prefix) throws JmriExce
return getSystemPrefix() + typeLetter() + curAddress;
}

/**
* {@inheritDoc}
*/
@Override
public String getNextValidAddress(String curAddress, String prefix) throws JmriException {
// always return this (the current) name without change
@@ -134,6 +166,29 @@ void validateSystemNameFormat(String address) throws IllegalArgumentException {
}
}


/** {@inheritDoc} */
@Override
public Turnout getBySystemName(@Nonnull String key) {
String name = normalizeSystemName(key);
return _tsys.get(name);
}

/**
* {@inheritDoc}
*
* Forces upper case and trims leading and trailing whitespace.
* Does not check for valid prefix, hence doesn't throw NamedBean.BadSystemNameException.
*/
@CheckReturnValue
@Override
public @Nonnull
String normalizeSystemName(@Nonnull String inputName) {
// does not check for valid prefix, hence doesn't throw NamedBean.BadSystemNameException
return inputName.toUpperCase().trim();
}


/**
* {@inheritDoc}
*/

0 comments on commit 9a94c32

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