ProtocolRepository implémenté

This commit is contained in:
Maximilien LEDOUX 2022-02-26 16:01:47 +01:00
parent 1dc0512bd0
commit 8b12bf0d5f
2 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,15 @@
package lightcontainer.interfaces;
import lightcontainer.protocol.ProtocolReader;
import lightcontainer.protocol.ProtocolWriter;
public interface ProtocolRepository {
boolean executeReader(String data);
String executeWriter(String... datas);
void addReader(ProtocolReader reader);
void addWriter(ProtocolWriter writer);
}

View File

@ -0,0 +1,44 @@
package lightcontainer.repository;
import lightcontainer.interfaces.ProtocolRepository;
import lightcontainer.protocol.ProtocolReader;
import lightcontainer.protocol.ProtocolWriter;
import java.util.HashSet;
import java.util.Set;
public class ProtocolRepositoryImpl implements ProtocolRepository {
private Set<ProtocolReader> readers = new HashSet<>();
private Set<ProtocolWriter> writers = new HashSet<>();
@Override
public boolean executeReader(String data) {
for (ProtocolReader reader : readers) {
if (reader.execute(data)) {
return true;
}
}
return false;
}
@Override
public String executeWriter(String... datas) {
for (ProtocolWriter writer : writers) {
String command = writer.execute(datas);
if (command != null) {
return command;
}
}
return null;
}
@Override
public void addReader(ProtocolReader reader) {
this.readers.add(reader);
}
@Override
public void addWriter(ProtocolWriter writer) {
this.writers.add(writer);
}
}