mirror of
https://bitbucket.org/akapribot/owm-japis.git
synced 2025-04-28 08:28:12 -07:00
Fixed bug of wrong data and time and improved code formatting.
This commit is contained in:
parent
4535ffd037
commit
0e90f5dcda
6 changed files with 1513 additions and 1184 deletions
|
@ -28,15 +28,15 @@ import java.net.URL;
|
|||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* Provides various tools, which help doing tasks in this application.
|
||||
* For example, tool for downloading content from the Internet, tool for
|
||||
* correcting, etc.
|
||||
*
|
||||
* <p>Note: This class directly do not provide any functions, but has
|
||||
* <code>static</code> sub-classes which provide various
|
||||
* related tools, i.e., this class only behaves as the container for those
|
||||
* classes.
|
||||
*
|
||||
* Provides various tools, which help doing tasks in this application. For
|
||||
* example, tool for downloading content from the Internet, tool for correcting,
|
||||
* etc.
|
||||
* <p>
|
||||
* <p>
|
||||
* Note: This class directly do not provide any functions, but has
|
||||
* <code>static</code> sub-classes which provide various related tools, i.e.,
|
||||
* this class only behaves as the container for those classes.
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2014-07-01
|
||||
* @since 2.5.0.1
|
||||
|
@ -45,7 +45,7 @@ public class Tools {
|
|||
|
||||
/**
|
||||
* Provides methods to download data or files from the Internet.
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013-07-24
|
||||
* @since 2.5.0.1
|
||||
|
@ -53,123 +53,105 @@ public class Tools {
|
|||
public static class Downloader {
|
||||
|
||||
/**
|
||||
* Downloads a page/content from the Internet.
|
||||
* This method gets the content of the web page, whose URL is given by
|
||||
* the <code>pageAddress</code>.
|
||||
*
|
||||
* <p>NOTE: <code>pageAddress</code> should be a correct URL, else
|
||||
* this method will throw {@link MalformedURLException}.
|
||||
*
|
||||
* @param pageAddress
|
||||
* Address of the web page to get from the Internet.
|
||||
*
|
||||
* Downloads a page/content from the Internet. This method gets the
|
||||
* content of the web page, whose URL is given by the
|
||||
* <code>pageAddress</code>.
|
||||
* <p>
|
||||
* <p>
|
||||
* NOTE: <code>pageAddress</code> should be a correct URL, else this
|
||||
* method will throw {@link MalformedURLException}.
|
||||
* <p>
|
||||
* @param pageAddress Address of the web page to get from the Internet.
|
||||
* <p>
|
||||
* @return Content of the web page
|
||||
*
|
||||
* @throws MalformedURLException
|
||||
* Address of the web page is not correct.
|
||||
*
|
||||
* @throws IOException
|
||||
* Error while loading the page from the Internet or connection
|
||||
* got disconnected.
|
||||
* <p>
|
||||
* @throws MalformedURLException Address of the web page is not correct.
|
||||
* <p>
|
||||
* @throws IOException Error while loading the page from the
|
||||
* Internet or connection got
|
||||
* disconnected.
|
||||
*/
|
||||
public static String downloadPage(String pageAddress)
|
||||
public static String downloadPage(String pageAddress)
|
||||
throws MalformedURLException, IOException {
|
||||
String webPage = null;
|
||||
|
||||
URL url = new URL(pageAddress);
|
||||
InputStream iStream = url.openStream();
|
||||
|
||||
if (iStream != null) {
|
||||
if (iStream != null) {
|
||||
// converting InputStream to String (as we require String)
|
||||
webPage = (new Scanner(iStream)).useDelimiter("\\A").next();
|
||||
webPage = (new Scanner(iStream)).useDelimiter("\\A").next();
|
||||
}
|
||||
iStream.close();
|
||||
|
||||
return webPage;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Provides methods to do conversions.
|
||||
* For example, converting degree to direction, etc.
|
||||
*
|
||||
* Provides methods to do conversions. For example, converting degree to
|
||||
* direction, etc.
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/05
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
public static class Convertor {
|
||||
|
||||
|
||||
/**
|
||||
* Converts degree to direction.
|
||||
* @param degree
|
||||
* <p>
|
||||
* @param degree <p>
|
||||
* @return Direction
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* Degree should be between 0 and 360.
|
||||
* <p>
|
||||
* @throws IllegalArgumentException Degree should be between 0 and 360.
|
||||
*/
|
||||
public String convertDegree2Direction(float degree)
|
||||
throws IllegalArgumentException{
|
||||
public String convertDegree2Direction(float degree)
|
||||
throws IllegalArgumentException {
|
||||
String direction;
|
||||
|
||||
|
||||
// degree should be between 0 and 360
|
||||
if ((degree < 0.0f) || (degree > 360.0f)) {
|
||||
throw new IllegalArgumentException("Degree cannot be less than 0 or more than 360.");
|
||||
}
|
||||
|
||||
|
||||
if (degree <= 11.25f) {
|
||||
direction = "N";
|
||||
}
|
||||
else if (degree <= 33.75f) {
|
||||
} else if (degree <= 33.75f) {
|
||||
direction = "NNE";
|
||||
}
|
||||
else if (degree <= 56.25f) {
|
||||
} else if (degree <= 56.25f) {
|
||||
direction = "NE";
|
||||
}
|
||||
else if (degree <= 78.75f) {
|
||||
} else if (degree <= 78.75f) {
|
||||
direction = "ENE";
|
||||
}
|
||||
else if (degree <= 101.25f) {
|
||||
} else if (degree <= 101.25f) {
|
||||
direction = "E";
|
||||
}
|
||||
else if (degree <= 123.75f) {
|
||||
} else if (degree <= 123.75f) {
|
||||
direction = "ESE";
|
||||
}
|
||||
else if (degree <= 146.25f) {
|
||||
} else if (degree <= 146.25f) {
|
||||
direction = "SE";
|
||||
}
|
||||
else if (degree <= 168.75f) {
|
||||
} else if (degree <= 168.75f) {
|
||||
direction = "SSE";
|
||||
}
|
||||
else if (degree <= 191.25f) {
|
||||
} else if (degree <= 191.25f) {
|
||||
direction = "S";
|
||||
}
|
||||
else if (degree <= 213.75f) {
|
||||
} else if (degree <= 213.75f) {
|
||||
direction = "SSW";
|
||||
}
|
||||
else if (degree <= 236.25f) {
|
||||
} else if (degree <= 236.25f) {
|
||||
direction = "SW";
|
||||
}
|
||||
else if (degree <= 258.75f) {
|
||||
} else if (degree <= 258.75f) {
|
||||
direction = "WSW";
|
||||
}
|
||||
else if (degree <= 281.25f) {
|
||||
} else if (degree <= 281.25f) {
|
||||
direction = "W";
|
||||
}
|
||||
else if (degree <= 303.75f) {
|
||||
} else if (degree <= 303.75f) {
|
||||
direction = "WNW";
|
||||
}
|
||||
else if (degree <= 326.25f) {
|
||||
} else if (degree <= 326.25f) {
|
||||
direction = "NW";
|
||||
}
|
||||
else if (degree <= 348.75f) {
|
||||
} else if (degree <= 348.75f) {
|
||||
direction = "NNW";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
direction = "N";
|
||||
}
|
||||
|
||||
return direction;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue