ProtocolRepository implémenté
This commit is contained in:
parent
1dc0512bd0
commit
8b12bf0d5f
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user