001    package ps6.tigerdb;
002    
003    public class DirectedStreetNumberRange {
004        private final IntSet s;
005    
006        private final int isLowToHigh; // 0 means false, 1 means true, -1 means don't know
007    
008        public DirectedStreetNumberRange(IntSet s,
009                                         boolean isLowToHigh) {
010            this.s = s;
011            if (isLowToHigh) {
012                this.isLowToHigh = 1;
013            } else {
014                this.isLowToHigh = 0;
015            }
016        }
017    
018        public DirectedStreetNumberRange() {
019            this.s = new IntSet();
020            this.isLowToHigh = -1; // don't-know value
021        }
022    
023        public boolean contains(int i) { return s.contains(i); }
024    
025        public String toString() { return "set:"+s+" low2high:"+unparse(isLowToHigh); }
026    
027        public int size() { return s.size(); }
028    
029        private String unparse(int l2h) {
030            switch(l2h) {
031            case 0: return "false";
032            case 1: return "true";
033            default: return "don't-know";
034            }
035        }
036    
037        public boolean sameDir(DirectedStreetNumberRange d) {
038            return d.isLowToHigh == -1 || this.isLowToHigh == -1 ||
039                this.isLowToHigh == d.isLowToHigh;
040        }
041    
042        public boolean couldBeLowToHigh() {
043            return (isLowToHigh == 1 || isLowToHigh == -1) ;
044        }
045    
046        public String rangeAsString() {
047            return s.unparse();
048        }
049    
050        protected IntSet getSet() {
051            return s;
052        }
053    }