tananaev/traccar — pull request #918 by jon-stumpf (2014-10-11 03:29:39+00:00)
Title: Eliminate hardcoded protocol names

In my work, I found that hardcoded strings representing protocol names were being used in the ProtocolDecoder files (e.g., ./src/org/traccar/protocol/*ProtocolDecoder.java). This required the programmer to ensure that the strings in the ProtocolDecoders were kept in-sync with the strings passed to the init*Server() functions in ServerManager.init() in file ./src/org/traccar/ServerManager.java. The first commit in this PULL request changes the constructor in the BaseProtocolDecoder class to include a second parameter (String protocol) so that the string passed to the Init*Server() function will be the same string used in ProtocolDecoder. The pattern for this change is small:

Two lines per protocol in ServerManager.java (the same two lines);
Seven lines per protocol in each ProtocolDecoder.java (the same seven lines);

While addressing the above, I noticed that the members in BaseProtocolDecoder were not "final" and had corresponding setter function. These members should not change after initial construction. In the second commit, I changed the members to "final", eliminate the setter functions, and create a specific constructor for the ProtocolDecoderTest classes. The pattern for this change is very small: I collapse two lines of code into one (per protocol) using the special constructor.

The bulk of the work occurs in src/org/traccar/BaseProtocolDecoder.java for both commits. All other changes, albeit pervasive, are the identical.

Both commits have been tested against the test cases found under the tools directory. Output is identical.