📄 dimensioncursor.java
字号:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/**
* Title: XELOPES Data Mining Library
* Description: The XELOPES library is an open platform-independent and data-source-independent library for Embedded Data Mining.
* Copyright: Copyright (c) 2002 Prudential Systems Software GmbH
* Company: ZSoft (www.zsoft.ru), Prudsys (www.prudsys.com)
* @author Michael Thess
* @version 1.2
*/
package com.prudsys.pdm.Olap.Cursor;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Map;
import javax.olap.OLAPException;
import javax.olap.cursor.Blob;
import javax.olap.cursor.Clob;
import javax.olap.cursor.Time;
import javax.olap.cursor.Timestamp;
import com.prudsys.pdm.Core.CategoricalAttribute;
import com.prudsys.pdm.Core.Category;
import com.prudsys.pdm.Core.MiningAttribute;
import com.prudsys.pdm.Core.MiningDataSpecification;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Input.MiningVector;
import com.prudsys.pdm.Olap.Metadata.Dimension;
import com.prudsys.pdm.Olap.Metadata.Measure;
import com.prudsys.pdm.Olap.Metadata.MeasureDimension;
import com.prudsys.pdm.Olap.Query.Core.DimensionStepManager;
import com.prudsys.pdm.Olap.Query.Core.DimensionView;
/**
* Dimension cursor access class. Supports navigation on asymmetric edges.
*/
public class DimensionCursor extends Cursor implements javax.olap.cursor.DimensionCursor
{
// -----------------------------------------------------------------------
// Variables declarations
// -----------------------------------------------------------------------
/** Reference to edge cursor ownig this dimension cursor. */
protected EdgeCursor edgeCursor;
/** Reference to dimension step manager. */
protected DimensionStepManager dimensionStepManager;
/** Reference to DimensionView. */
protected DimensionView dimView;
/** Indexes of dimension attributees in meta data of edge cursor stream. */
protected int[] attIndexes;
/** Cursor of left (controling) dimension. */
protected DimensionCursor leftCursor = null;
/** Cursor of right dimension. */
protected DimensionCursor rightCursor = null;
/** Value number of left (controling) dimension. */
protected int leftNr = 0;
/** Extent values for all left dimension value numbers. */
protected int[] extents;
/** Current cursor position. */
protected int cursorPosition = -1;
// -----------------------------------------------------------------------
// Constructors
// -----------------------------------------------------------------------
/**
* Empty constructor.
*/
public DimensionCursor() {
}
/**
* Constructor with dimension data.
*
* @param edgeCursor edge cursor owning this dimension
* @param dimView reference to associated dimension view
* @param leftCursor cursor of left (controling) dimension
* @param rightCursor cursor of right dimension
* @exception OLAPException cannot create dimension cursor
*/
public DimensionCursor(EdgeCursor edgeCursor, DimensionView dimView,
DimensionCursor leftCursor, DimensionCursor rightCursor) throws OLAPException {
this.edgeCursor = edgeCursor;
this.dimView = dimView;
this.leftCursor = leftCursor;
this.rightCursor = rightCursor;
createIndexes();
}
/**
* Creates array of indexes of dimension attribute in meta data of
* edge cursor stream.
*
* @throws OLAPException cannot create indexes
*/
private void createIndexes() throws OLAPException {
try {
MiningDataSpecification metaData = edgeCursor.edgeStream.getMetaData();
Dimension dim = (Dimension) dimView.getDimension();
int nAtt = dim.getNumberOfDimensionAttributes();
attIndexes = new int[nAtt];
for (int i = 0; i < nAtt; i++) {
MiningAttribute ma = null;
if (dim instanceof MeasureDimension) {
Measure meas = ((MeasureDimension) dim).getMeasureAttribute(i);
ma = metaData.getMiningAttribute( meas.getName() );
}
else
ma = dim.getDimensionAttribute(i);
attIndexes[i] = metaData.getAttributeIndex(ma);
};
}
catch (MiningException ex) {
throw new OLAPException( ex.toString() );
};
}
// -----------------------------------------------------------------------
// Getter and setter methods
// -----------------------------------------------------------------------
public void setEdgeCursor(javax.olap.cursor.EdgeCursor input) throws OLAPException {
this.edgeCursor = (EdgeCursor) input;
}
public javax.olap.cursor.EdgeCursor getEdgeCursor() throws OLAPException {
return edgeCursor;
}
public long getEdgeStart() throws OLAPException {
throw new UnsupportedOperationException();
}
public void setEdgeStart(long input) throws OLAPException {
throw new UnsupportedOperationException();
}
public long getEdgeEnd() throws OLAPException {
throw new UnsupportedOperationException();
}
public void setEdgeEnd(long input) throws OLAPException {
throw new UnsupportedOperationException();
}
public void setCurrentDimensionStepManager(javax.olap.query.querycoremodel.DimensionStepManager input) throws OLAPException {
this.dimensionStepManager = (DimensionStepManager) input;
}
public javax.olap.query.querycoremodel.DimensionStepManager getCurrentDimensionStepManager() throws OLAPException {
return dimensionStepManager;
}
// -----------------------------------------------------------------------
// RowDataNavigation methods
// -----------------------------------------------------------------------
protected int readKey() throws OLAPException {
return (int) edgeCursor.read().getValue(attIndexes[0]);
}
public boolean next() throws OLAPException {
if ( cursorPosition >= extents[leftNr] ) return false;
int val0 = -1;
if (cursorPosition >= 0) val0 = readKey();
int val = val0;
while ( val == val0 ) {
if (cursorPosition >= extents[leftNr] - 1) {
if (leftCursor == null) edgeCursor.next();
cursorPosition++;
return false;
}
else {
if (leftCursor == null || val0 > -1) edgeCursor.next();
}
val = readKey();
}
cursorPosition++;
if (rightCursor != null) {
rightCursor.setLeftNr(rightCursor.getLeftNr() + 1);
rightCursor.beforeFirst();
}
return true;
}
public boolean previous() throws OLAPException {
throw new UnsupportedOperationException();
}
public boolean relative(int arg0) throws OLAPException {
throw new UnsupportedOperationException();
}
public void beforeFirst() throws OLAPException {
cursorPosition = -1;
if (leftCursor == null)
edgeCursor.beforeFirst();
}
public void afterLast() throws OLAPException {
throw new UnsupportedOperationException();
}
public boolean isFirst() throws OLAPException {
return cursorPosition == 0;
}
public boolean isLast() throws OLAPException {
throw new UnsupportedOperationException();
}
public boolean first() throws OLAPException {
if (1 > 0) {
cursorPosition = 0;
return true;
}
else
return false;
}
public boolean last() throws OLAPException {
throw new UnsupportedOperationException();
}
public boolean isBeforeFirst() throws OLAPException {
return cursorPosition < 0;
}
public boolean isAfterLast() throws OLAPException {
throw new UnsupportedOperationException();
}
public void setPosition(long position) throws OLAPException {
throw new UnsupportedOperationException();
}
public long getPosition() throws OLAPException {
return cursorPosition;
}
public void close() throws OLAPException {
}
public int getType() throws OLAPException {
throw new UnsupportedOperationException();
}
public int getFetchDirection() throws OLAPException {
throw new UnsupportedOperationException();
}
public void setFetchDirection(int arg0) throws OLAPException {
throw new UnsupportedOperationException();
}
public int getFetchSize() throws OLAPException {
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -