📍Use lombok, reformat, and optimize the code (#1560)
* Use lombok, reformat, and optimize the code * Fix merge conflicts and some sonar issues Co-authored-by: va1m <va1m@email.com>
This commit is contained in:
@ -27,8 +27,7 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Event or message queues provide an asynchronous communications protocol, meaning that the sender
|
||||
@ -40,10 +39,9 @@ import org.slf4j.LoggerFactory;
|
||||
* enqueues the request and returns. The request processor then processes items from the queue at a
|
||||
* later time.
|
||||
*/
|
||||
@Slf4j
|
||||
public class App {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
*
|
||||
|
@ -29,16 +29,15 @@ import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.LineUnavailableException;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* This class implements the Event Queue pattern.
|
||||
*
|
||||
* @author mkuprivecz
|
||||
*/
|
||||
@Slf4j
|
||||
public class Audio {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Audio.class);
|
||||
private static final Audio INSTANCE = new Audio();
|
||||
|
||||
private static final int MAX_PENDING = 16;
|
||||
|
@ -24,36 +24,22 @@
|
||||
package com.iluwatar.event.queue;
|
||||
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* The Event Queue's queue will store the instances of this class.
|
||||
*
|
||||
* @author mkuprivecz
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class PlayMessage {
|
||||
|
||||
private AudioInputStream stream;
|
||||
private final AudioInputStream stream;
|
||||
|
||||
@Setter
|
||||
private float volume;
|
||||
|
||||
public PlayMessage(AudioInputStream stream, float volume) {
|
||||
setStream(stream);
|
||||
setVolume(volume);
|
||||
}
|
||||
|
||||
public AudioInputStream getStream() {
|
||||
return stream;
|
||||
}
|
||||
|
||||
private void setStream(AudioInputStream stream) {
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
public float getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
public void setVolume(float volume) {
|
||||
this.volume = volume;
|
||||
}
|
||||
}
|
||||
|
@ -23,22 +23,21 @@
|
||||
|
||||
package com.iluwatar.event.queue;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
/**
|
||||
* Testing the Audio service of the Queue
|
||||
* @author mkuprivecz
|
||||
*
|
||||
*/
|
||||
public class AudioTest {
|
||||
class AudioTest {
|
||||
|
||||
private Audio audio;
|
||||
|
||||
@ -46,6 +45,7 @@ public class AudioTest {
|
||||
void createAudioInstance() {
|
||||
audio = new Audio();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test here that the playSound method works correctly
|
||||
* @throws UnsupportedAudioFileException when the audio file is not supported
|
||||
@ -53,7 +53,7 @@ public class AudioTest {
|
||||
* @throws InterruptedException when the test is interrupted externally
|
||||
*/
|
||||
@Test
|
||||
public void testPlaySound() throws UnsupportedAudioFileException, IOException, InterruptedException {
|
||||
void testPlaySound() throws UnsupportedAudioFileException, IOException, InterruptedException {
|
||||
audio.playSound(audio.getAudioStream("./etc/Bass-Drum-1.wav"), -10.0f);
|
||||
// test that service is started
|
||||
assertTrue(audio.isServiceRunning());
|
||||
@ -72,7 +72,7 @@ public class AudioTest {
|
||||
* @throws InterruptedException when the test is interrupted externally
|
||||
*/
|
||||
@Test
|
||||
public void testQueue() throws UnsupportedAudioFileException, IOException, InterruptedException {
|
||||
void testQueue() throws UnsupportedAudioFileException, IOException, InterruptedException {
|
||||
audio.playSound(audio.getAudioStream("./etc/Bass-Drum-1.aif"), -10.0f);
|
||||
audio.playSound(audio.getAudioStream("./etc/Bass-Drum-1.aif"), -10.0f);
|
||||
audio.playSound(audio.getAudioStream("./etc/Bass-Drum-1.aif"), -10.0f);
|
||||
|
Reference in New Issue
Block a user