diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/Location.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/Location.java index 00f10bf1..4d1dbb64 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/Location.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/Location.java @@ -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; diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/LocationTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/LocationTest.java index 8119b59e..f237eadb 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/LocationTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/LocationTest.java @@ -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);