Skip to content

Commit a40a9f5

Browse files
committed
final keyword added throughout file
1 parent bcda703 commit a40a9f5

22 files changed

+197
-193
lines changed

src/main/java/org/sela/App.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,34 @@
1010
import org.sela.exception.FileException;
1111

1212
public final class App {
13-
public static void main(String[] args) {
13+
public static void main(final String[] args) {
1414
System.out.println("\u001B[1mSimplE Lossless Audio. Released under MIT license\u001B[0m");
1515
if (args.length < 2) {
1616
printUsage();
1717
} else {
1818
try {
1919
parseCommandLineArgs(args);
20-
} catch (Exception e) {
20+
} catch (final Exception e) {
2121
System.err.println("\u001B[1m" + e.getMessage() + ". Aborting...\u001B[0m");
2222
e.printStackTrace();
2323
}
2424
}
2525
}
2626

27-
private static void parseCommandLineArgs(String[] args) throws IOException, FileException, LineUnavailableException {
27+
private static void parseCommandLineArgs(final String[] args)
28+
throws IOException, FileException, LineUnavailableException {
2829
if (args[0].equals("-e") && args.length == 3) {
29-
File inputFile = new File(args[1]);
30-
File outputFile = new File(args[2]);
30+
final File inputFile = new File(args[1]);
31+
final File outputFile = new File(args[2]);
3132
System.out.println("\u001B[1mEncoding: \u001B[0m" + inputFile.getAbsolutePath());
3233
encodeFile(inputFile, outputFile);
3334
} else if (args[0].equals("-d") && args.length == 3) {
34-
File inputFile = new File(args[1]);
35-
File outputFile = new File(args[2]);
35+
final File inputFile = new File(args[1]);
36+
final File outputFile = new File(args[2]);
3637
System.out.println("\u001B[1mDecoding: \u001B[0m" + inputFile.getAbsolutePath());
3738
decodeFile(inputFile, outputFile);
3839
} else if (args[0].equals("-p") && args.length == 2) {
39-
File inputFile = new File(args[1]);
40+
final File inputFile = new File(args[1]);
4041
System.out.println("\u001B[1mPlaying: \u001B[0m" + inputFile.getAbsolutePath());
4142
playFile(inputFile);
4243
System.out.println("");
@@ -48,20 +49,20 @@ private static void parseCommandLineArgs(String[] args) throws IOException, File
4849
System.out.println("\u001B[1mDone\u001B[0m");
4950
}
5051

51-
private static void encodeFile(File inputFile, File outputFile) throws IOException, FileException {
52-
Encoder selaEncoder = new Encoder(inputFile, outputFile);
53-
SelaFile selaFile = selaEncoder.process();
52+
private static void encodeFile(final File inputFile, final File outputFile) throws IOException, FileException {
53+
final Encoder selaEncoder = new Encoder(inputFile, outputFile);
54+
final SelaFile selaFile = selaEncoder.process();
5455
selaFile.writeToStream();
5556
}
5657

57-
private static void decodeFile(File inputFile, File outputFile) throws IOException, FileException {
58-
Decoder selaDecoder = new Decoder(inputFile, outputFile);
59-
WavFile wavFile = selaDecoder.process();
58+
private static void decodeFile(final File inputFile, final File outputFile) throws IOException, FileException {
59+
final Decoder selaDecoder = new Decoder(inputFile, outputFile);
60+
final WavFile wavFile = selaDecoder.process();
6061
wavFile.writeToStream();
6162
}
6263

63-
private static void playFile(File inputFile) throws IOException, FileException, LineUnavailableException {
64-
Player selaPlayer = new Player(inputFile);
64+
private static void playFile(final File inputFile) throws IOException, FileException, LineUnavailableException {
65+
final Player selaPlayer = new Player(inputFile);
6566
selaPlayer.play();
6667
}
6768

src/main/java/org/sela/Decoder.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
public class Decoder {
1717
protected WavFile wavFile;
1818
protected SelaFile selaFile;
19-
private File outputFile;
19+
private final File outputFile;
2020

21-
public Decoder(File inputFile, File outputFile) throws FileNotFoundException {
21+
public Decoder(final File inputFile, final File outputFile) throws FileNotFoundException {
2222
this.selaFile = new SelaFile(new FileInputStream(inputFile));
2323
this.outputFile = outputFile;
2424
}
@@ -29,21 +29,22 @@ private void readFrames() throws IOException, FileException {
2929

3030
protected List<WavFrame> processFrames() throws IOException, FileException {
3131
readFrames();
32-
32+
3333
// Decode frames in parallel
34-
List<WavFrame> wavFrames = selaFile.getFrames().parallelStream().map(x -> new FrameDecoder(x).process())
34+
final List<WavFrame> wavFrames = selaFile.getFrames().parallelStream().map(x -> new FrameDecoder(x).process())
3535
.collect(Collectors.toList());
36-
36+
3737
// Sort decoded samples
3838
Collections.sort(wavFrames);
3939

4040
return wavFrames;
4141
}
4242

4343
public WavFile process() throws IOException, FileException {
44-
List<WavFrame> wavFrames = processFrames();
44+
final List<WavFrame> wavFrames = processFrames();
4545

46-
WavFile wavFile = new WavFile(selaFile.getSampleRate(), selaFile.getBitsPerSample(), selaFile.getChannels(), wavFrames, new FileOutputStream(outputFile));
46+
final WavFile wavFile = new WavFile(selaFile.getSampleRate(), selaFile.getBitsPerSample(),
47+
selaFile.getChannels(), wavFrames, new FileOutputStream(outputFile));
4748
this.wavFile = wavFile;
4849
return wavFile;
4950
}

src/main/java/org/sela/Encoder.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@
1313
import org.sela.exception.*;
1414

1515
public class Encoder {
16-
private WavFile wavFile;
17-
private File outputFile;
16+
private final WavFile wavFile;
17+
private final File outputFile;
1818
private List<WavFrame> wavFrames;
1919
private int frameCount;
2020
private final int samplePerSubFrame = 2048;
2121

22-
public Encoder(File inputFile, File outputFile) throws FileException, IOException {
22+
public Encoder(final File inputFile, final File outputFile) throws FileException, IOException {
2323
wavFile = new WavFile(inputFile);
2424
this.outputFile = outputFile;
2525
}
2626

2727
private void readSamples() {
28-
long sampleCount = wavFile.getSampleCount();
28+
final long sampleCount = wavFile.getSampleCount();
2929
frameCount = (int) Math.ceil((double) sampleCount / (samplePerSubFrame * wavFile.getNumChannels()));
3030
wavFrames = new ArrayList<>(frameCount);
3131

3232
for (int i = 0; i < frameCount; i++) {
33-
int[][] samples = new int[wavFile.getNumChannels()][samplePerSubFrame];
33+
final int[][] samples = new int[wavFile.getNumChannels()][samplePerSubFrame];
3434
wavFile.readFrames(samples, samplePerSubFrame);
3535
wavFrames.add(new WavFrame(i, samples));
3636
}
@@ -40,7 +40,7 @@ public SelaFile process() throws IOException {
4040
readSamples();
4141

4242
// Encode samples in parallel
43-
List<Frame> frames = wavFrames.parallelStream()
43+
final List<Frame> frames = wavFrames.parallelStream()
4444
.map(x -> (new FrameEncoder(x)).process()).collect(Collectors.toList());
4545

4646
// Sort encoded frames

src/main/java/org/sela/Player.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,37 @@
1515
import org.sela.exception.FileException;
1616

1717
public class Player extends Decoder {
18-
List<WavFrame> wavFrames;
18+
private List<WavFrame> wavFrames;
1919

20-
public Player(File inputFile) throws IOException, FileException {
20+
public Player(final File inputFile) throws IOException, FileException {
2121
super(inputFile, null);
2222
wavFrames = super.processFrames();
2323
}
2424

25-
private static void printProgress(long current, long total) {
26-
StringBuilder string = new StringBuilder(140);
27-
int percent = (int) (current * 100 / total);
28-
string.append('\r')
29-
.append(String.format("%d%% [", percent))
30-
.append(String.join("", Collections.nCopies(percent / 2, "=")))
31-
.append("\u001B[1m>\u001B[0m")
32-
.append(String.join("", Collections.nCopies(50 - (percent / 2), " ")))
33-
.append(']')
34-
.append(" (").append(current).append('/').append(total).append(')');
25+
private static void printProgress(final long current, final long total) {
26+
final StringBuilder string = new StringBuilder(140);
27+
final int percent = (int) (current * 100 / total);
28+
string.append('\r').append(String.format("%d%% [", percent))
29+
.append(String.join("", Collections.nCopies(percent / 2, "="))).append("\u001B[1m>\u001B[0m")
30+
.append(String.join("", Collections.nCopies(50 - (percent / 2), " "))).append(']').append(" (")
31+
.append(current).append('/').append(total).append(')');
3532
System.out.print(string);
3633
}
3734

3835
public void play() throws LineUnavailableException {
3936
// Select audio format parameters
40-
AudioFormat af = new AudioFormat(super.selaFile.getSampleRate(), super.selaFile.getBitsPerSample(),
37+
final AudioFormat af = new AudioFormat(super.selaFile.getSampleRate(), super.selaFile.getBitsPerSample(),
4138
super.selaFile.getChannels(), true, false);
42-
DataLine.Info info = new DataLine.Info(SourceDataLine.class, af);
43-
SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
39+
final DataLine.Info info = new DataLine.Info(SourceDataLine.class, af);
40+
final SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
4441

4542
// Prepare audio output
4643
line.open(af, 2048 * super.selaFile.getChannels());
4744
line.start();
4845

4946
// Output wave form repeatedly
5047
for (int i = 0; i < wavFrames.size(); i++) {
51-
byte[] bytes = wavFrames.get(i).getDemuxedShortSamplesInByteArray();
48+
final byte[] bytes = wavFrames.get(i).getDemuxedShortSamplesInByteArray();
5249
line.write(bytes, 0, bytes.length);
5350
Player.printProgress((i + 1), wavFrames.size());
5451
}

src/main/java/org/sela/data/Chunk.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ else if(!format.equals("WAVE")) {
2020
}
2121
}
2222

23-
public void write(ByteBuffer buffer) {
24-
buffer.put((byte)'R');
25-
buffer.put((byte)'I');
26-
buffer.put((byte)'F');
27-
buffer.put((byte)'F');
23+
public void write(final ByteBuffer buffer) {
24+
buffer.put((byte) 'R');
25+
buffer.put((byte) 'I');
26+
buffer.put((byte) 'F');
27+
buffer.put((byte) 'F');
2828
buffer.putInt(chunkSize);
29-
buffer.put((byte)'W');
30-
buffer.put((byte)'A');
31-
buffer.put((byte)'V');
32-
buffer.put((byte)'E');
33-
for (SubChunk subChunk : subChunks) {
29+
buffer.put((byte) 'W');
30+
buffer.put((byte) 'A');
31+
buffer.put((byte) 'V');
32+
buffer.put((byte) 'E');
33+
for (final SubChunk subChunk : subChunks) {
3434
subChunk.write(buffer);
3535
}
3636
}

src/main/java/org/sela/data/Frame.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
public final class Frame implements Comparable<Frame> {
77
public final int syncWord = 0xAA55FF00;
88
public ArrayList<SubFrame> subFrames;
9-
private int index; // For internal sorting, not to be written to output
9+
private final int index; // For internal sorting, not to be written to output
1010

11-
public Frame(ArrayList<SubFrame> subFrames, int index) {
11+
public Frame(final ArrayList<SubFrame> subFrames, final int index) {
1212
this.subFrames = subFrames;
1313
this.index = index;
1414
}
1515

16-
public Frame(int index) {
16+
public Frame(final int index) {
1717
this.index = index;
1818
}
1919

@@ -22,21 +22,21 @@ public int getIndex() {
2222
}
2323

2424
@Override
25-
public int compareTo(Frame frame) {
25+
public int compareTo(final Frame frame) {
2626
return this.index - frame.index;
2727
}
2828

2929
public int getByteCount() {
3030
int count = 4;
31-
for (SubFrame subFrame : subFrames) {
31+
for (final SubFrame subFrame : subFrames) {
3232
count += subFrame.getByteCount();
3333
}
3434
return count;
3535
}
3636

37-
public void write(ByteBuffer buffer) {
37+
public void write(final ByteBuffer buffer) {
3838
buffer.putInt(syncWord);
39-
for (SubFrame subFrame : subFrames) {
39+
for (final SubFrame subFrame : subFrames) {
4040
subFrame.write(buffer);
4141
}
4242
}

src/main/java/org/sela/data/LpcDecodedData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public final class LpcDecodedData {
44
public int[] samples;
55

6-
public LpcDecodedData(int[] samples) {
6+
public LpcDecodedData(final int[] samples) {
77
this.samples = samples;
88
}
99
}

src/main/java/org/sela/data/LpcEncodedData.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ public final class LpcEncodedData {
55
public int[] quantizedReflectionCoefficients;
66
public int[] residues;
77

8-
public LpcEncodedData(byte optimalLpcOrder, int[] quantizedReflectionCoefficients, int[] residues) {
8+
public LpcEncodedData(final byte optimalLpcOrder, final int[] quantizedReflectionCoefficients,
9+
final int[] residues) {
910
this.optimalLpcOrder = optimalLpcOrder;
1011
this.quantizedReflectionCoefficients = quantizedReflectionCoefficients;
1112
this.residues = residues;

src/main/java/org/sela/data/RiceDecodedData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public final class RiceDecodedData {
44
public int[] decodedData;
55

6-
public RiceDecodedData(int[] decodedData) {
6+
public RiceDecodedData(final int[] decodedData) {
77
this.decodedData = decodedData;
88
}
99
}

src/main/java/org/sela/data/RiceEncodedData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public final class RiceEncodedData {
55
public int dataCount;
66
public int[] encodedData;
77

8-
public RiceEncodedData(int optimumRiceParam, int dataCount, int[] encodedData) {
8+
public RiceEncodedData(final int optimumRiceParam, final int dataCount, final int[] encodedData) {
99
this.optimumRiceParam = optimumRiceParam;
1010
this.dataCount = dataCount;
1111
this.encodedData = encodedData;

0 commit comments

Comments
 (0)