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

alibaba / java-dns-cache-manipulator / 1267

pending completion
1267

push

Appveyor

oldratlee
chore(ci): upgrade CI JDK 🤖

527 of 645 relevant lines covered (81.71%)

0.82 hits per line

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

67.86
/library/src/main/java/com/alibaba/dcm/DnsCacheEntry.java
1
package com.alibaba.dcm;
2

3
import edu.umd.cs.findbugs.annotations.ReturnValuesAreNonnullByDefault;
4
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
5

6
import javax.annotation.ParametersAreNonnullByDefault;
7
import javax.annotation.concurrent.Immutable;
8
import java.io.Serializable;
9
import java.text.SimpleDateFormat;
10
import java.util.Arrays;
11
import java.util.Date;
12
import java.util.Objects;
13

14
/**
15
 * DNS cache entry(DNS record).
16
 *
17
 * @author Jerry Lee (oldratlee at gmail dot com)
18
 * @see DnsCache
19
 */
20
@Immutable
21
@ParametersAreNonnullByDefault
22
@ReturnValuesAreNonnullByDefault
23
public final class DnsCacheEntry implements Serializable {
24
    private static final long serialVersionUID = -7476648934387757732L;
25

26
    private final String host;
27
    private final String[] ips;
28
    private final long expiration;
29

30
    /**
31
     * get host name/domain name of DNS cache entry(DNS record).
32
     */
33
    public String getHost() {
34
        return host;
1✔
35
    }
36

37
    /**
38
     * get ips of DNS cache entry(DNS record).
39
     */
40
    public String[] getIps() {
41
        return ips.clone(); // defensive copy
1✔
42
    }
43

44
    /**
45
     * get the first ip of {@link #getIps()}
46
     */
47
    public String getIp() {
48
        return ips[0];
1✔
49
    }
50

51
    /**
52
     * get the expiration of DNS cache entry(DNS record).
53
     * <p>
54
     * return value {@link Long#MAX_VALUE} means "never expiration".
55
     */
56
    public Date getExpiration() {
57
        return new Date(expiration);
1✔
58
    }
59

60
    /**
61
     * Construct a {@link DnsCacheEntry}.
62
     *
63
     * @deprecated use {@link #DnsCacheEntry(String, String[], long)} instead
64
     */
65
    @Deprecated
66
    public DnsCacheEntry(String host,
67
                         @SuppressFBWarnings("EI_EXPOSE_REP2") String[] ips,
68
                         @SuppressFBWarnings("EI_EXPOSE_REP2") Date expiration) {
×
69
        this.host = host;
×
70
        this.ips = ips;
×
71
        this.expiration = expiration.getTime();
×
72
    }
×
73

74
    /**
75
     * Construct a {@link DnsCacheEntry}.
76
     *
77
     * @since 1.6.0
78
     */
79
    public DnsCacheEntry(String host,
80
                         @SuppressFBWarnings("EI_EXPOSE_REP2") String[] ips,
81
                         long expiration) {
1✔
82
        this.host = host;
1✔
83
        this.ips = ips;
1✔
84
        this.expiration = expiration;
1✔
85
    }
1✔
86

87
    /**
88
     * {@inheritDoc}
89
     */
90
    @Override
91
    public String toString() {
92
        final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
1✔
93

94
        return "DnsCacheEntry{" +
1✔
95
                "host='" + host + '\'' +
96
                ", ips=" + Arrays.toString(ips) +
1✔
97
                ", expiration=" + dateFormat.format(expiration) +
1✔
98
                '}';
99
    }
100

101
    /**
102
     * {@inheritDoc}
103
     */
104
    @Override
105
    public boolean equals(Object o) {
106
        if (this == o) return true;
1✔
107
        if (o == null || getClass() != o.getClass()) return false;
1✔
108

109
        DnsCacheEntry that = (DnsCacheEntry) o;
1✔
110

111
        if (expiration != that.expiration) return false;
1✔
112
        if (!Objects.equals(host, that.host)) return false;
1✔
113
        return Arrays.equals(ips, that.ips);
1✔
114
    }
115

116
    /**
117
     * {@inheritDoc}
118
     */
119
    @Override
120
    public int hashCode() {
121
        int result = host != null ? host.hashCode() : 0;
×
122
        result = 31 * result + Arrays.hashCode(ips);
×
123
        result = 31 * result + (int) (expiration ^ (expiration >>> 32));
×
124
        return result;
×
125
    }
126
}
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