Loading src/edu/bu/ec504/hw1p1/DistinctCounter.java +6 −6 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ public abstract class DistinctCounter { * This constructor cannot be used. */ private DistinctCounter() { state = new Integer[0]; state = new Byte[0]; }; /** Loading @@ -19,15 +19,15 @@ public abstract class DistinctCounter { * @param stateSize The size of the memory backing, in number of integers. */ public DistinctCounter(int stateSize) { state =new Integer[stateSize]; state = new Byte[stateSize]; } /** * Creates a DistinctCounter object from a given initial state. * @param initialState The output of a call to {@link #currentState()} on some DistinctCounter object. */ public DistinctCounter(Integer[] initialState) { state = new Integer[initialState.length]; public DistinctCounter(Byte[] initialState) { state = new Byte[initialState.length]; for (int ii=0; ii<initialState.length; ii++) state[ii]=initialState[ii]; } Loading @@ -50,11 +50,11 @@ public abstract class DistinctCounter { /** * outputs the current state of the DistinctCounter * */ public Integer[] currentState() { public Byte[] currentState() { return state; } // FIELD final private Integer[] state; final private Byte[] state; } src/edu/bu/ec504/hw1p1/Main.java +11 −0 Original line number Diff line number Diff line Loading @@ -5,5 +5,16 @@ import java.util.Arrays; public class Main { public static void main(String[] args) { String[] testStrings = {"Bravo", "Alfa", "Charlie", "Kilo", "Charlie", "Alfa", "Bravo"}; myDistinctCounter foo = new myDistinctCounter(10); for (String test: testStrings) { foo.see(test); } Byte[] savedState = foo.currentState(); myDistinctCounter newFoo = new myDistinctCounter(savedState); System.out.println(newFoo.numDistinct()); } } Loading
src/edu/bu/ec504/hw1p1/DistinctCounter.java +6 −6 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ public abstract class DistinctCounter { * This constructor cannot be used. */ private DistinctCounter() { state = new Integer[0]; state = new Byte[0]; }; /** Loading @@ -19,15 +19,15 @@ public abstract class DistinctCounter { * @param stateSize The size of the memory backing, in number of integers. */ public DistinctCounter(int stateSize) { state =new Integer[stateSize]; state = new Byte[stateSize]; } /** * Creates a DistinctCounter object from a given initial state. * @param initialState The output of a call to {@link #currentState()} on some DistinctCounter object. */ public DistinctCounter(Integer[] initialState) { state = new Integer[initialState.length]; public DistinctCounter(Byte[] initialState) { state = new Byte[initialState.length]; for (int ii=0; ii<initialState.length; ii++) state[ii]=initialState[ii]; } Loading @@ -50,11 +50,11 @@ public abstract class DistinctCounter { /** * outputs the current state of the DistinctCounter * */ public Integer[] currentState() { public Byte[] currentState() { return state; } // FIELD final private Integer[] state; final private Byte[] state; }
src/edu/bu/ec504/hw1p1/Main.java +11 −0 Original line number Diff line number Diff line Loading @@ -5,5 +5,16 @@ import java.util.Arrays; public class Main { public static void main(String[] args) { String[] testStrings = {"Bravo", "Alfa", "Charlie", "Kilo", "Charlie", "Alfa", "Bravo"}; myDistinctCounter foo = new myDistinctCounter(10); for (String test: testStrings) { foo.see(test); } Byte[] savedState = foo.currentState(); myDistinctCounter newFoo = new myDistinctCounter(savedState); System.out.println(newFoo.numDistinct()); } }