View Javadoc
1   package au.gov.amsa.ais;
2   
3   import java.math.BigInteger;
4   
5   import com.google.common.annotations.VisibleForTesting;
6   
7   /**
8    * Decodes the AtoN type code as per Table 71 in 1371-4.pdf.
9    * 
10   * @author pxg
11   * 
12   */
13  public final class AtonTypeDecoder {
14  
15  	/**
16  	 * Private constructor.
17  	 */
18  	private AtonTypeDecoder() {
19  		// private constructor.
20  	}
21  
22  	/**
23  	 * Visible for test coverage only (calls the private constructor).
24  	 */
25  	@VisibleForTesting
26  	static void forTestCoverageOnly() {
27  		new AtonTypeDecoder();
28  	}
29  
30  	private static String[] categoryTypes = { "Fixed - ", "Floating - " };
31  
32  	private static String[] atonTypes = { "Not specified", "Reference point",
33  			"RACON", "Fixed structure", "Reserved for future use",
34  			"Light, without sectors", "Light, with sectors",
35  			"Leading Light Front", "Leading Light Rear", "Beacon, Cardinal N",
36  			"Beacon, Cardinal E", "Beacon, Cardinal S", "Beacon, Cardinal W",
37  			"Beacon, Port hand", "Beacon, Starboard hand",
38  			"Beacon, Preferred Channel port hand",
39  			"Beacon, Preferred Channel starboard hand",
40  			"Beacon, Isolated danger", "Beacon, Safe water",
41  			"Beacon, Special mark", "Cardinal Mark N", "Cardinal Mark E",
42  			"Cardinal Mark S", "Cardinal Mark W", "Port hand Mark",
43  			"Starboard hand Mark", "Preferred Channel Port hand",
44  			"Preferred Channel Starboard hand", "Isolated danger",
45  			"Safe Water", "Special Mark", "Light Vessel, LANBY, Rigs" };
46  
47  	/**
48  	 * Returns the AtoN type for given integer. If integer is null then returns
49  	 * null.
50  	 * 
51  	 * @param ts
52  	 * @return
53  	 */
54  	public static String getAtonType(BigInteger ts) {
55  		if (ts == null)
56  			return null;
57  		else
58  			return getAtonType(ts.intValue());
59  	}
60  
61  	/**
62  	 * Returns the AtoN type for given integer. If integer is null then returns
63  	 * null.
64  	 * 
65  	 * @param ts
66  	 * @return
67  	 */
68  	public static String getAtonType(Integer ts) {
69  		if (ts == null)
70  			return null;
71  		if (ts < 0 || ts > 31) {
72  			return "unknown code " + ts.intValue();
73  		} else {
74  			if (ts >= 0 && ts < 5) {
75  				return atonTypes[ts];
76  			} else if (ts < 20) {
77  				return categoryTypes[0] + atonTypes[ts];
78  			} else {
79  				return categoryTypes[1] + atonTypes[ts];
80  			}
81  		}
82  	}
83  
84  }