인터페이스값을 리턴을 하려고 합니다.
글쓴이: rbtjdi / 작성시간: 일, 2012/02/12 - 12:24오후
다음은 인터페이스 입니다.
package simpledb;
import java.util.*;
/**
* DbFileIterator is the iterator interface that all SimpleDB Dbfile should
* implement.
*/
public interface DbFileIterator {
/**
* Opens the iterator
* @throws DbException when there are problems opening/accessing the database.
*/
public void open()
throws DbException, TransactionAbortedException;
/** @return true if there are more tuples available. */
public boolean hasNext()
throws DbException, TransactionAbortedException;
/**
* Gets the next tuple from the operator (typically implementing by reading
* from a child operator or an access method).
*
* @return The next tuple in the iterator.
* @throws NoSuchElementException if there are no more tuples
*/
public Tuple next()
throws DbException, TransactionAbortedException, NoSuchElementException;
/**
* Resets the iterator to the start.
* @throws DbException When rewind is unsupported.
*/
public void rewind() throws DbException, TransactionAbortedException;
/**
* Closes the iterator.
*/
public void close();
}다음은 자바 메소드 입니다. 이 메소드에서 리턴을 합니다.
public DbFileIterator iterator(TransactionId tid) {
// some code goes here
BufferPool bufferPool = Database.getBufferPool();
Vector vT = new Vector();
Enumeration<PageId> ePid = bufferPool.pages.keys();
DbFileIterator re;
while(ePid.hasMoreElements())
{
PageId pid = (PageId) ePid.nextElement();
Page page = null;
try {
page = bufferPool.getPage(tid, pid, Permissions.READ_ONLY);
} catch (TransactionAbortedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DbException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(((HeapPage)page).td == this.td)
{
for(Tuple t : ((HeapPage)page).tuples)
{
if(t != null)
vT.add(t);
}
}
}
re = (DbFileIterator) vT.iterator(); <----------
return re;
}
}보시는 바와 같이 (DbFileIterator) vT.iterator(); 부분에서 JUnit 테스트를 통과 못하고 에러가 납니다. 그럴만도 한것 같습니다. 벡터의 iterator값을
DbFileIterator 인터페이스로 캐스팅이 될까요?
저 인터페이스를 implements한 클래스조차 없습니다. 이런 경우 어떻게 리턴을 해줘야 하는지 정말 모르겠네요..
Forums:


댓글 달기