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:
parent
4c49dfb589
commit
fda4500302
7 changed files with 29 additions and 54 deletions
|
|
@ -171,9 +171,7 @@ public class Capacity {
|
|||
}
|
||||
|
||||
private void copy(int[] from, int[] to) {
|
||||
for (int i = 0; i < dimensions.length; i++) {
|
||||
to[i] = from[i];
|
||||
}
|
||||
System.arraycopy(from, 0, to, 0, dimensions.length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -195,7 +193,7 @@ public class Capacity {
|
|||
*
|
||||
* @param capacity capacity to be copied
|
||||
*/
|
||||
Capacity(Capacity capacity) {
|
||||
private Capacity(Capacity capacity) {
|
||||
this.dimensions = new int[capacity.getNuOfDimensions()];
|
||||
for (int i = 0; i < capacity.getNuOfDimensions(); i++) {
|
||||
this.dimensions[i] = capacity.get(i);
|
||||
|
|
@ -261,11 +259,11 @@ public class Capacity {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
String string = "[noDimensions=" + getNuOfDimensions() + "]";
|
||||
StringBuilder string = new StringBuilder("[noDimensions=" + getNuOfDimensions() + "]");
|
||||
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;
|
||||
|
||||
if (!Arrays.equals(dimensions, capacity.dimensions)) return false;
|
||||
|
||||
return true;
|
||||
return Arrays.equals(dimensions, capacity.dimensions);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -23,6 +23,6 @@ package com.graphhopper.jsprit.core.problem;
|
|||
*/
|
||||
public interface HasId {
|
||||
|
||||
public String getId();
|
||||
String getId();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,6 @@ package com.graphhopper.jsprit.core.problem;
|
|||
*/
|
||||
public interface HasIndex {
|
||||
|
||||
public int getIndex();
|
||||
int getIndex();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,6 @@ import java.util.List;
|
|||
*/
|
||||
public interface JobActivityFactory {
|
||||
|
||||
public List<AbstractActivity> createActivities(Job job);
|
||||
List<AbstractActivity> createActivities(Job job);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,8 +49,8 @@ public final class Location implements HasIndex, HasId {
|
|||
/**
|
||||
* Factory method (and shortcut) for creating location object just with location index
|
||||
*
|
||||
* @param index
|
||||
* @return
|
||||
* @param index of location
|
||||
* @return this builder
|
||||
*/
|
||||
public static Location newInstance(int index) {
|
||||
return Location.Builder.newInstance().setIndex(index).build();
|
||||
|
|
@ -92,7 +92,7 @@ public final class Location implements HasIndex, HasId {
|
|||
/**
|
||||
* Sets location index
|
||||
*
|
||||
* @param index
|
||||
* @param index location index
|
||||
* @return the builder
|
||||
*/
|
||||
public Builder setIndex(int index) {
|
||||
|
|
@ -104,8 +104,8 @@ public final class Location implements HasIndex, HasId {
|
|||
/**
|
||||
* Sets coordinate of location
|
||||
*
|
||||
* @param coordinate
|
||||
* @return
|
||||
* @param coordinate of location
|
||||
* @return this Builder
|
||||
*/
|
||||
public Builder setCoordinate(Coordinate coordinate) {
|
||||
this.coordinate = coordinate;
|
||||
|
|
@ -115,8 +115,8 @@ public final class Location implements HasIndex, HasId {
|
|||
/**
|
||||
* Sets location id
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
* @param id id of location
|
||||
* @return this Builder
|
||||
*/
|
||||
public Builder setId(String id) {
|
||||
this.id = id;
|
||||
|
|
@ -126,8 +126,8 @@ public final class Location implements HasIndex, HasId {
|
|||
/**
|
||||
* Adds name, e.g. street name, to location
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
* @param name name of location
|
||||
* @return this Builder
|
||||
*/
|
||||
public Builder setName(String name) {
|
||||
this.name = name;
|
||||
|
|
@ -198,14 +198,10 @@ public final class Location implements HasIndex, HasId {
|
|||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Location)) return false;
|
||||
|
||||
Location location = (Location) o;
|
||||
|
||||
if (index != location.index) 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 true;
|
||||
return id != null ? id.equals(location.id) : location.id == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class Skills {
|
|||
return new Builder();
|
||||
}
|
||||
|
||||
private Set<String> skills = new HashSet<String>();
|
||||
private Set<String> skills = new HashSet<>();
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
skills.addAll(builder.skills);
|
||||
|
|
@ -90,16 +90,16 @@ public class Skills {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
String s = "[";
|
||||
StringBuilder s = new StringBuilder("[");
|
||||
boolean first = true;
|
||||
for (String skill : values()) {
|
||||
if (first) {
|
||||
s += skill;
|
||||
s.append(skill);
|
||||
first = false;
|
||||
} else s += ", " + skill;
|
||||
} else s.append(", ").append(skill);
|
||||
}
|
||||
s += "]";
|
||||
return s;
|
||||
s.append("]");
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -119,9 +119,7 @@ public class Skills {
|
|||
|
||||
Skills skills1 = (Skills) o;
|
||||
|
||||
if (skills != null ? !skills.equals(skills1.skills) : skills1.skills != null) return false;
|
||||
|
||||
return true;
|
||||
return skills != null ? skills.equals(skills1.skills) : skills1.skills == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -157,14 +157,7 @@ public class VehicleRoutingProblem {
|
|||
* @return locations
|
||||
*/
|
||||
public Locations getLocations() {
|
||||
return new Locations() {
|
||||
|
||||
@Override
|
||||
public Coordinate getCoord(String id) {
|
||||
return tentative_coordinates.get(id);
|
||||
}
|
||||
|
||||
};
|
||||
return id -> tentative_coordinates.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -513,7 +506,6 @@ public class VehicleRoutingProblem {
|
|||
}
|
||||
|
||||
private Builder addService(Service service) {
|
||||
// tentative_coordinates.put(service.getLocation().getId(), service.getLocation().getCoordinate());
|
||||
addLocationToTentativeLocations(service);
|
||||
if (jobs.containsKey(service.getId())) {
|
||||
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 final JobActivityFactory jobActivityFactory = new JobActivityFactory() {
|
||||
|
||||
@Override
|
||||
public List<AbstractActivity> createActivities(Job job) {
|
||||
return copyAndGetActivities(job);
|
||||
}
|
||||
|
||||
};
|
||||
private final JobActivityFactory jobActivityFactory = job -> copyAndGetActivities(job);
|
||||
|
||||
private VehicleRoutingProblem(Builder builder) {
|
||||
this.jobs = builder.jobs;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue