Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/org/adblockplus/libadblockplus/ServerResponse.java

Issue 5697499218051072: Usage of new API, cleanups (reduced) (Closed)
Patch Set: Even more review issues fixed. Created April 28, 2014, 10:18 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 package org.adblockplus.libadblockplus; 18 package org.adblockplus.libadblockplus;
19 19
20 import java.util.ArrayList; 20 import java.util.ArrayList;
21 import java.util.HashMap; 21 import java.util.HashMap;
22 import java.util.List; 22 import java.util.List;
23 23
24 import com.github.rjeschke.neetutils.collections.Tuple; 24 public final class ServerResponse
25
26 public class ServerResponse
27 { 25 {
28 public static enum NsStatus 26 public static enum NsStatus
29 { 27 {
30 OK(0), ERROR_FAILURE(0x80004005), ERROR_OUT_OF_MEMORY(0x8007000e), ERROR_MAL FORMED_URI(0x804b000a), ERROR_CONNECTION_REFUSED(0x804b000d), ERROR_NET_TIMEOUT( 28 OK(0), ERROR_FAILURE(0x80004005), ERROR_OUT_OF_MEMORY(0x8007000e), ERROR_MAL FORMED_URI(0x804b000a), ERROR_CONNECTION_REFUSED(0x804b000d), ERROR_NET_TIMEOUT(
31 0x804b000e), ERROR_NO_CONTENT(0x804b0011), ERROR_UNKNOWN_PROTOCOL(0x804b 0012), ERROR_NET_RESET(0x804b0014), ERROR_UNKNOWN_HOST(0x804b001e), ERROR_REDIRE CT_LOOP( 29 0x804b000e), ERROR_NO_CONTENT(0x804b0011), ERROR_UNKNOWN_PROTOCOL(0x804b 0012), ERROR_NET_RESET(0x804b0014), ERROR_UNKNOWN_HOST(0x804b001e), ERROR_REDIRE CT_LOOP(
32 0x804b001f), ERROR_UNKNOWN_PROXY_HOST(0x804b002a), ERROR_NET_INTERRU PT(0x804b0047), ERROR_UNKNOWN_PROXY_CONNECTION_REFUSED(0x804b0048), CUSTOM_ERROR _BASE( 30 0x804b001f), ERROR_UNKNOWN_PROXY_HOST(0x804b002a), ERROR_NET_INTERRUPT(0 x804b0047), ERROR_UNKNOWN_PROXY_CONNECTION_REFUSED(0x804b0048), CUSTOM_ERROR_BAS E(
33 0x80850000), ERROR_NOT_INITIALIZED(0xc1f30001); 31 0x80850000), ERROR_NOT_INITIALIZED(0xc1f30001);
34 32
35 private final long statusCode; 33 private final long statusCode;
36 private final static HashMap<Long, NsStatus> ENUM_MAP = new HashMap<Long, Se rverResponse.NsStatus>(); 34 private final static HashMap<Long, NsStatus> ENUM_MAP = new HashMap<Long, Se rverResponse.NsStatus>();
37 35
38 static 36 static
39 { 37 {
40 for (final NsStatus e : NsStatus.values()) 38 for (final NsStatus e : NsStatus.values())
41 { 39 {
42 ENUM_MAP.put(e.statusCode, e); 40 ENUM_MAP.put(e.statusCode, e);
43 } 41 }
44 } 42 }
45 43
46 private NsStatus(final long value) 44 private NsStatus(final long value)
47 { 45 {
48 statusCode = value; 46 this.statusCode = value;
49 } 47 }
50 48
51 public long getStatusCode() 49 public long getStatusCode()
52 { 50 {
53 return statusCode; 51 return this.statusCode;
54 } 52 }
55 53
56 public static NsStatus fromStatusCode(final long code) 54 public static NsStatus fromStatusCode(final long code)
57 { 55 {
58 final NsStatus status = ENUM_MAP.get(code); 56 final NsStatus status = ENUM_MAP.get(code);
59 return status != null ? status : ERROR_FAILURE; 57 return status != null ? status : ERROR_FAILURE;
60 } 58 }
61 } 59 }
62 60
63 private long status = NsStatus.OK.getStatusCode(); 61 private long status = NsStatus.OK.getStatusCode();
(...skipping 26 matching lines...) Expand all
90 public String getResponse() 88 public String getResponse()
91 { 89 {
92 return this.response; 90 return this.response;
93 } 91 }
94 92
95 public void setResponse(final String response) 93 public void setResponse(final String response)
96 { 94 {
97 this.response = response; 95 this.response = response;
98 } 96 }
99 97
100 public List<Tuple<String, String>> getResponseHeaders() 98 public List<HeaderEntry> getResponseHeaders()
101 { 99 {
102 final ArrayList<Tuple<String, String>> ret = new ArrayList<Tuple<String, Str ing>>(); 100 final ArrayList<HeaderEntry> ret = new ArrayList<HeaderEntry>();
103 101
104 if (this.headers != null) 102 if (this.headers != null)
105 { 103 {
106 for (int i = 0; i < this.headers.length; i += 2) 104 for (int i = 0; i < this.headers.length; i += 2)
107 { 105 {
108 ret.add(Tuple.of(this.headers[i], this.headers[i + 1])); 106 ret.add(HeaderEntry.of(this.headers[i], this.headers[i + 1]));
109 } 107 }
110 } 108 }
111 109
112 return ret; 110 return ret;
113 } 111 }
114 112
115 public void setReponseHeaders(final List<Tuple<String, String>> headers) 113 public void setReponseHeaders(final List<HeaderEntry> headers)
116 { 114 {
117 if (headers.isEmpty()) 115 if (headers.isEmpty())
118 { 116 {
119 this.headers = null; 117 this.headers = null;
120 } 118 }
121 else 119 else
122 { 120 {
123 this.headers = new String[headers.size() * 2]; 121 this.headers = new String[headers.size() * 2];
124 122
125 int i = 0; 123 int i = 0;
126 for (final Tuple<String, String> e : headers) 124 for (final HeaderEntry e : headers)
127 { 125 {
128 this.headers[i] = e.a; 126 this.headers[i] = e.getKey();
129 this.headers[i + 1] = e.b; 127 this.headers[i + 1] = e.getValue();
130 i += 2; 128 i += 2;
131 } 129 }
132 } 130 }
133 } 131 }
134 } 132 }
OLDNEW
« no previous file with comments | « src/org/adblockplus/libadblockplus/JsValue.java ('k') | src/org/adblockplus/libadblockplus/Subscription.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld