mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add factory methods to Location to simplify location building
This commit is contained in:
parent
657f85e896
commit
f8f063773a
3 changed files with 101 additions and 13 deletions
|
|
@ -24,6 +24,37 @@ import jsprit.core.util.Coordinate;
|
|||
*/
|
||||
public final class Location implements HasIndex, HasId{
|
||||
|
||||
/**
|
||||
* Factory method (and shortcut) for creating a location object just with x and y coordinates.
|
||||
*
|
||||
* @param x coordinate
|
||||
* @param y coordinate
|
||||
* @return location
|
||||
*/
|
||||
public static Location newInstance(double x, double y){
|
||||
return Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(x,y)).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method (and shortcut) for creating location object just with id
|
||||
*
|
||||
* @param id location id
|
||||
* @return location
|
||||
*/
|
||||
public static Location newInstance(String id){
|
||||
return Location.Builder.newInstance().setId(id).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method (and shortcut) for creating location object just with location index
|
||||
*
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public static Location newInstance(int index){
|
||||
return Location.Builder.newInstance().setIndex(index).build();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private String id;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,13 @@ public class LocationTest {
|
|||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIndexSetWitFactory_returnCorrectLocation(){
|
||||
Location l = Location.newInstance(1);
|
||||
Assert.assertEquals(1,l.getIndex());
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenIndexSmallerZero_throwException(){
|
||||
Location l = Location.Builder.newInstance().setIndex(-1).build();
|
||||
|
|
@ -50,6 +57,13 @@ public class LocationTest {
|
|||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIdSetWithFactory_returnCorrectLocation(){
|
||||
Location l = Location.newInstance("id");
|
||||
Assert.assertEquals("id",l.getId());
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCoordinateSet_build(){
|
||||
Location l = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10,20)).build();
|
||||
|
|
@ -58,5 +72,14 @@ public class LocationTest {
|
|||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCoordinateSetWithFactory_returnCorrectLocation(){
|
||||
// Location l = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10,20)).build();
|
||||
Location l = Location.newInstance(10,20);
|
||||
Assert.assertEquals(10.,l.getCoordinate().getX());
|
||||
Assert.assertEquals(20.,l.getCoordinate().getY());
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue