Question: This is a short set of problems using interfaces. You will implement two of the methods of a class called StringList that uses interfaces for
This is a short set of problems using interfaces. You will implement two of the methods of a class called StringList that uses interfaces for performing various kinds of processing on text, as well as some sample classes that implement those interfaces. In all, you'll implement eight additional classes:
public StringList map(Transformation t) This method is already implemented. Returns a new StringList obtained by invoking the given Transformation's apply method to each string in this StringList. The apply method just takes a string and returns another string. public StringList filter(Selector selector) Returns a new StringList containing only the elements of this StringList for which the Selector's select method returns true. The select method just takes a string and returns true or false. public ArrayList mapToList(Converter converter) Converts each string in this StringList into an object of some type T, and returns them in an ArrayList. The Converter has one method, convert(), that takes a string and returns an object of the specified type T. public T reduce(Combiner combiner, T initialValue) This method is already implemented. Combines all strings in this StringList into a single value of some type T. A Combiner has one method, combine, that takes a given object of type T plus a string, and returns a value of type T.
package mini2;
import api.Combiner;
/**
* Combiner that appends the first letter of a string onto
* the accumulator. If the string is empty, returns the
* accumulator.
*/
public class FirstLetterCombiner implements Combiner
{
// TODO
}
package mini2;
import api.Combiner;
/**
* Adds the length of the given string to the accumulator
* and returns the result.
*/
public class LengthCombiner implements Combiner
{
// TODO
}
package mini2;
import api.Transformation;
/**
* Transformation whose apply method prepends a line number to each string.
* For a newly created LineNumberer, the line numbers start at 1 and increase on
* each successive call. The line number is left-justified in a field 5 spaces wide.
*/
public class LineNumberer implements Transformation
{
// TODO
}
package mini2;
import api.Selector;
/**
* Selector that returns false if the current string is
* within a javadoc comment, true otherwise. Using a NonJavadocSelector
* in the filter method of a StringList has the effect of removing all
* javadoc comments. Note that we are assuming that javadoc comments
* always start and end on different lines, and that no executable
* code ever appears on the same line as a javadoc comment.
*/
public class NonJavadocSelector implements Selector
{
// TODO
}
package mini2;
import api.Selector;
/**
* Selector whose select method returns false for strings whose first non-whitespace
* text is "//", and true for all other strings.
*/
public class NonLineCommentSelector implements Selector
{
// TODO
}
package mini2;
import java.awt.Point; import java.util.Scanner;
import api.Converter; import plotter.Polyline;
/** * Converts a string into a Polyline object. The given * string must conform to the format specified for one valid line of the file * as described in Lab 8, checkpoint 2. See *
* http://web.cs.iastate.edu/~cs227/labs/lab8/page12.html **/ public class PolylineConverter implements Converter
package mini2;
import api.Combiner;
/**
* Combiner whose combine method, given an Integer n and a string,
* returns n if the string is a blank line or a line containing
* a single curly brace; otherwise returns n + 1. (A curly brace on a line whose
* only other text is an end-of-line comment is treated as just a curly brace.)
* Using a SlocCounter in the reduce method has the general effect of counting
* the number of "source lines of code" that are actual program statements,
* assuming that line comments and javadoc comments have already been
* filtered out.
*/
public class SlocCounter implements Combiner
{
// TODO
}
package mini2;
import api.Selector;
/**
* Selector that returns false for a strings that are
* empty, that are all whitespace, or whose first non-whitespace
* character is the '#' character.
*/
public class ValidLineSelector implements Selector
{
// TODO
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
