1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

simplify and remove redundant stuff

This commit is contained in:
oblonski 2019-04-10 21:55:50 +02:00
parent 4c49dfb589
commit fda4500302
No known key found for this signature in database
GPG key ID: 179DE487285680D1
7 changed files with 29 additions and 54 deletions

View file

@ -171,9 +171,7 @@ public class Capacity {
} }
private void copy(int[] from, int[] to) { private void copy(int[] from, int[] to) {
for (int i = 0; i < dimensions.length; i++) { System.arraycopy(from, 0, to, 0, dimensions.length);
to[i] = from[i];
}
} }
/** /**
@ -195,7 +193,7 @@ public class Capacity {
* *
* @param capacity capacity to be copied * @param capacity capacity to be copied
*/ */
Capacity(Capacity capacity) { private Capacity(Capacity capacity) {
this.dimensions = new int[capacity.getNuOfDimensions()]; this.dimensions = new int[capacity.getNuOfDimensions()];
for (int i = 0; i < capacity.getNuOfDimensions(); i++) { for (int i = 0; i < capacity.getNuOfDimensions(); i++) {
this.dimensions[i] = capacity.get(i); this.dimensions[i] = capacity.get(i);
@ -261,11 +259,11 @@ public class Capacity {
@Override @Override
public String toString() { public String toString() {
String string = "[noDimensions=" + getNuOfDimensions() + "]"; StringBuilder string = new StringBuilder("[noDimensions=" + getNuOfDimensions() + "]");
for (int i = 0; i < getNuOfDimensions(); i++) { for (int i = 0; i < getNuOfDimensions(); i++) {
string += "[[dimIndex=" + i + "][dimValue=" + dimensions[i] + "]]"; string.append("[[dimIndex=").append(i).append("][dimValue=").append(dimensions[i]).append("]]");
} }
return string; return string.toString();
} }
/** /**
@ -300,9 +298,7 @@ public class Capacity {
Capacity capacity = (Capacity) o; Capacity capacity = (Capacity) o;
if (!Arrays.equals(dimensions, capacity.dimensions)) return false; return Arrays.equals(dimensions, capacity.dimensions);
return true;
} }
@Override @Override

View file

@ -23,6 +23,6 @@ package com.graphhopper.jsprit.core.problem;
*/ */
public interface HasId { public interface HasId {
public String getId(); String getId();
} }

View file

@ -23,6 +23,6 @@ package com.graphhopper.jsprit.core.problem;
*/ */
public interface HasIndex { public interface HasIndex {
public int getIndex(); int getIndex();
} }

View file

@ -27,6 +27,6 @@ import java.util.List;
*/ */
public interface JobActivityFactory { public interface JobActivityFactory {
public List<AbstractActivity> createActivities(Job job); List<AbstractActivity> createActivities(Job job);
} }

View file

@ -49,8 +49,8 @@ public final class Location implements HasIndex, HasId {
/** /**
* Factory method (and shortcut) for creating location object just with location index * Factory method (and shortcut) for creating location object just with location index
* *
* @param index * @param index of location
* @return * @return this builder
*/ */
public static Location newInstance(int index) { public static Location newInstance(int index) {
return Location.Builder.newInstance().setIndex(index).build(); return Location.Builder.newInstance().setIndex(index).build();
@ -92,7 +92,7 @@ public final class Location implements HasIndex, HasId {
/** /**
* Sets location index * Sets location index
* *
* @param index * @param index location index
* @return the builder * @return the builder
*/ */
public Builder setIndex(int index) { public Builder setIndex(int index) {
@ -104,8 +104,8 @@ public final class Location implements HasIndex, HasId {
/** /**
* Sets coordinate of location * Sets coordinate of location
* *
* @param coordinate * @param coordinate of location
* @return * @return this Builder
*/ */
public Builder setCoordinate(Coordinate coordinate) { public Builder setCoordinate(Coordinate coordinate) {
this.coordinate = coordinate; this.coordinate = coordinate;
@ -115,8 +115,8 @@ public final class Location implements HasIndex, HasId {
/** /**
* Sets location id * Sets location id
* *
* @param id * @param id id of location
* @return * @return this Builder
*/ */
public Builder setId(String id) { public Builder setId(String id) {
this.id = id; this.id = id;
@ -126,8 +126,8 @@ public final class Location implements HasIndex, HasId {
/** /**
* Adds name, e.g. street name, to location * Adds name, e.g. street name, to location
* *
* @param name * @param name name of location
* @return * @return this Builder
*/ */
public Builder setName(String name) { public Builder setName(String name) {
this.name = name; this.name = name;
@ -198,14 +198,10 @@ public final class Location implements HasIndex, HasId {
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (!(o instanceof Location)) return false; if (!(o instanceof Location)) return false;
Location location = (Location) o; Location location = (Location) o;
if (index != location.index) return false; if (index != location.index) return false;
if (coordinate != null ? !coordinate.equals(location.coordinate) : location.coordinate != null) return false; if (coordinate != null ? !coordinate.equals(location.coordinate) : location.coordinate != null) return false;
if (id != null ? !id.equals(location.id) : location.id != null) return false; return id != null ? id.equals(location.id) : location.id == null;
return true;
} }
@Override @Override

View file

@ -39,7 +39,7 @@ public class Skills {
return new Builder(); return new Builder();
} }
private Set<String> skills = new HashSet<String>(); private Set<String> skills = new HashSet<>();
/** /**
* Adds skill. Skill is transformed into lowerCase. * Adds skill. Skill is transformed into lowerCase.
@ -74,7 +74,7 @@ public class Skills {
} }
private Set<String> skills = new HashSet<String>(); private Set<String> skills = new HashSet<>();
private Skills(Builder builder) { private Skills(Builder builder) {
skills.addAll(builder.skills); skills.addAll(builder.skills);
@ -90,16 +90,16 @@ public class Skills {
} }
public String toString() { public String toString() {
String s = "["; StringBuilder s = new StringBuilder("[");
boolean first = true; boolean first = true;
for (String skill : values()) { for (String skill : values()) {
if (first) { if (first) {
s += skill; s.append(skill);
first = false; first = false;
} else s += ", " + skill; } else s.append(", ").append(skill);
} }
s += "]"; s.append("]");
return s; return s.toString();
} }
/** /**
@ -119,9 +119,7 @@ public class Skills {
Skills skills1 = (Skills) o; Skills skills1 = (Skills) o;
if (skills != null ? !skills.equals(skills1.skills) : skills1.skills != null) return false; return skills != null ? skills.equals(skills1.skills) : skills1.skills == null;
return true;
} }
@Override @Override

View file

@ -157,14 +157,7 @@ public class VehicleRoutingProblem {
* @return locations * @return locations
*/ */
public Locations getLocations() { public Locations getLocations() {
return new Locations() { return id -> tentative_coordinates.get(id);
@Override
public Coordinate getCoord(String id) {
return tentative_coordinates.get(id);
}
};
} }
/** /**
@ -513,7 +506,6 @@ public class VehicleRoutingProblem {
} }
private Builder addService(Service service) { private Builder addService(Service service) {
// tentative_coordinates.put(service.getLocation().getId(), service.getLocation().getCoordinate());
addLocationToTentativeLocations(service); addLocationToTentativeLocations(service);
if (jobs.containsKey(service.getId())) { if (jobs.containsKey(service.getId())) {
logger.warn("The service " + service + " has already been added to job list. This overrides existing job."); logger.warn("The service " + service + " has already been added to job list. This overrides existing job.");
@ -579,14 +571,7 @@ public class VehicleRoutingProblem {
private int nuActivities; private int nuActivities;
private final JobActivityFactory jobActivityFactory = new JobActivityFactory() { private final JobActivityFactory jobActivityFactory = job -> copyAndGetActivities(job);
@Override
public List<AbstractActivity> createActivities(Job job) {
return copyAndGetActivities(job);
}
};
private VehicleRoutingProblem(Builder builder) { private VehicleRoutingProblem(Builder builder) {
this.jobs = builder.jobs; this.jobs = builder.jobs;