com.greenpepper.interpreter.collection.RowFixtureSplitter Maven / Gradle / Ivy
/*
* Copyright (c) 2006 Pyxis Technologies inc.
*
* This 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 2 of the License, or
* (at your option) any later version.
*
* This software 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA,
* or see the FSF site: http://www.fsf.org.
*/
package com.greenpepper.interpreter.collection;
import com.greenpepper.Example;
import com.greenpepper.interpreter.column.Column;
import com.greenpepper.reflect.Fixture;
import java.util.ArrayList;
import java.util.List;
/**
* RowFixtureSplitter class.
*
* @author oaouattara
* @version $Id: $Id
*/
public class RowFixtureSplitter
{
private List match = new ArrayList();
private List missing = new ArrayList();
private List surplus = new ArrayList();
/**
* Getter for the field match
.
*
* @return a {@link java.util.List} object.
*/
public List getMatch()
{
return match;
}
/**
* Getter for the field missing
.
*
* @return a {@link java.util.List} object.
*/
public List getMissing()
{
return missing;
}
/**
* Getter for the field surplus
.
*
* @return a {@link java.util.List} object.
*/
public List getSurplus()
{
return surplus;
}
void split(Example rows, List adapters, Column[] headers )
{
surplus.addAll( adapters );
for (Example row : rows)
{
Fixture adapter = findMatchingFixture( row, surplus, headers );
if (adapter != null)
{
surplus.remove( adapter );
match.add( new RowFixture( row, adapter ) );
}
else
{
missing.add( row );
}
}
}
private Fixture findMatchingFixture(Example row, List fixtures, Column[] headers )
{
for (Fixture fixture : fixtures)
{
if (Row.parse( fixture, headers ).matches( row.firstChild() ) )
{
return fixture;
}
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy