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.Iterator; 00021 00022 public abstract class RelationCacheIterator implements RelationIterator 00023 { 00024 protected Table m_intermediateResult; 00025 00026 private boolean m_called; 00027 00028 private Iterator<Tuple> m_internalIterator; 00029 00030 public RelationCacheIterator() 00031 { 00032 super(); 00033 m_called = false; 00034 } 00035 00036 @Override 00037 public final boolean hasNext() 00038 { 00039 if (!m_called) 00040 initialize(); 00041 return m_internalIterator.hasNext(); 00042 } 00043 00044 @Override 00045 public final Tuple next() 00046 { 00047 if (!m_called) 00048 initialize(); 00049 return m_internalIterator.next(); 00050 } 00051 00052 protected final void initialize() 00053 { 00054 getIntermediateResult(); 00055 m_internalIterator = m_intermediateResult.tupleIterator(); 00056 m_called = true; 00057 } 00058 00059 @Override 00060 public void reset() 00061 { 00062 m_internalIterator = m_intermediateResult.tupleIterator(); 00063 } 00064 00065 @Override 00066 public final void remove() 00067 { 00068 // Unsupported at the moment 00069 } 00070 00071 protected abstract void getIntermediateResult(); 00072 }