001package jmri.jmrit.symbolicprog; 002 003/** 004 * Encapulates DCC address handling logic in one place 005 * 006 * <p> 007 * Expects one or more of the variables called: 008 * <ul> 009 * <li>primaryAddr - Short Address 010 * <li>extendAddr - Long Address 011 * <li>addMode - Address Format (an Enum variable to select) 012 * </ul> 013 * and handles the cases where: 014 * <ul> 015 * <li>All three are present - the normal advanced decoder case 016 * <li>Short Address is present and Long Address is not 017 * <li>Long Address is present and Short Address is not 018 * </ul> 019 * At least one of Short Address and Long Address must be present! 020 * 021 * @author Bob Jacobsen Copyright (C) 2013 022 */ 023public class DccAddressVarHandler { 024 025 public DccAddressVarHandler(VariableValue primaryAddr, VariableValue extendAddr, EnumVariableValue addMode) { 026 // check if only primary, or primary selected 027 if (extendAddr == null || (addMode != null && !addMode.getValueString().equals("1"))) { 028 if (primaryAddr != null) { 029 doPrimary(); 030 } 031 } else { 032 doExtended(); 033 } 034 } 035 036 /** 037 * Handle case of primary address valid 038 */ 039 protected void doPrimary() { 040 } 041 042 /** 043 * Handle case of extended address valid 044 */ 045 protected void doExtended() { 046 } 047}