2 changed files with 45 additions and 0 deletions
@ -0,0 +1,25 @@ |
|||||||
|
package org.leolo.nrdatad.util; |
||||||
|
|
||||||
|
public class Range<E extends Comparable> { |
||||||
|
|
||||||
|
private E lowerBound; |
||||||
|
private E upperBound; |
||||||
|
|
||||||
|
public Range(E bound1, E bound2){ |
||||||
|
if(bound1.compareTo(bound2)==-1){ |
||||||
|
lowerBound = bound1; |
||||||
|
upperBound = bound2; |
||||||
|
}else{ |
||||||
|
lowerBound = bound2; |
||||||
|
upperBound = bound1; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public E getLowerBound() { |
||||||
|
return lowerBound; |
||||||
|
} |
||||||
|
|
||||||
|
public E getUpperBound() { |
||||||
|
return upperBound; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
package org.leolo.nrdatad.util; |
||||||
|
|
||||||
|
import org.junit.Test; |
||||||
|
|
||||||
|
import static org.junit.Assert.*; |
||||||
|
public class RangeTest { |
||||||
|
|
||||||
|
@Test |
||||||
|
public void basicInteger1(){ |
||||||
|
Range<Integer> range = new Range<>(1,2); |
||||||
|
assertEquals(1, range.getLowerBound().intValue()); |
||||||
|
assertEquals(2, range.getUpperBound().intValue()); |
||||||
|
range = new Range<>(2,1); |
||||||
|
assertEquals(1, range.getLowerBound().intValue()); |
||||||
|
assertEquals(2, range.getUpperBound().intValue()); |
||||||
|
range = new Range<>(2,2); |
||||||
|
assertEquals(2, range.getLowerBound().intValue()); |
||||||
|
assertEquals(2, range.getUpperBound().intValue()); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue