/*
* Debellor
*
* Copyright (C) 2008-2009 by Marcin Wojnarski
*
* 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 3 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, see http://www.gnu.org/licenses/.
*/
package org.debellor.core.cell;
import org.debellor.core.Cell;
import org.debellor.core.Sample;
import org.debellor.core.Sample.SampleType;
/**
* Buffer which holds at most one {@link Sample},
* passed into the buffer by a special method {@link #put}.
* Useful when samples must be passed to a cell
* one-by-one, under control of an outside procedure.
* With method {@link #isEmpty} it can be checked
* whether the receiving cell has "eaten" up the sample or not.
*
* @author Marcin Wojnarski
*
*/
public class SingleSample extends Cell {
private Sample theSample;
protected SampleType type;
public SingleSample() {
super(false);
}
public boolean isEmpty() {
return theSample == null;
}
public void put(Sample s) {
theSample = s;
}
@Override
protected SampleType onOpen() throws Exception {
return type;
}
@Override
protected Sample onNext() throws Exception {
Sample s = theSample;
theSample = null;
return s;
}
@Override
protected void onClose() throws Exception {
}
public void setType(SampleType type) {
this.type = type;
}
}