View Javadoc
1   package au.gov.amsa.util.identity;
2   
3   import java.util.HashSet;
4   import java.util.Set;
5   
6   public final class MmsiValidator2 {
7   
8       private final Set<Long> bad = new HashSet<Long>();
9   
10      public static MmsiValidator2 INSTANCE = new MmsiValidator2();
11  
12      private MmsiValidator2() {
13          bad.add(123456789L);
14          bad.add(987654321L);
15          bad.add(111111111L);
16          bad.add(999999999L);
17          // multiple ships use these mmsi numbers
18          bad.add(107374182L);
19          bad.add(503499100L);
20          bad.add(503000000L);
21          bad.add(777777777L);
22          bad.add(333333333L);
23          bad.add(525123456L);
24          bad.add(273000000L);
25          bad.add(525000000L);
26          bad.add(100000000L);
27          bad.add(553111692L);
28          bad.add(888888888L);
29          bad.add(555555555L);
30          bad.add(273000000L);
31          bad.add(1193046L);
32          bad.add(222222222L);
33          bad.add(352286000L);
34          bad.add(352055000L);
35      }
36  
37      /**
38       * Returns true if and only if the <code>mmsi</code> is a series of 9 digits
39       * and is not one of a set of bad identifiers e.g. 123456789.
40       * 
41       * @param mmsi
42       * @return
43       */
44      public boolean isValid(long mmsi) {
45          return mmsi <= 999999999L && mmsi >= 1000000L && !bad.contains(mmsi);
46      }
47  }