mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add name to location
This commit is contained in:
parent
76fe48a798
commit
e7d1019b8f
2 changed files with 20 additions and 1 deletions
|
|
@ -64,6 +64,8 @@ public final class Location implements HasIndex, HasId {
|
|||
|
||||
private Coordinate coordinate;
|
||||
|
||||
private String name = "";
|
||||
|
||||
public static Builder newInstance() {
|
||||
return new Builder();
|
||||
}
|
||||
|
|
@ -84,6 +86,11 @@ public final class Location implements HasIndex, HasId {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder setName(String name){
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Location build() {
|
||||
if (id == null && coordinate == null) {
|
||||
if (index == -1) throw new IllegalArgumentException("either id or coordinate or index must be set");
|
||||
|
|
@ -107,10 +114,13 @@ public final class Location implements HasIndex, HasId {
|
|||
|
||||
private final String id;
|
||||
|
||||
private final String name;
|
||||
|
||||
private Location(Builder builder) {
|
||||
this.index = builder.index;
|
||||
this.coordinate = builder.coordinate;
|
||||
this.id = builder.id;
|
||||
this.name = builder.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -127,6 +137,8 @@ public final class Location implements HasIndex, HasId {
|
|||
return coordinate;
|
||||
}
|
||||
|
||||
public String getName() { return name; }
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@
|
|||
package com.graphhopper.jsprit.core.problem;
|
||||
|
||||
import com.graphhopper.jsprit.core.util.Coordinate;
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
|
@ -34,6 +35,12 @@ public class LocationTest {
|
|||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNameSet_buildLocation() {
|
||||
Location l = Location.Builder.newInstance().setName("mystreet 6a").setIndex(1).build();
|
||||
Assert.assertEquals("mystreet 6a",l.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIndexSetWitFactory_returnCorrectLocation() {
|
||||
Location l = Location.newInstance(1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue