repositories
/
Persons_Comparator.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Implement some compareTo() methods.
[Persons_Comparator.git]
/
src
/
Size.java
diff --git
a/src/Size.java
b/src/Size.java
index 0cecada6c98192f7cfa94f874f937e1fe9831276..20e96f6b47f04c7c9e330aec7a271e4b54aad289 100644
(file)
--- a/
src/Size.java
+++ b/
src/Size.java
@@
-1,5
+1,6
@@
+import java.util.Comparator;
-public class Size {
+public class Size
implements Comparable<Size>
{
private int max = 240;
private int min = 20;
private int size;
private int max = 240;
private int min = 20;
private int size;
@@
-15,10
+16,22
@@
public class Size {
public void setSize(int size) {
if (validateSize(size)) {
this.size = size;
public void setSize(int size) {
if (validateSize(size)) {
this.size = size;
- } /* FIXME: raise an error */
+ } else {
+ throw new IllegalArgumentException("Size must be between" + this.min + " and " + this.max);
+ }
}
private boolean validateSize(int size) {
return (size > max || size < min);
}
}
private boolean validateSize(int size) {
return (size > max || size < min);
}
+
+ @Override
+ public int compareTo(Size size) {
+ int distance = size.size - this.getSize();
+ if (distance >= 0)
+ return distance;
+ else
+ return -distance;
+
+ }
}
}