001package jmri.jmrix.can.cbus.eventtable; 002 003import java.util.HashSet; 004import java.util.Set; 005import jmri.NamedBean; 006 007/** 008 * Class to provide access to the EventTableData.xml file. 009 * @author Steve Young Copyright (C) 2020 010 */ 011public class CbusEventBeanData { 012 013 private final Set<NamedBean> _nbActiveA; 014 private final Set<NamedBean> _nbActiveB; 015 016 public CbusEventBeanData( Set<NamedBean> nbActiveA, Set<NamedBean> nbActiveB) { 017 _nbActiveA = nbActiveA; 018 _nbActiveB = nbActiveB; 019 } 020 021 public CbusEventBeanData( Set<NamedBean> nbActiveA, Set<NamedBean> nbActiveB, 022 Set<NamedBean> nbInActiveA, Set<NamedBean> nbInActiveB, CbusTableEvent.EvState state ) { 023 _nbActiveA = ( state== CbusTableEvent.EvState.ON ? nbActiveA : nbInActiveA); 024 _nbActiveB = ( state== CbusTableEvent.EvState.ON ? nbActiveB : nbInActiveB); 025 } 026 027 @Override 028 public String toString(){ 029 StringBuilder sb = new StringBuilder(); 030 _nbActiveA.forEach((n) -> appendFromNb( n, sb, true) ); 031 _nbActiveB.forEach((n) -> appendFromNb( n, sb, false) ); 032 return sb.toString().trim(); 033 } 034 035 private void appendFromNb( NamedBean bean, StringBuilder sb, boolean beanOn) { 036 sb.append(bean.getBeanType()).append(" "); 037 sb.append( bean.describeState(beanOn? jmri.DigitalIO.ON : jmri.DigitalIO.OFF)).append(": "); 038 sb.append(bean.getDisplayName()).append(" "); 039 } 040 041 public Set<NamedBean> getActionA(){ 042 return new HashSet<> ( _nbActiveA); 043 } 044 045 public Set<NamedBean> getActionB(){ 046 return new HashSet<> ( _nbActiveB); 047 } 048 049}