• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

coditory / quark-uri / #3

pending completion
#3

push

github-actions

ogesaku
init

1212 of 1212 new or added lines in 21 files covered. (100.0%)

926 of 1212 relevant lines covered (76.4%)

0.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.31
/src/main/java/com/coditory/quark/uri/UriAuthority.java
1
package com.coditory.quark.uri;
2

3
import org.jetbrains.annotations.NotNull;
4
import org.jetbrains.annotations.Nullable;
5

6
import java.util.Locale;
7
import java.util.Objects;
8

9
import static com.coditory.quark.uri.Nullable.mapNotNull;
10
import static com.coditory.quark.uri.Ports.SCHEME_DEFAULT_PORT_NUMBER;
11
import static com.coditory.quark.uri.Ports.validatePortNumberOrSchemeDefault;
12
import static com.coditory.quark.uri.Preconditions.expectNoWhitespaces;
13
import static com.coditory.quark.uri.Preconditions.expectNonEmpty;
14

15
public final class UriAuthority {
16
    private static final UriAuthority EMPTY = new UriAuthority(null, null, SCHEME_DEFAULT_PORT_NUMBER);
1✔
17

18
    @NotNull
19
    public static UriAuthority empty() {
20
        return EMPTY;
1✔
21
    }
22

23
    @NotNull
24
    public static UriAuthority of(@Nullable String userInfo, @Nullable String hostname, int port) {
25
        if (hostname != null) {
1✔
26
            expectNoWhitespaces(hostname, "hostname");
1✔
27
        }
28
        if (userInfo != null) {
1✔
29
            expectNonEmpty(userInfo, "userInfo");
1✔
30
        }
31
        validatePortNumberOrSchemeDefault(port);
1✔
32
        if (userInfo == null && hostname == null && Ports.isSchemeDefault(port)) {
1✔
33
            return empty();
1✔
34
        }
35
        return new UriAuthority(
1✔
36
                userInfo,
37
                mapNotNull(hostname, h -> h.toLowerCase(Locale.ROOT)),
1✔
38
                port
39
        );
40
    }
41

42
    private final String userInfo;
43
    private final String hostname;
44
    private final int port;
45

46
    private UriAuthority(@Nullable String userInfo, @Nullable String hostname, int port) {
1✔
47
        this.userInfo = userInfo;
1✔
48
        this.hostname = hostname;
1✔
49
        this.port = port;
1✔
50
    }
1✔
51

52
    @Nullable
53
    public String getUserInfo() {
54
        return userInfo;
×
55
    }
56

57
    @Nullable
58
    public String getHostname() {
59
        return hostname;
×
60
    }
61

62
    public int getPort() {
63
        return port;
×
64
    }
65

66
    public boolean usesSchemeDefaultPort() {
67
        return port == SCHEME_DEFAULT_PORT_NUMBER;
×
68
    }
69

70
    public boolean isEmpty() {
71
        return this.equals(EMPTY);
1✔
72
    }
73

74
    @Override
75
    public String toString() {
76
        return "UriAuthority{" +
×
77
                "userInfo='" + userInfo + '\'' +
78
                ", hostname='" + hostname + '\'' +
79
                ", port=" + port +
80
                '}';
81
    }
82

83
    @Override
84
    public boolean equals(Object o) {
85
        if (this == o) return true;
1✔
86
        if (o == null || getClass() != o.getClass()) return false;
1✔
87
        UriAuthority that = (UriAuthority) o;
1✔
88
        return port == that.port
1✔
89
                && Objects.equals(userInfo, that.userInfo)
1✔
90
                && Objects.equals(hostname, that.hostname);
1✔
91
    }
92

93
    @Override
94
    public int hashCode() {
95
        return Objects.hash(userInfo, hostname, port);
×
96
    }
97
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc