forked from vijayontheweb/Concurrency
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberRange.java
More file actions
37 lines (32 loc) · 883 Bytes
/
Copy pathNumberRange.java
File metadata and controls
37 lines (32 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package concurrency.composingobjects;
import java.util.concurrent.atomic.AtomicInteger;
/**
*Number Range class that doesn't sufficiently protect its invariants
*
* @author vijay
*/
public class NumberRange {
private final AtomicInteger lower = new AtomicInteger();
private final AtomicInteger upper = new AtomicInteger();
public void setLower(int i){
if(i<upper.get()){
lower.set(i);
}else{
throw new IllegalArgumentException();
}
}
public void setUpper(int i){
if(i>lower.get()){
upper.set(i);
}else{
throw new IllegalArgumentException();
}
}
public boolean isInRange(int i){
return (i>=lower.get() && i<=upper.get());
}
}