All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.codetaco.funnel.provider.FunnelInternalNodeProvider Maven / Gradle / Ivy

There is a newer version: 3.0.5
Show newest version
package com.codetaco.funnel.provider;

import java.io.IOException;
import java.text.ParseException;

import com.codetaco.funnel.Funnel;
import com.codetaco.funnel.FunnelDataProvider;
import com.codetaco.funnel.FunnelItem;

/**
 * 

* FunnelInternalNodeProvider class. *

* * @author Chris DeGreef [email protected] */ public class FunnelInternalNodeProvider implements FunnelDataProvider { final Funnel funnel; final FunnelItem left; final FunnelItem right; /** *

* Constructor for FunnelInternalNodeProvider. *

* * @param _funnel a {@link com.codetaco.funnel.Funnel} object. * @param leftContestantIndex a {@link com.codetaco.funnel.FunnelItem} * object. * @param rightContestantIndex a {@link com.codetaco.funnel.FunnelItem} * object. */ public FunnelInternalNodeProvider( final Funnel _funnel, final FunnelItem leftContestantIndex, final FunnelItem rightContestantIndex) { funnel = _funnel; left = leftContestantIndex; right = rightContestantIndex; } /** {@inheritDoc} */ @Override public long actualNumberOfRows() { return maximumNumberOfRows(); } /** {@inheritDoc} */ @Override public void attachTo(final FunnelItem item) { item.setProvider(this); } /** {@inheritDoc} */ @Override public void close() throws IOException { // intentionally empty } /** {@inheritDoc} */ @Override public long maximumNumberOfRows() { return Long.MAX_VALUE; } /** {@inheritDoc} */ @Override public boolean next(final FunnelItem item, final long phase) throws IOException, ParseException { if (!left.isEndOfData() && left.getData() == null) left.next(phase); if (!right.isEndOfData() && right.getData() == null) right.next(phase); if (left.isEndOfData()) { if (right.isEndOfData()) { item.setEndOfData(true); return false; } item.setData(right.getData()); item.setPhase(phase); right.next(phase); return true; } else if (right.isEndOfData()) { item.setData(left.getData()); item.setPhase(phase); left.next(phase); return true; } /* * compare right and left nodes and use the one that is less */ if (left.getData().compareTo(right.getData()) > 0) { item.setData(right.getData()); item.setPhase(phase); right.next(phase); } else { item.setData(left.getData()); item.setPhase(phase); left.next(phase); } return true; } /** {@inheritDoc} */ @Override public void reset() { // Intentionally empty } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy