GitHub repository: kshamagirish/streams
Primary language: Java
Created: 2019-06-26T09:42:36Z
Description: Programming (60% of the project grade) For this project you will implement streams. A stream is a class that produces (theoretically) infinite amounts of data. We will create both simple streams as well as neat streams such as a stream of all primes using the Sieve of Eratosthenes.  Your project should contain the following types. Each type can be a class or an interface. You may need to create additional types to accomplish all the tasks. The goal is to write a good hierachy that limits the amount of code you need to write:  IntegerStream: An integer stream produces a continuous sequence of integers, starting at some initial integer. Each subsequence integer produced should be one more than the previous integer. The class will need the following methods and constructors:  The constructor takes an integer that represents the first value returned by the stream.  next(): Takes no input and returns the next value of the stream starting at the initial value. Each time next is called, the number returned should be one more than what was returned the previous time next was called,  For example, if you create stream = new IntegerStream(10); then calling stream.next() should produce the following: > stream.next() 10 > stream.next() 11 > stream.next() 12 StringStream: A string stream produces a continuous sequence of strings that consist of lower case letters, in lexicographical order. (The strings in lexicographical order are: { "", "a", "b", ..., "z", "aa", "ab", ..., "az", "ba", "bb", ..., "bz", ..., "zz", "aaa", "aab", ...}.) The class will need the following methods and constructors:  The constructor takes a String that represents the first value returned by the stream. (The behavior if the input is not all lowercase letters is up to you.)  next: Takes no input and returns the next value of the stream, i.e. it returns the string that is next in the lexicographical ordering from the previous value returned by next.  For example, if you create stream = new StringStream("pez"); then calling stream.next() should produce the following: > stream.next() "pez" > stream.next() "pfa" > stream.next() "pfb" NotMultipleFilter: a filter is used to apply a certain test to data. A filter also contains an upstream filter so that this filter can be part of a chain of filters. In this case, we want to determine if an integer is not divisible by some value. The class will need the following methods and constructors:  The constructor takes two values: an integer and another filter. The integer is the base value for the filter, and the other filter is the upstream filter.  passFilter: takes an integer value and returns true or false. The method should return true if the value both passes the upstream filter and is not divisible by this filter's base value.  PalindromeFilter: a filter is used to apply a certain test to data. A filter also contains an upstream filter so that this filter can be part of a chain of filters. In this case, we want to determine if a string is a palindrome. The class will need the following methods and constructors:  The constructor takes a filter that will be the upstream filter.  passFilter: takes a string value and returns true or false. The method should return true if the value both passes the upstream filter and is a palindrome (is identical forwards as backwards).  NotMultipleStream: a stream that returns, in numeric order, integers that are not multiples of a certain value, starting from an initial value. The NotMultipleStream should behave like an IntegerStream, but it should include a NotMultipleFilter to filter out multiples of a certain value. The class will need the following methods and constructors:  The constructor takes two integer values. The first is the base value and the second is the initial value.  next: takes no input and returns an integer. The first value returned by next should be the the smallest number, no smaller than the initial value such that the number is not divisible by the base value. Each subsequent call should return the next largest integer that is not a multiple of the base value.  PalindromeStream: a stream that returns all palindromes, consisting of only lower case letters, in lexicographical order. The class will need the following methods and constructors:  The constructor takes a single string that will be the initial value. You may assume the string is all lower case letters, but you may not assume it is a palindrome.  next: Takes no input and returns the next value of the stream. The first value returned should be the lexicographically smallest palindrome that is no smaller than the initial value. Each subsequenct call should return the next palindrome in lexicographical order.  PrimeStream: a stream that returns all prime numbers, in order, starting at 2. Tne stream will use the Sieve of Eratosthenes technique. The class will need the following methods and constructors:  The constructor takes no input.  next: Takes no input and returns the next prime number, in order. The first time it is called, it should return 2. Each time next is called, it should take the return value, create a NoMultiplesFilter with that number as the base and the current filter as the upstream filter and make this new filter the filter of the stream. As a result, the stream should no longer produce multiples of the last number (or all previous numbers) output by the next method.  IntegerPair: a class that represents a pair of integers. The class will need the following methods and constructors:  The constructor takes two integers.  getValue1 takes no input and returns the first value of the pair.  getValue2 takes no input and returns the second value of the pair.  toString overrides the toString method of Object to return a string representation of the pair. The representation should be the two integers, separated by a comma, and inside parentheses. For example, "(3,4)".  TwinPrimeStream: a stream that returns IntegerPair's that represent twin primes. A twin prime is a set of two primes that differ by two. For example, (3,5), (5,7), and (11,13) are twin primes. The stream should initially return (3,5), and then each subsequent pair, with the smaller prime appearing first, in numeric order of the smaller prime. The class will need the following methods and constructors:  The constructor takes no input.  next: returns the next integer pair of twin primes, in numeric order, starting with (3,5).  MersennePrimeStream: a stream that returns primes of the form 2^x -1., starting with the smallest such prime. The class will need the following methods and constructors:  The constructor takes no input.  next: returns the next Mersenne prime. (Hint: You need to get the next prime and then determine if one more than that number is a power of 2.  Note that using the Sieve of Eratoshenes to find Mersenne primes is quite inefficient. You will not be able to find more than the first five before blowing up the stack. StreamUtilities: a collection of (sort of) useful things to do with streams. The class should have the following methods:  print: takes two inputs: a stream and an integer. Uses System.out.println to print the first x values returned by the stream, where x is the integer input to the method.  sum: takes a stream that produces integers and an integer as input and returns an integer. The method returns the sum of the first x values of the stream, where x is the integer input to the method.  product: takes a stream that produces integers and an integer as input and returns an integer. The method returns the product of the first x values of the stream, where x is the integer input to the method.  concatenate: takes a stream that produces strings and an integer as input and returns a string. The method returns the concatenation of the first x values of the stream, where x is the integer input to the method.