Skip to content

Commit

Permalink
Refactored the selection objects so that everything is statically typ…
Browse files Browse the repository at this point in the history
…ed rather than a conditional instanceof check. I used a pseudo visitor pattern approach. I also factored out the selection implementations into an abstract super class. I also simplified the selection objects and removed all unnecessary calls.

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@401 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
lucboudreau committed Feb 4, 2011
1 parent 633ca0a commit 828ad8f
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 205 deletions.
73 changes: 73 additions & 0 deletions src/org/olap4j/query/AbstractSelection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
// $Id:$
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2007-2011 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package org.olap4j.query;

import java.util.ArrayList;
import java.util.List;

import org.olap4j.metadata.Dimension;

/**
* Abstract implementation of a selection.
* @author LBoudreau
* @version $Id:$
*/
abstract class AbstractSelection extends QueryNodeImpl implements Selection {

Operator operator;
Dimension dimension;
List<Selection> selectionContext;

public AbstractSelection(
Dimension dimension,
Operator operator)
{
this.dimension = dimension;
this.operator = operator;
}

public Dimension getDimension() {
return dimension;
}

public Operator getOperator() {
return operator;
}

public void setOperator(Operator operator) {
assert operator != null;
this.operator = operator;
notifyChange(this,-1);
}

void tearDown() {
}

public List<Selection> getSelectionContext() {
return selectionContext;
}

public void addContext(Selection selection) {
if (selectionContext == null) {
selectionContext = new ArrayList<Selection>();
}
selectionContext.add(selection);
}

public void removeContext(Selection selection) {
selectionContext.remove(selection);
}

public String getUniqueName() {
return getRootElement().getUniqueName();
}
}

// End AbstractSelection.java
105 changes: 13 additions & 92 deletions src/org/olap4j/query/LevelSelectionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2007-2010 Julian Hyde
// Copyright (C) 2007-2011 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package org.olap4j.query;

import java.util.ArrayList;
import java.util.List;

import org.olap4j.mdx.ParseTreeNode;
import org.olap4j.metadata.Dimension;
import org.olap4j.metadata.Level;
import org.olap4j.metadata.Member;
import org.olap4j.metadata.MetadataElement;

/**
* Abstract implementation of {@link Selection}.
Expand All @@ -23,34 +21,17 @@
* @version $Id: LevelSelectionImpl.java 399 2011-02-03 20:53:50Z pstoellberger $
* @since Feb 3, 2011
*/
class LevelSelectionImpl extends QueryNodeImpl implements Selection {
class LevelSelectionImpl extends AbstractSelection {

protected Level level;
protected String dimensionName;
protected String hierarchyName;
protected String levelName;
protected Dimension dimension;
protected Operator operator = Operator.MEMBER;
protected List<Selection> selectionContext;

/**
* Creates a SelectionImpl.
*
* @pre operator != null
*/
public LevelSelectionImpl(
Level level,
Dimension dimension,
String hierarchyName,
String levelName,
Operator operator)
{
super();
super(dimension, operator);
this.level = level;
this.dimension = dimension;
this.hierarchyName = hierarchyName;
this.levelName = levelName;
this.operator = operator;
}

public int hashCode() {
Expand Down Expand Up @@ -102,81 +83,21 @@ public boolean equals(Object obj) {
return true;
}

public String getName() {
return levelName;
}

public void setName(String name) {
levelName = name;
}

public Dimension getDimension() {
return dimension;
}

public void setDimension(Dimension dimension) {
this.dimension = dimension;
}

public Level getLevel() {
public MetadataElement getRootElement() {
return level;
}

public String getDimensionName() {
return dimensionName;
}

public void setDimensionName(String dimensionName) {
this.dimensionName = dimensionName;
}

public String getHierarchyName() {
return hierarchyName;
}

public void setHierarchyName(String hierarchyName) {
this.hierarchyName = hierarchyName;
}

public String getLevelName() {
return levelName;
}

public void setLevelName(String levelName) {
this.levelName = levelName;
}

public Operator getOperator() {
return operator;
public ParseTreeNode visit() {
return Olap4jNodeConverter.toOlap4j(level, operator);
}

@Override
public void setOperator(Operator operator) {
assert operator != null;
this.operator = operator;
notifyChange(this,-1);
}

void tearDown() {
}

public List<Selection> getSelectionContext() {
return selectionContext;
}

public void addContext(Selection selection) {
if (selectionContext == null) {
selectionContext = new ArrayList<Selection>();
if (!operator.equals(Operator.MEMBERS)) {
throw new IllegalArgumentException(
"Selections based on a Level have to be of Operator MEMBERS.");
}
selectionContext.add(selection);
}

public void removeContext(Selection selection) {
selectionContext.remove(selection);
}

public Member getMember() {
// there is no member in this type of Selections
return null;
super.setOperator(operator);
}
}

Expand Down
99 changes: 14 additions & 85 deletions src/org/olap4j/query/MemberSelectionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2007-2010 Julian Hyde
// Copyright (C) 2007-2011 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package org.olap4j.query;

import java.util.ArrayList;
import java.util.List;

import org.olap4j.mdx.ParseTreeNode;
import org.olap4j.metadata.Dimension;
import org.olap4j.metadata.Member;
import org.olap4j.metadata.MetadataElement;

/**
* Abstract implementation of {@link Selection}.
Expand All @@ -22,16 +21,9 @@
* @version $Id$
* @since May 30, 2007
*/
class MemberSelectionImpl extends QueryNodeImpl implements Selection {
class MemberSelectionImpl extends AbstractSelection {

protected Member member;
protected String dimensionName;
protected String hierarchyName;
protected String levelName;
protected String memberName;
protected Dimension dimension;
protected Operator operator = Operator.MEMBER;
protected List<Selection> selectionContext;
private Member member;

/**
* Creates a SelectionImpl.
Expand All @@ -41,18 +33,10 @@ class MemberSelectionImpl extends QueryNodeImpl implements Selection {
public MemberSelectionImpl(
Member member,
Dimension dimension,
String hierarchyName,
String levelName,
String memberName,
Operator operator)
{
super();
super(dimension, operator);
this.member = member;
this.dimension = dimension;
this.hierarchyName = hierarchyName;
this.levelName = levelName;
this.memberName = memberName;
this.operator = operator;
}

public int hashCode() {
Expand Down Expand Up @@ -104,76 +88,21 @@ public boolean equals(Object obj) {
return true;
}

public String getName() {
return memberName;
}

public void setName(String name) {
memberName = name;
}

public Dimension getDimension() {
return dimension;
}

public void setDimension(Dimension dimension) {
this.dimension = dimension;
}

public Member getMember() {
public MetadataElement getRootElement() {
return member;
}

public String getDimensionName() {
return dimensionName;
}

public void setDimensionName(String dimensionName) {
this.dimensionName = dimensionName;
}

public String getHierarchyName() {
return hierarchyName;
}

public void setHierarchyName(String hierarchyName) {
this.hierarchyName = hierarchyName;
}

public String getLevelName() {
return levelName;
}

public void setLevelName(String levelName) {
this.levelName = levelName;
}

public Operator getOperator() {
return operator;
public ParseTreeNode visit() {
return Olap4jNodeConverter.toOlap4j(member, operator);
}

@Override
public void setOperator(Operator operator) {
assert operator != null;
this.operator = operator;
notifyChange(this,-1);
}

void tearDown() {
}

public List<Selection> getSelectionContext() {
return selectionContext;
}

public void addContext(Selection selection) {
if (selectionContext == null) {
selectionContext = new ArrayList<Selection>();
if (operator.equals(Operator.MEMBERS)) {
throw new IllegalArgumentException(
"Selections based on a Members cannot be of Operator MEMBERS.");
}
selectionContext.add(selection);
}

public void removeContext(Selection selection) {
selectionContext.remove(selection);
super.setOperator(operator);
}
}

Expand Down
Loading

0 comments on commit 828ad8f

Please sign in to comment.