All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hyperfoil.api.config.Protocol Maven / Gradle / Ivy

There is a newer version: 0.27
Show newest version
package io.hyperfoil.api.config;

import java.util.stream.Stream;

public enum Protocol {
    HTTP("http", 80, false),
    HTTPS("https", 443, true);

    public final String scheme;
    public final int defaultPort;
    public final boolean secure;

    Protocol(String scheme, int defaultPort, boolean secure) {
        this.scheme = scheme;
        this.defaultPort = defaultPort;
        this.secure = secure;
    }

    public static Protocol fromScheme(String scheme) {
        return Stream.of(values()).filter(p -> p.scheme.equals(scheme)).findFirst()
              .orElseThrow(() -> new IllegalArgumentException("Unknown scheme '"+ scheme + "'"));
    }

    public int portOrDefault(int port) {
        return port < 0 ? defaultPort : port;
    }

    public boolean secure() {
        return secure;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy