1 21 package com.db4o.inside.btree; 22 23 import com.db4o.foundation.*; 24 import com.db4o.inside.btree.algebra.*; 25 26 public class BTreeRangeUnion implements BTreeRange { 27 28 private final BTreeRangeSingle[] _ranges; 29 30 public BTreeRangeUnion(BTreeRangeSingle[] ranges) { 31 this(toSortedCollection(ranges)); 32 } 33 34 public BTreeRangeUnion(SortedCollection4 sorted) { 35 if (null == sorted) { 36 throw new ArgumentNullException(); 37 } 38 _ranges = toArray(sorted); 39 } 40 41 public void accept(BTreeRangeVisitor visitor) { 42 visitor.visit(this); 43 } 44 45 public boolean isEmpty() { 46 for (int i = 0; i < _ranges.length; i++) { 47 if (!_ranges[i].isEmpty()) { 48 return false; 49 } 50 } 51 return true; 52 } 53 54 private static SortedCollection4 toSortedCollection(BTreeRangeSingle[] ranges) { 55 if (null == ranges) { 56 throw new ArgumentNullException(); 57 } 58 SortedCollection4 collection = new SortedCollection4(BTreeRangeSingle.COMPARISON); 59 for (int i = 0; i < ranges.length; i++) { 60 BTreeRangeSingle range = ranges[i]; 61 if (!range.isEmpty()) { 62 collection.add(range); 63 } 64 } 65 return collection; 66 } 67 68 private static BTreeRangeSingle[] toArray(SortedCollection4 collection) { 69 return (BTreeRangeSingle[]) collection.toArray(new BTreeRangeSingle[collection.size()]); 70 } 71 72 public BTreeRange extendToFirst() { 73 throw new NotImplementedException(); 74 } 75 76 public BTreeRange extendToLast() { 77 throw new NotImplementedException(); 78 } 79 80 public BTreeRange extendToLastOf(BTreeRange upperRange) { 81 throw new NotImplementedException(); 82 } 83 84 public BTreeRange greater() { 85 throw new NotImplementedException(); 86 } 87 88 public BTreeRange intersect(BTreeRange range) { 89 if (null == range) { 90 throw new ArgumentNullException(); 91 } 92 return new BTreeRangeUnionIntersect(this).dispatch(range); 93 } 94 95 public Iterator4 pointers() { 96 return Iterators.concat(Iterators.map(_ranges, new Function4() { 97 public Object apply(Object range) { 98 return ((BTreeRange)range).pointers(); 99 } 100 })); 101 } 102 103 public Iterator4 keys() { 104 return Iterators.concat(Iterators.map(_ranges, new Function4() { 105 public Object apply(Object range) { 106 return ((BTreeRange)range).keys(); 107 } 108 })); 109 } 110 111 public int size() { 112 int size = 0; 113 for (int i = 0; i < _ranges.length; i++) { 114 size += _ranges[i].size(); 115 } 116 return size; 117 } 118 119 public BTreeRange smaller() { 120 throw new NotImplementedException(); 121 } 122 123 public BTreeRange union(BTreeRange other) { 124 if (null == other) { 125 throw new ArgumentNullException(); 126 } 127 return new BTreeRangeUnionUnion(this).dispatch(other); 128 } 129 130 public Iterator4 ranges() { 131 return new ArrayIterator4(_ranges); 132 } 133 134 public BTreePointer lastPointer() { 135 throw new NotImplementedException(); 136 } 137 } 138 | Popular Tags |