View Javadoc

1   package nl.geozet.openls.client;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import nl.geozet.openls.databinding.openls.Address;
7   import nl.geozet.openls.databinding.openls.GeocodeResponse;
8   import nl.geozet.openls.databinding.openls.GeocodeResponseList;
9   import nl.geozet.openls.databinding.openls.GeocodedAddress;
10  import nl.geozet.openls.databinding.openls.OpenLSConstants;
11  
12  /**
13   * Utility klasse OpenLSClientUtil.
14   * 
15   * @author strampel@atlis.nl
16   */
17  public final class OpenLSClientUtil {
18  
19      /**
20       * Instantiates a new open ls client util.
21       */
22      private OpenLSClientUtil() {
23          /* private constructor voor deze utility klasse. */
24      }
25  
26      /**
27       * Gets the geocoded address list.
28       * 
29       * @param gcr
30       *            the gcr
31       * @return the geocoded address list
32       */
33      public static List<GeocodedAddress> getGeocodedAddressList(
34              GeocodeResponse gcr) {
35          final List<GeocodedAddress> addressList = new ArrayList<GeocodedAddress>();
36          for (int i = 0; i < gcr.getGeocodeResponseListSize(); i++) {
37              final GeocodeResponseList gcrl = gcr.getGeocodeResponseListAt(i);
38              for (int j = 0; j < gcrl.getGeocodedAddressSize(); j++) {
39                  final GeocodedAddress gca = gcrl.getGeocodedAddressAt(j);
40                  addressList.add(gca);
41              }
42          }
43          return addressList;
44      }
45  
46      /**
47       * Gets the open ls client address list.
48       * 
49       * @param gcr
50       *            the gcr
51       * @return the open ls client address list
52       */
53      public static List<OpenLSClientAddress> getOpenLSClientAddressList(
54              GeocodeResponse gcr) {
55          final List<OpenLSClientAddress> addressList = new ArrayList<OpenLSClientAddress>();
56          final List<GeocodedAddress> gcal = getGeocodedAddressList(gcr);
57          for (int i = 0; i < gcal.size(); i++) {
58              final GeocodedAddress gca = gcal.get(i);
59              final OpenLSClientAddress addr = new OpenLSClientAddress();
60  
61              if (!gca.hasPoint() || (gca.getPoint().getPosSize() == 0)) {
62                  continue;
63              }
64  
65              addr.setxCoord((gca.getPoint().getPosAt(0).getX()).toString());
66              addr.setyCoord((gca.getPoint().getPosAt(0).getY()).toString());
67  
68              if (gca.getAddress() != null) {
69                  final Address adr = gca.getAddress();
70                  if (adr.hasStreetAddress()
71                          && adr.getStreetAddress().hasStreet()) {
72                      addr.setStreetName(adr.getStreetAddress().getStreet()
73                              .getStreet());
74                  }
75                  if (adr.hasStreetAddress()
76                          && adr.getStreetAddress().hasBuilding()
77                          && adr.getStreetAddress().getBuilding().hasNumber()) {
78                      addr.setStreetNumber(adr.getStreetAddress().getBuilding()
79                              .getNumber());
80                  }
81                  if (adr.hasPostalCode() && adr.getPostalCode().hasPostalCode()) {
82                      addr.setPostalCode(adr.getPostalCode().getPostalCode());
83                  }
84                  if (adr.getPlaceByType(OpenLSConstants.PLACE_TYPE_COUNTRYSUBDIVISION) != null) {
85                      addr.setCountrySubdivision(adr
86                              .getPlaceByType(OpenLSConstants.PLACE_TYPE_COUNTRYSUBDIVISION));
87                  }
88                  if (adr.getPlaceByType(OpenLSConstants.PLACE_TYPE_MUNICIPALITY) != null) {
89                      addr.setMunicipality(adr
90                              .getPlaceByType(OpenLSConstants.PLACE_TYPE_MUNICIPALITY));
91                  }
92                  if (adr.getPlaceByType(OpenLSConstants.PLACE_TYPE_MUNICIPALITYSUBDIVISION) != null) {
93                      addr.setMunicipalitySubdivision(adr
94                              .getPlaceByType(OpenLSConstants.PLACE_TYPE_MUNICIPALITYSUBDIVISION));
95                  }
96              }
97              if (addr.isValidClientAddress()) {
98                  addressList.add(addr);
99              }
100         }
101         return addressList;
102     }
103 }