TurtleDB
A mini distributed database system
|
00001 /*------------------------------------------------------------------------- 00002 Simple distributed database engine 00003 Copyright (C) 2012 Sylvain Hallé 00004 00005 This program is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation, either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 -------------------------------------------------------------------------*/ 00018 package ca.uqac.dim.turtledb; 00019 00020 import java.util.LinkedList; 00021 import java.util.List; 00022 00023 public abstract class RelationStreamIterator implements RelationIterator 00024 { 00025 protected List<Tuple> m_outputTuples; 00026 protected Tuple m_nextTuple; 00027 protected boolean m_internalNextCalled; 00028 00029 public RelationStreamIterator() 00030 { 00031 super(); 00032 m_outputTuples = new LinkedList<Tuple>(); 00033 m_internalNextCalled = false; 00034 } 00035 00036 @Override 00037 public final boolean hasNext() 00038 { 00039 if (!m_internalNextCalled) 00040 { 00041 next(); 00042 m_internalNextCalled = true; 00043 } 00044 return m_nextTuple != null; 00045 } 00046 00047 @Override 00048 public final Tuple next() 00049 { 00050 if (!m_internalNextCalled) 00051 { 00052 while (true) 00053 { 00054 m_nextTuple = internalNext(); 00055 if (m_nextTuple == null) 00056 { 00057 break; 00058 } 00059 if (!m_outputTuples.contains(m_nextTuple)) 00060 { 00061 m_outputTuples.add(m_nextTuple); 00062 break; 00063 } 00064 } 00065 } 00066 m_internalNextCalled = false; 00067 return m_nextTuple; 00068 } 00069 00083 protected abstract Tuple internalNext(); 00084 00085 @Override 00086 public final void remove() 00087 { 00088 // Not supported at the moment 00089 } 00090 00095 public void reset() 00096 { 00097 m_nextTuple = null; 00098 m_outputTuples.clear(); 00099 m_internalNextCalled = false; 00100 } 00101 }