Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some code smells. #180

Merged
merged 11 commits into from
Jul 25, 2018
Merged

Fixed some code smells. #180

merged 11 commits into from
Jul 25, 2018

Conversation

@@ -81,8 +81,8 @@ public static Location forStringLongitudeLatitude(final String locationString)
{
throw new CoreException("Invalid Location String: {}", locationString);
}
final double latitude = Double.valueOf(split.get(1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to be a little careful with using parseDouble functions. They can throw NumberFormatExceptions if the string you are parsing is not valid. And it seems like you don't handle that exception in this function and the one above. I would suggest throwing it from the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is certainly true. In fact, the original Double.valueOf call had the same problem, if we check out the implementation in java.lang.Double

public static Double valueOf(String s) throws NumberFormatException {
        return new Double(parseDouble(s));
}

I am a little hesitant about declaring NumberFormatException to be thrown at the function level, since it is a RuntimeException, and in general we avoid declaring those explicitly in the Atlas codebase (clutters the function signature). However, in this case it may be worth it, since it would be possible for the caller to recover from invalid input.

@@ -142,7 +141,7 @@ public Rectangle bounds()
if (this.bounds == null && !this.isEmpty())
{
final Set<Location> locations = new HashSet<>();
forEach(polygon -> polygon.forEach(location -> locations.add(location)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice I really like this type of code style, much easier to read in my opinion.

@@ -99,11 +99,10 @@ public GeoJsonObject asGeoJson()
public GeoJsonObject asGeoJsonFeatureCollection()
{
final GeoJsonBuilder builder = new GeoJsonBuilder();
return builder.createFeatureCollection(Iterables.translate(outers(), outerPolygon ->
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh common sonar, have mercy, I did this for clarity

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sonar has spoken. Question not its wisdom. :D

{
poorlyFormattedFile.printStackTrace();
});
.ifPresent(poorlyFormattedFile -> poorlyFormattedFile.printStackTrace());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The continue with the nice style @mgcuthbert referred to above, what about

.ifPresent(StreamCorruptedException::printStackTrace);

@MikeGost MikeGost merged commit 3740c67 into osmlab:dev Jul 25, 2018
@lucaspcram lucaspcram deleted the codesmells branch July 25, 2018 22:18
@MikeGost MikeGost mentioned this pull request Jul 25, 2018
@matthieun matthieun added this to the 5.1.5 milestone Jul 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants