Commit 6e629106 authored by Deepak's avatar Deepak

Added java Doc

parent 0dc702b7
......@@ -11,8 +11,6 @@ public class OutcodeReverseGeocoding {
private static String outwardCode;
private static boolean nearest = false;
private static boolean latlong = false;
private static String latitude;
......@@ -29,9 +27,8 @@ public class OutcodeReverseGeocoding {
OutcodeReverseGeocoding.latlong = true;
}
protected OutcodeReverseGeocoding(String outwardCode, boolean nearest) {
protected OutcodeReverseGeocoding(String outwardCode) {
OutcodeReverseGeocoding.outwardCode = outwardCode;
OutcodeReverseGeocoding.nearest = nearest;
}
/**
......@@ -60,17 +57,13 @@ public class OutcodeReverseGeocoding {
public JSONObject asJson() throws UnirestException {
try {
if (nearest) {
return Unirest.get(OUTCODE_URL.concat(outwardCode).concat("/nearest"))
.queryString("limit", limit != 0 ? limit : 10)
.queryString("radius", radius != 0 ? radius : 5000).asJson().getBody().getObject();
}
if (latlong) {
return Unirest.get(OUTCODE_URL).queryString("lon", longitude).queryString("lat", latitude)
.queryString("limit", limit != 0 ? limit : 10)
.queryString("radius", radius != 0 ? radius : 5000).asJson().getBody().getObject();
}
return Unirest.get(OUTCODE_URL.concat(outwardCode)).asJson().getBody().getObject();
return latlong
? Unirest.get(OUTCODE_URL).queryString("lon", longitude).queryString("lat", latitude)
.queryString("limit", limit != 0 ? limit : 10)
.queryString("radius", radius != 0 ? radius : 5000).asJson().getBody().getObject()
: Unirest.get(OUTCODE_URL.concat(outwardCode).concat("/nearest"))
.queryString("limit", limit != 0 ? limit : 10)
.queryString("radius", radius != 0 ? radius : 5000).asJson().getBody().getObject();
} finally {
clear();
}
......@@ -79,7 +72,6 @@ public class OutcodeReverseGeocoding {
private void clear() {
latitude = null;
longitude = null;
nearest = false;
latlong = false;
limit = 0;
radius = 0;
......
......@@ -83,30 +83,78 @@ public class PostcodeLookup {
return new ReverseGeocoding(reverses);
}
/**
* Convenience method to get random postcode and all available data for that postcode.
*
* @return
*/
public static RandomPostcode randomPostcode() {
return new RandomPostcode();
}
/**
*
* Convenience method to validate a postcode. Returns true or false (meaning valid or invalid
* respectively)
*
* @param postcode
* @return
* @throws JSONException
* @throws UnirestException
*/
public static boolean isValid(String postcode) throws JSONException, UnirestException {
return Postcode.isValid(postcode);
}
/**
* Convenience method to get nearest outcodes for a given outcode.
*
* @param postcode
* @return
*/
public static NearestPostcode nearestPostcode(String postcode) {
return new NearestPostcode(postcode);
}
/**
* Convenience method to return an list of matching postcodes.
*
* @param postcode
* @return
*/
public static LimitPostcode autocomplete(String postcode) {
return new LimitPostcode(postcode);
}
/**
* Geolocation data for the centroid of the outward code specified. The outward code represents
* the first half of any postcode (separated by a space).
*
*
* @param outwardCode
* @return
*/
public static OutwardCode lookupOutwardCode(String outwardCode) {
return new OutwardCode(outwardCode);
}
/**
* Returns nearest outcodes for a given outcode.
*
* @param outwardCode
* @return
*/
public static OutcodeReverseGeocoding nearestOutwardCode(String outwardCode) {
return new OutcodeReverseGeocoding(outwardCode, true);
return new OutcodeReverseGeocoding(outwardCode);
}
/**
* Returns nearest outcodes for a given longitude and latitude.
*
* @param longitude
* @param latitude
* @return
*/
public static OutcodeReverseGeocoding outcodeReverseGeocoding(Double longitude, Double latitude) {
return new OutcodeReverseGeocoding(String.valueOf(longitude), String.valueOf(latitude));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment