Skip to content

Commit

Permalink
Added getPrintName
Browse files Browse the repository at this point in the history
  • Loading branch information
kloverde committed Jun 16, 2018
1 parent 903e9fb commit 6a9458c
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Release 4.2 (June 16, 2018)

* Added a `getPrintName` method to the `CompassDirection` classes. This returns a grammatically correct version of `name()`, changing all letters to lowercase and all underscores to spaces


# Release 4.1.1 (June 13, 2018)

* Fixed incorrect exception messages. When supplying an invalid value to the Latitude(double) or Longitude(double) constructors, the resulting exception message said that the lower bound for valid values was 0. This is incorrect when using floating-point notation; valid values can be negative. The actual validation logic was correct - this was only an issue with the literal text of the error message.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GeographicCoordinate 4.1.1
==========================
GeographicCoordinate 4.2
========================

See LICENSE for this software's licensing terms.

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ buildScriptsDir=../BuildScripts
# BuildScripts configuration

projectName=GeographicCoordinate
releaseVersion=4.1.1
specVersion=3.0
releaseVersion=4.2
specVersion=4.2
javaSourceCompatibility=1.10
javaTargetCompatibility=1.10
jarName=geographiccoordinate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
public interface CompassDirection {

public String getAbbreviation();
public String getPrintName();
public BigDecimal getMinimum();
public BigDecimal getMiddle();
public BigDecimal getMaximum();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ public String getAbbreviation() {
return abbreviation;
}

/**
* @return A visually friendly, grammatically correct transformation of {@link #name()}, with all lowercase letters, and underscores changed to spaces
*/
@Override
public String getPrintName() {
return name().toLowerCase().replaceAll( "_", " " );
}

/**
* @return The lower bound for a given direction
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ public String getAbbreviation() {
return abbreviation;
}

/**
* @return A visually friendly, grammatically correct transformation of {@link #name()}, with all lowercase letters, and underscores changed to spaces
*/
@Override
public String getPrintName() {
return name().toLowerCase().replaceAll( "_", " " );
}

/**
* @return The lower bound for a given direction
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ public String getAbbreviation() {
return abbreviation;
}

/**
* @return A visually friendly, grammatically correct transformation of {@link #name()}, with all lowercase letters, and underscores changed to spaces
*/
@Override
public String getPrintName() {
return name().toLowerCase().replaceAll( "_", " " );
}

/**
* @return The lower bound for a given direction
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,24 @@ public void getByBearing_invalidMax() {
thrown.expectMessage( "Bearing 360.000000000001 is not in range [0, 360]" );
CompassDirection16.getByBearing( new BigDecimal("360.000000000001") );
}

@Test
public void getPrintName() {
assertEquals( "east", CompassDirection16.EAST.getPrintName() );
assertEquals( "east northeast", CompassDirection16.EAST_NORTHEAST.getPrintName() );
assertEquals( "east southeast", CompassDirection16.EAST_SOUTHEAST.getPrintName() );
assertEquals( "north", CompassDirection16.NORTH.getPrintName() );
assertEquals( "north northeast", CompassDirection16.NORTH_NORTHEAST.getPrintName() );
assertEquals( "north northwest", CompassDirection16.NORTH_NORTHWEST.getPrintName() );
assertEquals( "northeast", CompassDirection16.NORTHEAST.getPrintName() );
assertEquals( "northwest", CompassDirection16.NORTHWEST.getPrintName() );
assertEquals( "south", CompassDirection16.SOUTH.getPrintName() );
assertEquals( "south southeast", CompassDirection16.SOUTH_SOUTHEAST.getPrintName() );
assertEquals( "south southwest", CompassDirection16.SOUTH_SOUTHWEST.getPrintName() );
assertEquals( "southeast", CompassDirection16.SOUTHEAST.getPrintName() );
assertEquals( "southwest", CompassDirection16.SOUTHWEST.getPrintName() );
assertEquals( "west", CompassDirection16.WEST.getPrintName() );
assertEquals( "west northwest", CompassDirection16.WEST_NORTHWEST.getPrintName() );
assertEquals( "west southwest", CompassDirection16.WEST_SOUTHWEST.getPrintName() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,40 @@ public void getByBearing_invalidMax() {
thrown.expectMessage( "Bearing 360.000000000001 is not in range [0, 360]" );
CompassDirection32.getByBearing( new BigDecimal("360.000000000001") );
}

@Test
public void getPrintName() {
assertEquals( "north", CompassDirection32.NORTH.getPrintName() );
assertEquals( "north by east", CompassDirection32.NORTH_BY_EAST.getPrintName() );
assertEquals( "north northeast", CompassDirection32.NORTH_NORTHEAST.getPrintName() );
assertEquals( "northeast by north", CompassDirection32.NORTHEAST_BY_NORTH.getPrintName() );
assertEquals( "northeast", CompassDirection32.NORTHEAST.getPrintName() );
assertEquals( "northeast by east", CompassDirection32.NORTHEAST_BY_EAST.getPrintName() );
assertEquals( "east northeast", CompassDirection32.EAST_NORTHEAST.getPrintName() );
assertEquals( "east by north", CompassDirection32.EAST_BY_NORTH.getPrintName() );
assertEquals( "east", CompassDirection32.EAST.getPrintName() );
assertEquals( "east by south", CompassDirection32.EAST_BY_SOUTH.getPrintName() );
assertEquals( "east southeast", CompassDirection32.EAST_SOUTHEAST.getPrintName() );
assertEquals( "southeast by east", CompassDirection32.SOUTHEAST_BY_EAST.getPrintName() );
assertEquals( "southeast", CompassDirection32.SOUTHEAST.getPrintName() );
assertEquals( "southeast by south", CompassDirection32.SOUTHEAST_BY_SOUTH.getPrintName() );
assertEquals( "south southeast", CompassDirection32.SOUTH_SOUTHEAST.getPrintName() );
assertEquals( "south by east", CompassDirection32.SOUTH_BY_EAST.getPrintName() );
assertEquals( "south", CompassDirection32.SOUTH.getPrintName() );
assertEquals( "south by west", CompassDirection32.SOUTH_BY_WEST.getPrintName() );
assertEquals( "south southwest", CompassDirection32.SOUTH_SOUTHWEST.getPrintName() );
assertEquals( "southwest by south", CompassDirection32.SOUTHWEST_BY_SOUTH.getPrintName() );
assertEquals( "southwest", CompassDirection32.SOUTHWEST.getPrintName() );
assertEquals( "southwest by west", CompassDirection32.SOUTHWEST_BY_WEST.getPrintName() );
assertEquals( "west southwest", CompassDirection32.WEST_SOUTHWEST.getPrintName() );
assertEquals( "west by south", CompassDirection32.WEST_BY_SOUTH.getPrintName() );
assertEquals( "west", CompassDirection32.WEST.getPrintName() );
assertEquals( "west by north", CompassDirection32.WEST_BY_NORTH.getPrintName() );
assertEquals( "west northwest", CompassDirection32.WEST_NORTHWEST.getPrintName() );
assertEquals( "northwest by west", CompassDirection32.NORTHWEST_BY_WEST.getPrintName() );
assertEquals( "northwest", CompassDirection32.NORTHWEST.getPrintName() );
assertEquals( "northwest by north", CompassDirection32.NORTHWEST_BY_NORTH.getPrintName() );
assertEquals( "north northwest", CompassDirection32.NORTH_NORTHWEST.getPrintName() );
assertEquals( "north by west", CompassDirection32.NORTH_BY_WEST.getPrintName() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,16 @@ public void getByBearing_invalidMax() {
thrown.expectMessage( "Bearing 360.000000000001 is not in range [0, 360]" );
CompassDirection8.getByBearing( new BigDecimal("360.000000000001") );
}

@Test
public void getPrintName() {
assertEquals( "east", CompassDirection8.EAST.getPrintName() );
assertEquals( "north", CompassDirection8.NORTH.getPrintName() );
assertEquals( "northeast", CompassDirection8.NORTHEAST.getPrintName() );
assertEquals( "northwest", CompassDirection8.NORTHWEST.getPrintName() );
assertEquals( "south", CompassDirection8.SOUTH.getPrintName() );
assertEquals( "southeast", CompassDirection8.SOUTHEAST.getPrintName() );
assertEquals( "southwest", CompassDirection8.SOUTHWEST.getPrintName() );
assertEquals( "west", CompassDirection8.WEST.getPrintName() );
}
}

0 comments on commit 6a9458c

Please sign in to comment.