mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add copyOf and copyConstructor to Capacity
This commit is contained in:
parent
c2377252ea
commit
b0e2637bea
2 changed files with 47 additions and 3 deletions
|
|
@ -3,6 +3,11 @@ package jsprit.core.problem;
|
||||||
|
|
||||||
public class Capacity {
|
public class Capacity {
|
||||||
|
|
||||||
|
public static Capacity copyOf(Capacity capacity){
|
||||||
|
if(capacity == null) return null;
|
||||||
|
return new Capacity(capacity);
|
||||||
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -56,6 +61,18 @@ public class Capacity {
|
||||||
|
|
||||||
private int[] dimensions;
|
private int[] dimensions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* copy constructor
|
||||||
|
*
|
||||||
|
* @param capacity
|
||||||
|
*/
|
||||||
|
Capacity(Capacity capacity){
|
||||||
|
this.dimensions = new int[capacity.getNuOfDimensions()];
|
||||||
|
for(int i=0;i<capacity.getNuOfDimensions();i++){
|
||||||
|
this.dimensions[i]=capacity.get(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Capacity(Builder builder) {
|
Capacity(Builder builder) {
|
||||||
dimensions = builder.dimensions;
|
dimensions = builder.dimensions;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
|
|
||||||
package jsprit.core.problem.job;
|
package jsprit.core.problem;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import jsprit.core.problem.Capacity;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class CapacityTest {
|
public class CapacityTest {
|
||||||
|
|
@ -62,5 +61,33 @@ public class CapacityTest {
|
||||||
assertEquals(0, cap.get(0));
|
assertEquals(0, cap.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCopyingCapacityWithTwoCapDim_copiedObjShouldHvSameNuOfDims(){
|
||||||
|
Capacity.Builder capBuilder = Capacity.Builder.newInstance();
|
||||||
|
capBuilder.addDimension(0, 4);
|
||||||
|
capBuilder.addDimension(1,10);
|
||||||
|
Capacity cap = capBuilder.build();
|
||||||
|
|
||||||
|
Capacity copiedCapacity = Capacity.copyOf(cap);
|
||||||
|
assertEquals(2,copiedCapacity.getNuOfDimensions());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCopyingCapacityWithTwoCapDim_copiedObjShouldHvSameValues(){
|
||||||
|
Capacity.Builder capBuilder = Capacity.Builder.newInstance();
|
||||||
|
capBuilder.addDimension(0, 4);
|
||||||
|
capBuilder.addDimension(1,10);
|
||||||
|
Capacity cap = capBuilder.build();
|
||||||
|
|
||||||
|
Capacity copiedCapacity = Capacity.copyOf(cap);
|
||||||
|
assertEquals(4,copiedCapacity.get(0));
|
||||||
|
assertEquals(10,copiedCapacity.get(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCopyingNull_itShouldReturnNull(){
|
||||||
|
Capacity nullCap = Capacity.copyOf(null);
|
||||||
|
assertTrue(nullCap==null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue