Permalink
Browse files

Formatting code

  • Loading branch information...
1 parent eea8d51 commit 2505c57ec41f78a8affb1b51f0389dda5f7697b1 @luiz committed Mar 7, 2012
@@ -20,7 +20,7 @@
/**
* The algorithm implementation
- *
+ *
* @author Luiz Fernando Oliveira Corte Real
*/
public final class AZTEC {
@@ -35,7 +35,7 @@ public AZTEC(AlgorithmParameters params) {
* Encodes the given signal, writing the output to the
* {@link EncodingOutput} specified in the {@link AlgorithmParameters}
* passed on the construction of this object
- *
+ *
* @param signal
* Signal to be encoded
* @throws IOException
@@ -15,22 +15,23 @@
*/
package br.ime.usp.aztec;
-
/**
* AZTEC algorithm parameters provider interface.
- *
+ *
* @author Luiz Fernando Oliveira Corte Real
*/
public interface AlgorithmParameters {
/**
* Default value for the parameter T of the algorithm, in samples
+ *
* @see AlgorithmParameters#getT()
*/
public static final double DEFAULT_T = 4;
/**
* Default value for the parameter N of the algorithm, in samples
+ *
* @see AlgorithmParameters#getN()
*/
public static final double DEFAULT_N = 25;
@@ -34,10 +34,11 @@
/**
* Parses algorithm parameters from command line, such as voltage variation
* threshold, and stores them.
- *
+ *
* @author Luiz Fernando Oliveira Corte Real
*/
-public final class CommandLineAlgorithmParameters implements AlgorithmParameters {
+public final class CommandLineAlgorithmParameters implements
+ AlgorithmParameters {
private final CommandLine options;
@@ -48,7 +49,8 @@
* if the given arguments are invalid or neither the mandatory
* argument -K nor -h were not given
*/
- public CommandLineAlgorithmParameters(String[] commandLine) throws ParseException {
+ public CommandLineAlgorithmParameters(String[] commandLine)
+ throws ParseException {
CommandLineParser parser = new PosixParser();
this.options = parser.parse(getCommandLineOptions(), commandLine);
if (!this.options.hasOption('h') && !this.options.hasOption('K')) {
@@ -24,7 +24,8 @@
public static void main(String[] args) throws Exception {
try {
- CommandLineAlgorithmParameters params = new CommandLineAlgorithmParameters(args);
+ CommandLineAlgorithmParameters params = new CommandLineAlgorithmParameters(
+ args);
if (params.isHelpAsked()) {
CommandLineAlgorithmParameters.printHelp();
System.exit(0);
@@ -20,13 +20,13 @@
/**
* An object to transform the algorithm output, composed of real values, to any
* desired format
- *
+ *
* @author Luiz Fernando Oliveira Corte Real
*/
public interface EncodingOutput {
/**
* Adds a new value to the algorithm output
- *
+ *
* @param value
* Any value generated by the algorithm
* @throws IOException
@@ -21,7 +21,7 @@
/**
* Container for AZTEC algorithm parameters that can be created from inside the
* program. Must be created with the Builder class inside it.
- *
+ *
* @author Luiz Fernando Oliveira Corte Real
* @see CommandLineAlgorithmParameters
*/
@@ -37,29 +37,34 @@
private ProgrammaticAlgorithmParameters() {
}
+ @Override
public double getT() {
return t;
}
+ @Override
public double getK() {
return k;
}
+ @Override
public double getN() {
return n;
}
+ @Override
public Iterable<Double> getInput() {
return input;
}
+ @Override
public EncodingOutput getOutput() {
return output;
}
/**
* Builder for {@link ProgrammaticAlgorithmParameters}
- *
+ *
* @author Luiz Fernando Oliveira Corte Real
*/
public static final class Builder {
@@ -77,8 +82,10 @@ public OptionalParametersBuilder withMaximumAcceptableVariation(
this.params.k = variation;
this.params.n = DEFAULT_N;
this.params.t = DEFAULT_T;
- this.params.input = new SignalParser(new InputStreamReader(System.in));
- this.params.output = new WriterEncodingOutput(new OutputStreamWriter(System.out));
+ this.params.input = new SignalParser(new InputStreamReader(
+ System.in));
+ this.params.output = new WriterEncodingOutput(
+ new OutputStreamWriter(System.out));
return new OptionalParametersBuilder(params);
}
}
@@ -138,7 +145,7 @@ public OptionalParametersBuilder withOutput(EncodingOutput output) {
/**
* Call this method when you have finished the configuration of the
* parameters
- *
+ *
* @return A configured {@link ProgrammaticAlgorithmParameters}
*/
public ProgrammaticAlgorithmParameters build() {
@@ -25,7 +25,7 @@
/**
* Parses a signal from a given reader
- *
+ *
* @author Luiz Fernando Oliveira Corte Real
*/
public final class SignalParser implements Iterable<Double> {
@@ -67,7 +67,8 @@ public String toString() {
public Iterator<Double> iterator() {
return new Iterator<Double>() {
- private final BufferedReader bufferedReader = new BufferedReader(reader);
+ private final BufferedReader bufferedReader = new BufferedReader(
+ reader);
private final int numReadPoints = readPoints.size();
private int usedReadPoints = 0;
private String nextLine;
@@ -89,7 +90,8 @@ public Double next() {
readPoints.add(read);
return read;
} catch (Exception e) {
- throw new NoSuchElementException("Failed to read more items");
+ throw new NoSuchElementException(
+ "Failed to read more items");
}
}
@@ -21,7 +21,7 @@
/**
* Writes the given values in a Writer, one per line, using Java's default
* double formatting.
- *
+ *
* @author Luiz Fernando Oliveira Corte Real
*/
public final class WriterEncodingOutput implements EncodingOutput {
@@ -39,7 +39,9 @@ public void put(double value) throws IOException {
/**
* Closes underlying writer
- * @throws IOException If the underlying writer throws this exception
+ *
+ * @throws IOException
+ * If the underlying writer throws this exception
*/
public void close() throws IOException {
this.writer.close();
@@ -54,51 +54,59 @@ public void encodesSomethingCloseToALineAsALine() throws Exception {
}
@Test
- public void createsTwoLinesIfInputVariationExceedsMaximumAcceptableVariation() throws Exception {
+ public void createsTwoLinesIfInputVariationExceedsMaximumAcceptableVariation()
+ throws Exception {
Iterable<Double> signal = asList(1.0, 1.01, 1.1, 1.0, 1.02, 1.12, 1.12);
this.aztec.encode(signal);
assertThat(this.output, contains(5.0, 1.05, 2.0, 1.12));
}
@Test
public void breaksABigLineIntoTwo() throws Exception {
- Iterable<Double> signal = asList(1.0, 1.1, 1.1, 1.1, 1.0, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1);
+ Iterable<Double> signal = asList(1.0, 1.1, 1.1, 1.1, 1.0, 1.1, 1.1,
+ 1.1, 1.1, 1.1, 1.1);
this.aztec.encode(signal);
assertThat(this.output, contains(10.0, 1.05, 1.0, 1.1));
}
@Test
public void encodesASinglePositiveSlope() throws Exception {
- Iterable<Double> signal = asList(1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.5, 1.6, 1.8, 1.9, 2.0);
+ Iterable<Double> signal = asList(1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.5,
+ 1.6, 1.8, 1.9, 2.0);
this.aztec.encode(signal);
assertThat(this.output, contains(-11.0, 1.0));
}
@Test
public void encodesASingleNegativeSlope() throws Exception {
- Iterable<Double> signal = asList(2.0, 1.9, 1.8, 1.7, 1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0);
+ Iterable<Double> signal = asList(2.0, 1.9, 1.8, 1.7, 1.6, 1.5, 1.4,
+ 1.3, 1.2, 1.1, 1.0);
this.aztec.encode(signal);
assertThat(this.output, contains(-11.0, -1.0));
}
@Test
public void encodesASmallSlopeBetweenTwoLines() throws Exception {
- Iterable<Double> signal = asList(1.0, 1.0, 1.1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.5, 1.5);
+ Iterable<Double> signal = asList(1.0, 1.0, 1.1, 1.1, 1.2, 1.3, 1.4,
+ 1.5, 1.5, 1.5);
this.aztec.encode(signal);
double subtractionError = 9e-17;
- assertThat(this.output, contains(4.0, 1.05, -2.0, 0.1 + subtractionError, 4.0, 1.45));
+ assertThat(this.output,
+ contains(4.0, 1.05, -2.0, 0.1 + subtractionError, 4.0, 1.45));
}
@Test
public void encodesABigNegativeSlopeBetweenTwoLines() throws Exception {
- Iterable<Double> signal = asList(10.0, 10.0, 10.0, 10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 1.0, 1.0, 1.0);
+ Iterable<Double> signal = asList(10.0, 10.0, 10.0, 10.0, 9.0, 8.0, 7.0,
+ 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 1.0, 1.0, 1.0);
this.aztec.encode(signal);
assertThat(this.output, contains(4.0, 10.0, -8.0, -7.0, 4.0, 1.0));
}
@Test
@Ignore
- public void encodesAPositiveSlopeFollowedByANegativeSlope() throws Exception {
+ public void encodesAPositiveSlopeFollowedByANegativeSlope()
+ throws Exception {
Iterable<Double> signal = asList(1.0, 2.0, 3.0, 4.0, 3.0, 2.0, 1.0, 0.0);
this.aztec.encode(signal);
assertThat(this.output, contains(-4.0, 3.0, -4.0, -3.0));
@@ -107,7 +115,6 @@ public void encodesAPositiveSlopeFollowedByANegativeSlope() throws Exception {
private AlgorithmParameters createDefaultParameters() {
return new ProgrammaticAlgorithmParameters.Builder()
.withMaximumAcceptableVariation(0.1)
- .withMaximumLineLength(10.0)
- .withOutput(this.output).build();
+ .withMaximumLineLength(10.0).withOutput(this.output).build();
}
}
@@ -40,8 +40,11 @@
@Before
public void setUp() throws Exception {
File tempFile = createTempFile();
- this.filledParameters = new CommandLineAlgorithmParameters(new String[] { "-K", "15", "-T", "3", "-N", "30", "-i", tempFile.getAbsolutePath() });
- this.defaultParameters = new CommandLineAlgorithmParameters(new String[] { "-K", "20" });
+ this.filledParameters = new CommandLineAlgorithmParameters(
+ new String[] { "-K", "15", "-T", "3", "-N", "30", "-i",
+ tempFile.getAbsolutePath() });
+ this.defaultParameters = new CommandLineAlgorithmParameters(
+ new String[] { "-K", "20" });
}
private File createTempFile() throws IOException {
@@ -53,7 +56,8 @@ private File createTempFile() throws IOException {
}
@Test
- public void extractsMaximumVoltageVariationFromCommandLine() throws Exception {
+ public void extractsMaximumVoltageVariationFromCommandLine()
+ throws Exception {
assertThat(this.filledParameters.getK(), is(15.0));
}
@@ -70,7 +74,8 @@ public void extractsMaximumLineLengthFromCommandLine() throws Exception {
@Test
public void detectsIfHelpWasAsked() throws Exception {
assertThat(this.filledParameters.isHelpAsked(), is(false));
- CommandLineAlgorithmParameters askedHelp = new CommandLineAlgorithmParameters(new String[] { "-h" });
+ CommandLineAlgorithmParameters askedHelp = new CommandLineAlgorithmParameters(
+ new String[] { "-h" });
assertThat(askedHelp.isHelpAsked(), is(true));
}
@@ -85,7 +90,8 @@ public void createsWriterForGivenOutputFile() throws Exception {
File tempFile = createTempFile();
Double number = 3.14159;
- CommandLineAlgorithmParameters params = new CommandLineAlgorithmParameters(new String[] { "-K", "20", "-o", tempFile.getAbsolutePath() });
+ CommandLineAlgorithmParameters params = new CommandLineAlgorithmParameters(
+ new String[] { "-K", "20", "-o", tempFile.getAbsolutePath() });
WriterEncodingOutput output = params.getOutput();
output.put(number);
output.close();
@@ -25,7 +25,7 @@
/**
* An implementation of {@link EncodingOutput} that is also iterable, so that
* one can inspect what values were put.
- *
+ *
* @author Luiz Fernando Oliveira Corte Real
*/
public final class MockEncodingOutput implements Iterable<Double>,

0 comments on commit 2505c57

Please sign in to comment.