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

com.greenpepper.document.Document Maven / Gradle / Ivy

The newest version!
package com.greenpepper.document;

import static com.greenpepper.GreenPepper.canContinue;

import java.io.PrintWriter;

import com.greenpepper.Example;
import com.greenpepper.Interpreter;
import com.greenpepper.Statistics;
import com.greenpepper.TimeStatistics;

/**
 * 

Document class.

* * @author oaouattara * @version $Id: $Id */ public class Document { private final String type; private final Example start; private final Statistics stats; private final TimeStatistics timeStats; private final CompositeFilter filters; private String[] sections; private final String name; private final String externalLink; private String uri; private SpecificationListener listener = new NullSpecificationListener(); /** *

html.

* * @param example a {@link com.greenpepper.Example} object. * @return a {@link com.greenpepper.document.Document} object. */ public static Document html( Example example ) { return new Document( "html", example ); } /** *

html.

* * @param example a {@link com.greenpepper.Example} object. * @param name a {@link java.lang.String} object. * @param externalLink a {@link java.lang.String} object. * @return a {@link com.greenpepper.document.Document} object. */ public static Document html( Example example, String name, String externalLink ) { return new Document( "html", example, name, externalLink ); } /** *

text.

* * @param example a {@link com.greenpepper.Example} object. * @return a {@link com.greenpepper.document.Document} object. */ public static Document text( Example example ) { return new Document( "txt", example ); } /** *

Constructor for Document.

* * @param type a {@link java.lang.String} object. * @param example a {@link com.greenpepper.Example} object. */ public Document( String type, Example example ) { this( type, example, null, null ); } /** *

Constructor for Document.

* * @param type a {@link java.lang.String} object. * @param example a {@link com.greenpepper.Example} object. * @param name a {@link java.lang.String} object. * @param externalLink a {@link java.lang.String} object. */ public Document( String type, Example example, String name, String externalLink ) { this.type = type; this.start = example; this.name = name; this.externalLink = externalLink; this.stats = new Statistics(); this.timeStats = new TimeStatistics(); this.filters = new CompositeFilter(); } /** *

Getter for the field type.

* * @return a {@link java.lang.String} object. */ public String getType() { return type; } /** *

Getter for the field sections.

* * @return an array of {@link java.lang.String} objects. */ public String[] getSections() { return sections; } /** *

Setter for the field sections.

* * @param sections an array of {@link java.lang.String} objects. */ public void setSections(String[] sections) { this.sections = sections; } /** *

Getter for the field name.

* * @return a {@link java.lang.String} object. */ public String getName() { return name; } /** *

Getter for the field externalLink.

* * @return a {@link java.lang.String} object. */ public String getExternalLink() { return externalLink; } /** *

setSpecificationListener.

* * @param listener a {@link com.greenpepper.document.SpecificationListener} object. */ public void setSpecificationListener( SpecificationListener listener ) { this.listener = listener; } /** *

execute.

* * @param interpreterSelector a {@link com.greenpepper.document.InterpreterSelector} object. */ public void execute(InterpreterSelector interpreterSelector) { AbstractSpecification spec = new FilteredSpecification( start ); while (spec.hasMoreExamples() && canContinue( stats )) { Interpreter interpreter = interpreterSelector.selectInterpreter( spec.peek() ); interpreter.interpret( spec ); } } /** *

print.

* * @param writer a {@link java.io.PrintWriter} object. */ public void print( PrintWriter writer ) { start.print( writer ); } /** *

tally.

* * @param statistics a {@link com.greenpepper.Statistics} object. */ public void tally( Statistics statistics ) { stats.tally( statistics ); } /** *

Getter for the field uri.

* * @return a {@link java.lang.String} object. */ public String getUri() { return uri; } /** *

Setter for the field uri.

* * @param uri a {@link java.lang.String} object. */ public void setUri(String uri) { this.uri = uri; } public class FilteredSpecification extends AbstractSpecification { public FilteredSpecification(Example start) { super(); setStart( start ); } protected Example peek() { return new EagerFilter( filters ).filter( cursor.nextSibling() ); } public void exampleDone( Statistics statistics ) { tally( statistics ); listener.exampleDone( cursor, statistics ); } } /** * Notify the registered listener that the specification is done */ public void done() { listener.specificationDone( start, stats ); } /** *

addFilter.

* * @param filter a {@link com.greenpepper.document.ExampleFilter} object. */ public void addFilter( ExampleFilter filter ) { filters.add( filter ); } /** *

getStatistics.

* * @return a {@link com.greenpepper.Statistics} object. */ public Statistics getStatistics() { return stats; } /** *

getTimeStatistics.

* * @return a {@link com.greenpepper.TimeStatistics} object. */ public TimeStatistics getTimeStatistics() { return timeStats; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy