Skip to content

Commit

Permalink
MONDRIAN
Browse files Browse the repository at this point in the history
   Michael pointed out that I had the semantics incorrect
   for some of the Iterators I'd checked in. Now one can
   call the 'hasNext' method multiple times without changing
   the 'next' value.

[git-p4: depot-paths = "//open/mondrian/": change = 8538]
  • Loading branch information
Richard Emberson committed Jan 18, 2007
1 parent 65b94c2 commit eada284
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/main/mondrian/olap/ResultStyleException.java
Expand Up @@ -61,4 +61,4 @@ public ResultStyleException(String message) {
}
}

// End ResourceLimitExceeded.java
// End ResultStyleException.java
36 changes: 32 additions & 4 deletions src/main/mondrian/olap/fun/CrossJoinFunDef.java
Expand Up @@ -356,6 +356,9 @@ public Iterator<Member[]> iterator() {
Iterator i2 = it2.iterator();
Object o2 = null;
public boolean hasNext() {
if (o2 != null) {
return true;
}
if (! hasNextO1()) {
return false;
}
Expand All @@ -374,7 +377,11 @@ public boolean hasNext() {
return true;
}
public Member[] next() {
return makeNext(o1, o2);
try {
return makeNext(o1, o2);
} finally {
o2 = null;
}
}
public void remove() {
throw new UnsupportedOperationException("remove");
Expand Down Expand Up @@ -416,6 +423,9 @@ public Iterator<Member[]> iterator() {
int index2 = 0;
Object o2 = null;
public boolean hasNext() {
if (o2 != null) {
return true;
}
if (! hasNextO1()) {
return false;
}
Expand All @@ -434,7 +444,11 @@ public boolean hasNext() {
return true;
}
public Member[] next() {
return makeNext(o1, o2);
try {
return makeNext(o1, o2);
} finally {
o2 = null;
}
}
public void remove() {
throw new UnsupportedOperationException("remove");
Expand Down Expand Up @@ -475,6 +489,9 @@ public Iterator<Member[]> iterator() {
Iterator i2 = it2.iterator();
Object o2 = null;
public boolean hasNext() {
if (o2 != null) {
return true;
}
if (! hasNextO1()) {
return false;
}
Expand All @@ -493,7 +510,11 @@ public boolean hasNext() {
return true;
}
public Member[] next() {
return makeNext(o1, o2);
try {
return makeNext(o1, o2);
} finally {
o2 = null;
}
}
public void remove() {
throw new UnsupportedOperationException("remove");
Expand Down Expand Up @@ -535,6 +556,9 @@ public Iterator<Member[]> iterator() {
int index2 = 0;
Object o2 = null;
public boolean hasNext() {
if (o2 != null) {
return true;
}
if (! hasNextO1()) {
return false;
}
Expand All @@ -553,7 +577,11 @@ public boolean hasNext() {
return true;
}
public Member[] next() {
return makeNext(o1, o2);
try {
return makeNext(o1, o2);
} finally {
o2 = null;
}
}
public void remove() {
throw new UnsupportedOperationException("remove");
Expand Down
18 changes: 16 additions & 2 deletions src/main/mondrian/olap/fun/FilterFunDef.java
Expand Up @@ -212,6 +212,9 @@ public Iterator<Member> iterator() {
Iterator<Member> it = iter.iterator();
Member m = null;
public boolean hasNext() {
if (m != null) {
return true;
}
if (! it.hasNext()) {
return false;
}
Expand All @@ -227,7 +230,11 @@ public boolean hasNext() {
return true;
}
public Member next() {
return this.m;
try {
return this.m;
} finally {
this.m = null;
}
}
public void remove() {
throw new UnsupportedOperationException("remove");
Expand Down Expand Up @@ -310,6 +317,9 @@ public Iterator<Member[]> iterator() {
Iterator<Member[]> it = iter.iterator();
Member[] m = null;
public boolean hasNext() {
if (m != null) {
return true;
}
if (! it.hasNext()) {
return false;
}
Expand All @@ -325,7 +335,11 @@ public boolean hasNext() {
return true;
}
public Member[] next() {
return this.m;
try {
return this.m;
} finally {
this.m = null;
}
}
public void remove() {
throw new UnsupportedOperationException("remove");
Expand Down
39 changes: 22 additions & 17 deletions src/main/mondrian/olap/fun/SetFunDef.java
Expand Up @@ -340,17 +340,16 @@ public Iterable evaluateIterable(Evaluator evaluator) {
Iterable<Member> iterable = new Iterable<Member>() {
public Iterator<Member> iterator() {
return new Iterator<Member>() {
private Member m = null;
private Member m = member;
public boolean hasNext() {
if (m == null) {
m = member;
return true;
} else {
return false;
}
return (m != null);
}
public Member next() {
return m;
try {
return m;
} finally {
m = null;
}
}
public void remove() {
throw new UnsupportedOperationException("remove");
Expand All @@ -373,17 +372,16 @@ public Iterable evaluateIterable(Evaluator evaluator) {
Iterable<Member[]> iterable = new Iterable<Member[]>() {
public Iterator<Member[]> iterator() {
return new Iterator<Member[]>() {
private Member[] m = null;
private Member[] m = members;
public boolean hasNext() {
if (m == null) {
m = members;
return true;
} else {
return false;
}
return (m != null);
}
public Member[] next() {
return m;
try {
return m;
} finally {
m = null;
}
}
public void remove() {
throw new UnsupportedOperationException("remove");
Expand All @@ -408,6 +406,9 @@ public Iterator<Member> iterator() {
Iterator<Member> currentIterator = null;
Member member = null;
public boolean hasNext() {
if (member != null) {
return true;
}
if (currentIterator == null) {
if (index >= iterCalcs.length) {
return false;
Expand Down Expand Up @@ -437,7 +438,11 @@ public boolean hasNext() {
return true;
}
public Member next() {
return member;
try {
return member;
} finally {
member = null;
}
}
public void remove() {
throw new UnsupportedOperationException("remove");
Expand Down
22 changes: 17 additions & 5 deletions src/main/mondrian/rolap/RolapAxis.java
Expand Up @@ -15,6 +15,7 @@
import mondrian.olap.Member;
import mondrian.olap.Position;
import mondrian.util.UnsupportedList;
import org.apache.log4j.Logger;
import java.util.Collection;
import java.util.Collections;
import java.util.ListIterator;
Expand All @@ -34,6 +35,7 @@
* @version $Id$
*/
public abstract class RolapAxis implements Axis {
private static final Logger LOGGER = Logger.getLogger(RolapAxis.class);
/**
* A Wrapper has many uses. In particular, if one is using Java 5 or
* above, one can create a Wrapper that is also a memory usage listener.
Expand Down Expand Up @@ -152,6 +154,11 @@ class PositionWrapper extends PositionListUnsupported {
positionList = new PositionIter();
}
protected synchronized void materialize() {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"PositionWrapper.materialize: Member iter.class="
+ iter.getClass().getName());
}
RolapAxis.MemberIterable.this.materialize();
positionList = new PositionList();
}
Expand Down Expand Up @@ -218,9 +225,11 @@ public boolean hasNext() {
return (member != null);
}
public Member next() {
Member m = member;
member = null;
return m;
try {
return member;
} finally {
member = null;
}
}
public void remove() {
throw new UnsupportedOperationException("remove");
Expand Down Expand Up @@ -363,6 +372,11 @@ class PositionWrapper extends PositionListUnsupported {
positionList = new PositionIter();
}
protected synchronized void materialize() {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"PositionWrapper.materialize: Member[] iter.class="
+ iter.getClass().getName());
}
RolapAxis.MemberArrayIterable.this.materialize();
positionList = new PositionList();
}
Expand Down Expand Up @@ -400,10 +414,8 @@ class PositionIter extends PositionIterBase {
}
public Iterator<Position> iterator() {
return new Iterator<Position>() {
int hasNextCnt = 0;
int nextCnt = 0;
public boolean hasNext() {
hasNextCnt++;
return it.hasNext();
}
public Position next() {
Expand Down
4 changes: 3 additions & 1 deletion src/main/mondrian/rolap/RolapCell.java
Expand Up @@ -169,7 +169,9 @@ public Object getPropertyValue(String propertyName) {
case Property.VALUE_ORDINAL:
return getValue();
case Property.FORMAT_STRING_ORDINAL:
return getEvaluator().getFormatString();
return (cachedFormatString == null)
? getEvaluator().getFormatString()
: cachedFormatString;
case Property.FORMATTED_VALUE_ORDINAL:
return getFormattedValue();
case Property.FONT_FLAGS_ORDINAL:
Expand Down
6 changes: 5 additions & 1 deletion src/main/mondrian/rolap/RolapResult.java
Expand Up @@ -61,6 +61,7 @@ class RolapResult extends ResultBase {
this.batchingReader = new FastBatchingCellReader(rcube);
this.cellValues = new HashMap<CellKey, Object>();
this.formatStrings = new HashMap<CellKey, String>();

if (!execute) {
return;
}
Expand Down Expand Up @@ -497,7 +498,10 @@ private void executeStripe(int axisOrdinal, RolapEvaluator evaluator) {
evaluator.format(value, cachedFormatString);
}

formatStrings.put(key, cachedFormatString);
// no need to store a null format string
if (cachedFormatString != null) {
formatStrings.put(key, cachedFormatString);
}

} catch (MondrianEvaluationException e) {
// ignore
Expand Down

0 comments on commit eada284

Please sign in to comment.