Commit c54b8d1b authored by Jean-Mael BOIS's avatar Jean-Mael BOIS
Browse files

Réalisation du projet

parent ec15694a
package fr.unantes.dnssd;
public interface ServiceApplicationModifier {
ServiceDescriptionBuilder application(String application);
}
......@@ -2,30 +2,30 @@ package fr.unantes.dnssd;
public class ServiceDescription {
private String name;
private int port;
private String transport;
private String application;
private String subtype;
private int weight;
private int priority;
private int ttl;
private boolean persistent;
private String name;
private int port;
private String transport;
private String application;
private String subtype;
private int weight;
private int priority;
private int ttl;
private boolean persistent;
public ServiceDescription(String name, int port, String transport,
String application, String subtype, int weight, int priority, int ttl,
boolean persistent) {
public ServiceDescription(String name, int port, String transport,
String application, String subtype, int weight, int priority, int ttl,
boolean persistent) {
this.name = name;
this.port = port;
this.transport = transport;
this.application = application;
this.subtype = subtype;
this.weight = weight;
this.priority = priority;
this.ttl = ttl;
this.persistent = persistent;
}
this.name = name;
this.port = port;
this.transport = transport;
this.application = application;
this.subtype = subtype;
this.weight = weight;
this.priority = priority;
this.ttl = ttl;
this.persistent = persistent;
}
}
package fr.unantes.dnssd;
public interface ServiceDescriptionBuilder {
ServiceDescriptionBuilder subtype(String subtype);
ServiceDescriptionBuilder weight(int weight);
ServiceDescriptionBuilder priority(int priority);
ServiceDescriptionBuilder ttl(int ttl);
ServiceDescriptionBuilder persistent(boolean persistent);
ServiceDescription build();
}
package fr.unantes.dnssd;
public interface ServiceNameModifier {
ServicePortModifier name(String name);
}
package fr.unantes.dnssd;
public interface ServicePortModifier {
ServiceTransportModifier port(int port);
}
package fr.unantes.dnssd;
public interface ServiceTransportModifier {
ServiceApplicationModifier transport(String transport);
}
package fr.unantes.dnssd;
public class SimpleServiceDescriptionBuilder implements ServiceNameModifier, ServicePortModifier, ServiceTransportModifier, ServiceApplicationModifier, ServiceDescriptionBuilder {
private String name;
private int port;
private String transport;
private String application;
private String subtype;
private int weight;
private int priority;
private int ttl;
private boolean persistent;
public SimpleServiceDescriptionBuilder() {
this.subtype = null;
this.weight = 0;
this.priority = 0;
this.ttl = 3600;
this.persistent = false;
}
@Override
public ServicePortModifier name(String name) {
this.name = name;
return this;
}
@Override
public ServiceTransportModifier port(int port) {
this.port = port;
return this;
}
@Override
public ServiceApplicationModifier transport(String transport) {
this.transport = transport;
return this;
}
@Override
public ServiceDescriptionBuilder application(String application) {
this.application = application;
return this;
}
@Override
public ServiceDescriptionBuilder subtype(String subtype) {
this.subtype = subtype;
return this;
}
@Override
public ServiceDescriptionBuilder weight(int weight) {
this.weight = weight;
return this;
}
@Override
public ServiceDescriptionBuilder priority(int priority) {
this.priority = priority;
return this;
}
@Override
public ServiceDescriptionBuilder ttl(int ttl) {
this.ttl = ttl;
return this;
}
@Override
public ServiceDescriptionBuilder persistent(boolean persistent) {
this.persistent = persistent;
return this;
}
@Override
public ServiceDescription build() {
return new ServiceDescription(name, port, transport, application, subtype, weight, priority, ttl, persistent);
}
}
import fr.unantes.dnssd.ServiceDescription;
import fr.unantes.dnssd.SimpleServiceDescriptionBuilder;
import org.junit.jupiter.api.Test;
public class SimpleServiceDescriptionBuilderTest {
@Test
void creation_service_avec_parametre_par_default() {
ServiceDescription serviceDescription =
new SimpleServiceDescriptionBuilder()
.name("name")
.port(404)
.transport("transport")
.application("application")
.build();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment