com.greenpepper.interpreter.collection.CollectionInterpreter Maven / Gradle / Ivy
The newest version!
/*
* 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.*;
import com.greenpepper.annotation.Annotations;
import com.greenpepper.call.Annotate;
import com.greenpepper.call.Compile;
import com.greenpepper.interpreter.AbstractTableInterpreter;
import com.greenpepper.interpreter.CollectionHeaderForm;
import com.greenpepper.interpreter.column.Column;
import com.greenpepper.interpreter.column.ExpectedColumn;
import com.greenpepper.interpreter.column.NullColumn;
import com.greenpepper.reflect.CollectionProvider;
import com.greenpepper.reflect.Fixture;
import com.greenpepper.reflect.NoSuchMessageException;
import com.greenpepper.util.StringUtil;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import static com.greenpepper.GreenPepper.canContinue;
import static com.greenpepper.GreenPepper.shouldStop;
import static com.greenpepper.annotation.Annotations.exception;
import static com.greenpepper.annotation.Annotations.ignored;
import static com.greenpepper.util.ExampleUtil.contentOf;
// TODO: STATS compile stats here and in derived classes ( no test for that yet )
/**
* Abstract CollectionInterpreter class.
*
* @author oaouattara
* @version $Id: $Id
*/
public abstract class CollectionInterpreter extends AbstractTableInterpreter
{
/**
* statistics.
*
* @return a {@link com.greenpepper.Statistics} object.
*/
public Statistics statistics()
{
return this.stats;
}
/**
* Constructor for CollectionInterpreter.
*
* @param fixture a {@link com.greenpepper.reflect.Fixture} object.
*/
protected CollectionInterpreter( Fixture fixture )
{
super(fixture);
}
protected ExpectedColumn parseColumn(Example header )
{
try
{
return CollectionHeaderForm.parse(header.getContent()).selectColumn();
}
catch (Exception e)
{
header.annotate( exception( e ) );
stats.exception();
return new NullColumn();
}
}
/**
* toList.
*
* @param results a {@link java.lang.Object} object.
* @return a {@link java.util.List} object.
*/
private List> toList(Object results)
{
if (results instanceof Object[])
{
return Arrays.asList( (Object[]) results );
}
if (results instanceof Collection)
{
return new ArrayList