use of jmri.NamedBean in project JMRI by JMRI.
the class AbstractProxyManager method provideNamedBean.
/**
* Locate via user name, then system name if needed. If that fails, create a
* new NamedBean: If the name is a valid system name, it will be used for
* the new NamedBean. Otherwise, the makeSystemName method will attempt to
* turn it into a valid system name. Subclasses use this to create provider methods such as
* getSensor or getTurnout via casts.
*
* @param name the user name or system name of the bean
* @return an existing or new NamedBean
*/
protected NamedBean provideNamedBean(String name) throws IllegalArgumentException {
// make sure internal present
initInternal();
NamedBean t = getNamedBean(name);
if (t != null) {
return t;
}
// Doesn't exist. If the systemName was specified, find that system
int index = matchTentative(name);
if (index >= 0) {
return makeBean(index, name, null);
}
log.debug("provideNamedBean did not find manager for name " + name + ", defer to default");
return makeBean(0, getMgr(0).makeSystemName(name), null);
}
use of jmri.NamedBean in project JMRI by JMRI.
the class DefaultIdTagManager method getTagsForReporter.
@Override
public List<IdTag> getTagsForReporter(Reporter reporter, long threshold) {
List<IdTag> out = new ArrayList<>();
Date lastWhenLastSeen = new Date(0);
// and record the time most recently seen
for (NamedBean n : _tsys.values()) {
IdTag t = (IdTag) n;
if (t.getWhereLastSeen() == reporter) {
out.add(t);
if (t.getWhenLastSeen().after(lastWhenLastSeen)) {
lastWhenLastSeen = t.getWhenLastSeen();
}
}
}
if (out.size() > 0) {
// Calculate the threshold time based on the most recently seen tag
Date thresholdTime = new Date(lastWhenLastSeen.getTime() - threshold);
// Now remove from the list all tags seen prior to the threshold time
for (IdTag t : out) {
if (t.getWhenLastSeen().before(thresholdTime)) {
out.remove(t);
}
}
}
return out;
}
use of jmri.NamedBean in project JMRI by JMRI.
the class NamedBeanTest method testGetBeanParameter.
public void testGetBeanParameter() {
NamedBean n = createInstance();
n.setProperty("foo", "bar");
Assert.assertEquals("bar", n.getProperty("foo"));
}
use of jmri.NamedBean in project JMRI by JMRI.
the class NamedBeanTest method testGetSetNullBeanParameter.
public void testGetSetNullBeanParameter() {
NamedBean n = createInstance();
n.setProperty("foo", "bar");
Assert.assertEquals("bar", n.getProperty("foo"));
n.setProperty("foo", null);
Assert.assertEquals(null, n.getProperty("foo"));
}
use of jmri.NamedBean in project JMRI by JMRI.
the class NamedBeanTest method testDispose.
public void testDispose() {
NamedBean n = createInstance();
n.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent p) {
}
});
n.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent p) {
}
});
Assert.assertEquals("start length", 2, n.getNumPropertyChangeListeners());
n.dispose();
Assert.assertEquals("end length", 0, n.getNumPropertyChangeListeners());
}
Aggregations