View Javadoc

1   package se.citerus.dddsample.domain.model.location;
2   
3   import java.lang.reflect.Field;
4   import java.util.ArrayList;
5   import java.util.HashMap;
6   import java.util.List;
7   import java.util.Map;
8   
9   /**
10   * Sample locations, for test purposes.
11   * 
12   */
13  public class SampleLocations {
14  
15    public static final Location HONGKONG = new Location(new UnLocode("CNHKG"), "Hongkong");
16    public static final Location MELBOURNE = new Location(new UnLocode("AUMEL"), "Melbourne");
17    public static final Location STOCKHOLM = new Location(new UnLocode("SESTO"), "Stockholm");
18    public static final Location HELSINKI = new Location(new UnLocode("FIHEL"), "Helsinki");
19    public static final Location CHICAGO = new Location(new UnLocode("USCHI"), "Chicago");
20    public static final Location TOKYO = new Location(new UnLocode("JNTKO"), "Tokyo");
21    public static final Location HAMBURG = new Location(new UnLocode("DEHAM"), "Hamburg");
22    public static final Location SHANGHAI = new Location(new UnLocode("CNSHA"), "Shanghai");
23    public static final Location ROTTERDAM = new Location(new UnLocode("NLRTM"), "Rotterdam");
24    public static final Location GOTHENBURG = new Location(new UnLocode("SEGOT"), "Göteborg");
25    public static final Location HANGZOU = new Location(new UnLocode("CNHGH"), "Hangzhou");
26    public static final Location NEWYORK = new Location(new UnLocode("USNYC"), "New York");
27    public static final Location DALLAS = new Location(new UnLocode("USDAL"), "Dallas");
28  
29    public static final Map<UnLocode, Location> ALL = new HashMap<UnLocode, Location>();
30  
31    static {
32      for (Field field : SampleLocations.class.getDeclaredFields()) {
33        if (field.getType().equals(Location.class)) {
34          try {
35            Location location = (Location) field.get(null);
36            ALL.put(location.unLocode(), location);
37          } catch (IllegalAccessException e) {
38            throw new RuntimeException(e);
39          }
40        }
41      }
42    }
43  
44    public static List<Location> getAll() {
45      return new ArrayList<Location>(ALL.values());
46    }
47  
48    public static Location lookup(UnLocode unLocode) {
49      return ALL.get(unLocode);
50    }
51  
52  }