001package jmri.jmrix.lenz.messageformatters; 002 003import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 004import jmri.jmrix.Message; 005import jmri.jmrix.lenz.XNetConstants; 006import jmri.jmrix.lenz.XNetReply; 007import jmri.jmrix.lenz.XPressNetMessageFormatter; 008 009/** 010 * XPressNet message formatter for throttle taken over reply. 011 * 012 * @author Paul Bender Copyright (C) 2024 013 */ 014public class XNetThrottleTakenOverReplyFormatter implements XPressNetMessageFormatter { 015 016 @Override 017 public boolean handlesMessage(Message m) { 018 return m instanceof XNetReply && ((XNetReply) m).getElement(0) == XNetConstants.LOCO_INFO_RESPONSE 019 && ((XNetReply) m).getElement(1) == XNetConstants.LOCO_NOT_AVAILABLE; 020 } 021 022 @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "cast is checked in handlesMessage") 023 @Override 024 public String formatMessage(Message m) { 025 if (handlesMessage(m)) { 026 XNetReply reply = (XNetReply) m; 027 int address = reply.getThrottleMsgAddr(); 028 return Bundle.getMessage("XNetReplyLocoLabel") + " " + 029 Bundle.getMessage("rsType") + " " + address + " " + 030 Bundle.getMessage("XNetReplyLocoOperated"); 031 } 032 throw new IllegalArgumentException("Message is not supported"); 033 } 034 035}