LinkInfo.java
5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* Decompiled with CFR 0_118.
*/
package com.day.cq.rewriter.linkchecker;
import java.util.Calendar;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
public class LinkInfo {
public static final int X_STATUS_NOT_CHECKED = 0;
public static final int X_STATUS_UNSUPPORTED = -1;
public static final int X_STATUS_URI_SYNTAX_ERROR = -2;
public static final int X_STATUS_CONNECT_ERROR = -3;
public static final int X_STATUS_NO_ROUTE_TO_HOST = -4;
public static final int X_STATUS_UNKOWN_HOST = -5;
public static final int X_STATUS_IO_ERROR = -6;
public static final int X_STATUS_SSL_ERROR = -7;
private final String url;
private Calendar lastChecked;
private Calendar lastAccessed;
private Calendar lastAvailable;
private boolean valid;
private int lastStatus;
private final Set<String> referencedBy = new HashSet<String>();
public LinkInfo(String url) {
this.url = url;
this.lastAccessed = Calendar.getInstance();
this.valid = true;
}
public LinkInfo(LinkInfo base) {
this.url = base.url;
this.lastChecked = base.lastChecked;
this.lastAccessed = base.lastAccessed;
this.lastAvailable = base.lastAvailable;
this.lastStatus = base.lastStatus;
this.valid = base.valid;
this.referencedBy.addAll(base.referencedBy);
}
public Calendar getLastAccessed() {
return this.lastAccessed;
}
public void setLastAccessed(Calendar lastAccessed) {
this.lastAccessed = lastAccessed;
}
public Calendar getLastChecked() {
return this.lastChecked;
}
public void setLastChecked(Calendar lastChecked) {
this.lastChecked = lastChecked;
}
public Calendar getLastAvailable() {
return this.lastAvailable;
}
public void setLastAvailable(Calendar lastAvailable) {
this.lastAvailable = lastAvailable;
}
public String getUrl() {
return this.url;
}
public boolean isValid() {
return this.valid;
}
public void setValid(boolean valid) {
this.valid = valid;
}
public int getLastStatus() {
return this.lastStatus;
}
public String getLastStatusAsString() {
switch (this.lastStatus) {
case -3: {
return "No Connection";
}
case -6: {
return "I/O Error";
}
case -7: {
return "SSL Error";
}
case -4: {
return "No Route to Host";
}
case 0: {
return "";
}
case -5: {
return "Unknown Host";
}
case -1: {
return "Unsupported Protocol";
}
case -2: {
return "URI Syntax Error";
}
}
return String.valueOf(this.lastStatus);
}
public void setLastStatus(int lastStatus) {
this.lastStatus = lastStatus;
}
public void addReferrer(String path) {
this.referencedBy.add(path);
}
public String[] getReferrer() {
return this.referencedBy.toArray(new String[0]);
}
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || this.getClass() != o.getClass()) {
return false;
}
LinkInfo linkInfo = (LinkInfo)o;
if (this.valid != linkInfo.valid) {
return false;
}
if (this.lastStatus != linkInfo.lastStatus) {
return false;
}
if (this.lastAccessed != null ? !this.lastAccessed.equals(linkInfo.lastAccessed) : linkInfo.lastAccessed != null) {
return false;
}
if (this.lastAvailable != null ? !this.lastAvailable.equals(linkInfo.lastAvailable) : linkInfo.lastAvailable != null) {
return false;
}
if (this.lastChecked != null ? !this.lastChecked.equals(linkInfo.lastChecked) : linkInfo.lastChecked != null) {
return false;
}
return this.url.equals(linkInfo.url);
}
public boolean isSame(LinkInfo linkInfo) {
if (this.valid != linkInfo.valid) {
return false;
}
if (this.lastStatus != linkInfo.lastStatus) {
return false;
}
if (this.lastAvailable != null ? !this.lastAvailable.equals(linkInfo.lastAvailable) : linkInfo.lastAvailable != null) {
return false;
}
if (this.lastChecked != null ? !this.lastChecked.equals(linkInfo.lastChecked) : linkInfo.lastChecked != null) {
return false;
}
if (!this.referencedBy.equals(linkInfo.referencedBy)) {
return false;
}
return this.url.equals(linkInfo.url);
}
public int hashCode() {
int result = this.url.hashCode();
result = 31 * result + (this.lastChecked != null ? this.lastChecked.hashCode() : 0);
result = 31 * result + (this.lastAccessed != null ? this.lastAccessed.hashCode() : 0);
result = 31 * result + (this.lastAvailable != null ? this.lastAvailable.hashCode() : 0);
result = 31 * result + (this.valid ? 1 : 0);
result = 31 * result + this.lastStatus;
return result;
}
}