1 13 package com.tonbeller.jpivot.olap.model.impl; 14 15 import java.util.List ; 16 import java.util.ListIterator ; 17 18 import com.tonbeller.jpivot.olap.model.Axis; 19 import com.tonbeller.jpivot.olap.model.Member; 20 import com.tonbeller.jpivot.olap.model.Position; 21 22 43 44 public class PositionSpan { 45 Axis axis; 46 Position position; 47 Member member; 48 49 int memberIndex; int startIndex; int endIndex; 53 56 public PositionSpan(Axis axis, Position position, Member member) { 57 this.axis = axis; 58 this.position = position; 59 this.member = member; 60 61 memberIndex = indexOf(position.getMembers(), member); 62 initStartIndex(); 63 initEndIndex(); 64 } 65 66 void initStartIndex() { 67 List list = axis.getPositions(); 68 int index = list.indexOf(position); 69 ListIterator li = list.listIterator(index); 70 loop: while (li.hasPrevious()) { 71 Position p = (Position)li.previous(); 72 if (!match(p)) 73 break loop; 74 index -= 1; 75 } 76 startIndex = index; 77 } 78 79 void initEndIndex() { 80 List list = axis.getPositions(); 81 int index = list.indexOf(position); 82 ListIterator li = list.listIterator(index); 83 loop: while (li.hasNext()) { 84 Position p = (Position)li.next(); 85 if (!match(p)) 86 break loop; 87 index += 1; 88 } 89 endIndex = index; 90 } 91 92 boolean match(Position p) { 93 Member[] m1 = p.getMembers(); 94 Member[] m2 = position.getMembers(); 95 for (int i = 0; i <= memberIndex; i++) 96 if (!m1[i].equals(m2[i])) 97 return false; 98 return true; 99 } 100 101 102 int indexOf(Object [] array, Object obj) { 103 for (int i = 0; i < array.length; i++) 104 if (array[i] == obj) 105 return i; 106 return -1; 107 } 108 109 113 public Axis getAxis() { 114 return axis; 115 } 116 117 121 public int getEndIndex() { 122 return endIndex; 123 } 124 125 129 public Member getMember() { 130 return member; 131 } 132 133 137 public Position getPosition() { 138 return position; 139 } 140 141 145 public int getStartIndex() { 146 return startIndex; 147 } 148 149 153 public int getMemberIndex() { 154 return memberIndex; 155 } 156 157 } 158 | Popular Tags |