Skip to content

Commit 52aa4cf

Browse files
committed
Simplify collection declarations.
1 parent e967941 commit 52aa4cf

File tree

14 files changed

+97
-79
lines changed

14 files changed

+97
-79
lines changed

httprpc-client/src/main/java/org/httprpc/WebServiceProxy.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private static class TypedInvocationHandler implements InvocationHandler {
111111
Class<?> type;
112112
BiFunction<String, URL, WebServiceProxy> factory;
113113

114-
HashMap<Object, Object> keys;
114+
Map<Object, Object> keys;
115115

116116
TypedInvocationHandler(URL baseURL, Class<?> type, BiFunction<String, URL, WebServiceProxy> factory) {
117117
this.baseURL = baseURL;
@@ -179,7 +179,7 @@ public Object invoke(Object proxy, Method method, Object[] arguments) throws Thr
179179

180180
Parameter[] parameters = method.getParameters();
181181

182-
HashMap<String, Object> argumentMap = new HashMap<>();
182+
Map<String, Object> argumentMap = new HashMap<>();
183183

184184
for (int i = 0; i < parameters.length; i++) {
185185
Parameter parameter = parameters[i];
@@ -552,7 +552,7 @@ public void encodeRequest(OutputStream outputStream) throws IOException {
552552
T result;
553553
if (responseCode / 100 == 2) {
554554
if (responseCode % 100 < 4 && responseHandler != null) {
555-
HashMap<String, String> headers = new HashMap<>();
555+
Map<String, String> headers = new HashMap<>();
556556

557557
for (Map.Entry<String, List<String>> entry : connection.getHeaderFields().entrySet()) {
558558
String key = entry.getKey();

httprpc-client/src/main/java/org/httprpc/beans/BeanAdapter.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ public class BeanAdapter extends AbstractMap<String, Object> {
4545
// Iterable adapter
4646
private static class IterableAdapter extends AbstractList<Object> {
4747
Iterable<?> iterable;
48-
HashMap<Class<?>, TreeMap<String, Method>> accessorCache;
48+
Map<Class<?>, Map<String, Method>> accessorCache;
4949

50-
IterableAdapter(Iterable<?> iterable, HashMap<Class<?>, TreeMap<String, Method>> accessorCache) {
50+
IterableAdapter(Iterable<?> iterable, Map<Class<?>, Map<String, Method>> accessorCache) {
5151
this.iterable = iterable;
5252
this.accessorCache = accessorCache;
5353
}
@@ -91,9 +91,9 @@ public Object next() {
9191
// Map adapter
9292
private static class MapAdapter extends AbstractMap<Object, Object> {
9393
Map<?, ?> map;
94-
HashMap<Class<?>, TreeMap<String, Method>> accessorCache;
94+
Map<Class<?>, Map<String, Method>> accessorCache;
9595

96-
MapAdapter(Map<?, ?> map, HashMap<Class<?>, TreeMap<String, Method>> accessorCache) {
96+
MapAdapter(Map<?, ?> map, Map<Class<?>, Map<String, Method>> accessorCache) {
9797
this.map = map;
9898
this.accessorCache = accessorCache;
9999
}
@@ -196,9 +196,9 @@ public String toString() {
196196
}
197197

198198
private Object bean;
199-
private HashMap<Class<?>, TreeMap<String, Method>> accessorCache;
199+
private Map<Class<?>, Map<String, Method>> accessorCache;
200200

201-
private TreeMap<String, Method> accessors;
201+
private Map<String, Method> accessors;
202202

203203
private static final String GET_PREFIX = "get";
204204
private static final String IS_PREFIX = "is";
@@ -213,7 +213,7 @@ public BeanAdapter(Object bean) {
213213
this(bean, new HashMap<>());
214214
}
215215

216-
private BeanAdapter(Object bean, HashMap<Class<?>, TreeMap<String, Method>> accessorCache) {
216+
private BeanAdapter(Object bean, Map<Class<?>, Map<String, Method>> accessorCache) {
217217
if (bean == null) {
218218
throw new IllegalArgumentException();
219219
}
@@ -377,7 +377,7 @@ public static <T> T adapt(Object value) {
377377
return (T)adapt(value, new HashMap<>());
378378
}
379379

380-
private static Object adapt(Object value, HashMap<Class<?>, TreeMap<String, Method>> accessorCache) {
380+
private static Object adapt(Object value, Map<Class<?>, Map<String, Method>> accessorCache) {
381381
if (value == null
382382
|| value instanceof CharSequence
383383
|| value instanceof Number
@@ -710,8 +710,8 @@ public V setValue(V value) {
710710
* @return
711711
* The accessors defined by the given type.
712712
*/
713-
public static TreeMap<String, Method> getAccessors(Class<?> type) {
714-
TreeMap<String, Method> accessors = new TreeMap<>();
713+
public static Map<String, Method> getAccessors(Class<?> type) {
714+
Map<String, Method> accessors = new TreeMap<>();
715715

716716
Method[] methods = type.getMethods();
717717

httprpc-client/src/main/java/org/httprpc/io/CSVDecoder.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.ArrayList;
2222
import java.util.Iterator;
2323
import java.util.LinkedHashMap;
24+
import java.util.List;
2425
import java.util.Map;
2526
import java.util.NoSuchElementException;
2627
import java.util.stream.Stream;
@@ -40,8 +41,8 @@ public static class Cursor implements Iterable<Map<String, String>> {
4041

4142
private StringBuilder valueBuilder = new StringBuilder();
4243

43-
private ArrayList<String> keys = new ArrayList<>();
44-
private ArrayList<String> values = new ArrayList<>();
44+
private List<String> keys = new ArrayList<>();
45+
private List<String> values = new ArrayList<>();
4546

4647
private Iterator<Map<String, String>> iterator = new Iterator<Map<String, String>>() {
4748
private Boolean hasNext = null;
@@ -69,7 +70,7 @@ public Map<String, String> next() {
6970
throw new NoSuchElementException();
7071
}
7172

72-
LinkedHashMap<String, String> row = new LinkedHashMap<>();
73+
Map<String, String> row = new LinkedHashMap<>();
7374

7475
for (int i = 0, n = Math.min(keys.size(), values.size()); i < n; i++) {
7576
String key = keys.get(i);
@@ -102,7 +103,7 @@ private Cursor(Reader reader, char delimiter) throws IOException {
102103
readValues(reader, keys, delimiter);
103104
}
104105

105-
private void readValues(Reader reader, ArrayList<String> values, char delimiter) throws IOException {
106+
private void readValues(Reader reader, List<String> values, char delimiter) throws IOException {
106107
int c = reader.read();
107108

108109
while (c != '\r' && c != '\n' && c != EOF) {

httprpc-client/src/main/java/org/httprpc/io/JSONDecoder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.io.Reader;
1919
import java.nio.charset.StandardCharsets;
2020
import java.util.ArrayList;
21+
import java.util.Deque;
2122
import java.util.LinkedHashMap;
2223
import java.util.LinkedList;
2324
import java.util.List;
@@ -32,7 +33,7 @@ public class JSONDecoder extends Decoder {
3233

3334
private int c = EOF;
3435

35-
private LinkedList<Object> collections = new LinkedList<>();
36+
private Deque<Object> collections = new LinkedList<>();
3637

3738
private StringBuilder valueBuilder = new StringBuilder();
3839

httprpc-client/src/main/java/org/httprpc/io/PagedReader.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
import java.io.IOException;
1818
import java.io.Reader;
1919
import java.util.ArrayList;
20+
import java.util.Deque;
2021
import java.util.LinkedList;
22+
import java.util.List;
2123

2224
class PagedReader extends Reader {
2325
private Reader reader;
@@ -28,8 +30,8 @@ class PagedReader extends Reader {
2830

2931
private boolean endOfFile = false;
3032

31-
private ArrayList<char[]> pages = new ArrayList<>();
32-
private LinkedList<Integer> marks = new LinkedList<>();
33+
private List<char[]> pages = new ArrayList<>();
34+
private Deque<Integer> marks = new LinkedList<>();
3335

3436
private static int DEFAULT_PAGE_SIZE = 1024;
3537
private static int EOF = -1;

httprpc-client/src/main/java/org/httprpc/io/TemplateEncoder.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.AbstractMap;
3636
import java.util.Collections;
3737
import java.util.Date;
38+
import java.util.Deque;
3839
import java.util.HashMap;
3940
import java.util.Iterator;
4041
import java.util.LinkedList;
@@ -401,14 +402,14 @@ public Set<Entry<Object, Object>> entrySet() {
401402

402403
private URL url;
403404
private Charset charset;
404-
private HashMap<String, Modifier> modifiers;
405+
private Map<String, Modifier> modifiers;
405406
private Modifier defaultEscapeModifier;
406407

407-
private LinkedList<Map<?, ?>> dictionaries = new LinkedList<>();
408+
private Deque<Map<?, ?>> dictionaries = new LinkedList<>();
408409

409-
private LinkedList<String> sectionNames = new LinkedList<>();
410+
private Deque<String> sectionNames = new LinkedList<>();
410411

411-
private static HashMap<String, Modifier> defaultModifiers = new HashMap<>();
412+
private static Map<String, Modifier> defaultModifiers = new HashMap<>();
412413

413414
private static final int EOF = -1;
414415

@@ -656,8 +657,8 @@ private void writeRoot(Object root, Writer writer, Locale locale, TimeZone timeZ
656657

657658
String marker = markerBuilder.toString();
658659

659-
LinkedList<String> modifierNames = new LinkedList<>();
660-
HashMap<String, String> modifierArguments = new HashMap<>();
660+
Deque<String> modifierNames = new LinkedList<>();
661+
Map<String, String> modifierArguments = new HashMap<>();
661662

662663
if (c == ':') {
663664
StringBuilder modifierNameBuilder = new StringBuilder();

httprpc-client/src/main/java/org/httprpc/sql/Parameters.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.StringReader;
2020
import java.sql.PreparedStatement;
2121
import java.sql.SQLException;
22+
import java.util.Deque;
2223
import java.util.LinkedList;
2324
import java.util.Map;
2425

@@ -27,11 +28,11 @@
2728
*/
2829
public class Parameters {
2930
private String sql;
30-
private LinkedList<String> keys;
31+
private Deque<String> keys;
3132

3233
private static final int EOF = -1;
3334

34-
private Parameters(String sql, LinkedList<String> keys) {
35+
private Parameters(String sql, Deque<String> keys) {
3536
this.sql = sql;
3637
this.keys = keys;
3738
}
@@ -107,7 +108,7 @@ public static Parameters parse(Reader sqlReader) throws IOException {
107108
throw new IllegalArgumentException();
108109
}
109110

110-
LinkedList<String> keys = new LinkedList<>();
111+
Deque<String> keys = new LinkedList<>();
111112

112113
StringBuilder sqlBuilder = new StringBuilder();
113114

httprpc-client/src/main/java/org/httprpc/sql/QueryBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.httprpc.sql;
1616

1717
import java.util.ArrayList;
18+
import java.util.List;
1819
import java.util.Map;
1920

2021
/**
@@ -248,7 +249,7 @@ public static QueryBuilder insertInto(String table, Map<String, ?> values) {
248249
sqlBuilder.append(table);
249250
sqlBuilder.append(" (");
250251

251-
ArrayList<String> columns = new ArrayList<>(values.keySet());
252+
List<String> columns = new ArrayList<>(values.keySet());
252253

253254
int n = columns.size();
254255

httprpc-client/src/main/java/org/httprpc/sql/ResultSetAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public Map<String, Object> next() {
5252
throw new NoSuchElementException();
5353
}
5454

55-
LinkedHashMap<String, Object> row = new LinkedHashMap<>();
55+
Map<String, Object> row = new LinkedHashMap<>();
5656

5757
try {
5858
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();

httprpc-client/src/main/java/org/httprpc/util/Collections.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static <E> List<E> listOf(E... elements) {
6161
*/
6262
@SafeVarargs
6363
public static <K, V> Map<K, V> mapOf(Map.Entry<K, V>... entries) {
64-
LinkedHashMap<K, V> map = new LinkedHashMap<>();
64+
Map<K, V> map = new LinkedHashMap<>();
6565

6666
for (Map.Entry<K, V> entry : entries) {
6767
map.put(entry.getKey(), entry.getValue());

0 commit comments

Comments
 (0)