Skip to content

Commit cdee263

Browse files
committed
Internal refactorings using generics
Use for-each loop
1 parent c3008da commit cdee263

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

src/main/java/org/apache/commons/jxpath/FunctionLibrary.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import java.util.ArrayList;
2121
import java.util.HashMap;
22-
import java.util.Iterator;
2322
import java.util.List;
2423
import java.util.Map;
2524
import java.util.Set;
@@ -30,12 +29,12 @@
3029
*/
3130
public class FunctionLibrary implements Functions {
3231

33-
private final List allFunctions = new ArrayList();
34-
private Map byNamespace;
32+
private final List<Functions> allFunctions = new ArrayList<>();
33+
private Map<String, Object> byNamespace;
3534

3635
/**
3736
* Add functions to the library
38-
*
37+
*
3938
* @param functions to add
4039
*/
4140
public void addFunctions(final Functions functions) {
@@ -47,23 +46,22 @@ public void addFunctions(final Functions functions) {
4746

4847
/**
4948
* Prepare the cache.
50-
*
49+
*
5150
* @return cache map keyed by namespace
5251
*/
53-
private synchronized Map functionCache() {
52+
private synchronized Map<String, Object> functionCache() {
5453
if (byNamespace == null) {
55-
byNamespace = new HashMap();
54+
byNamespace = new HashMap<>();
5655
final int count = allFunctions.size();
5756
for (int i = 0; i < count; i++) {
58-
final Functions funcs = (Functions) allFunctions.get(i);
57+
final Functions funcs = allFunctions.get(i);
5958
final Set<String> namespaces = funcs.getUsedNamespaces();
60-
for (final Iterator<String> it = namespaces.iterator(); it.hasNext();) {
61-
final String ns = it.next();
59+
for (final String ns : namespaces) {
6260
final Object candidates = byNamespace.get(ns);
6361
if (candidates == null) {
6462
byNamespace.put(ns, funcs);
6563
} else if (candidates instanceof Functions) {
66-
final List lst = new ArrayList();
64+
final List<Object> lst = new ArrayList<>();
6765
lst.add(candidates);
6866
lst.add(funcs);
6967
byNamespace.put(ns, lst);
@@ -77,8 +75,8 @@ private synchronized Map functionCache() {
7775
}
7876

7977
/**
80-
* Returns a Function, if any, for the specified namespace, name and parameter types.
81-
*
78+
* Gets a Function, if any, for the specified namespace, name and parameter types.
79+
*
8280
* @param namespace function namespace
8381
* @param name function name
8482
* @param parameters parameters
@@ -91,10 +89,10 @@ public Function getFunction(final String namespace, final String name, final Obj
9189
return ((Functions) candidates).getFunction(namespace, name, parameters);
9290
}
9391
if (candidates instanceof List) {
94-
final List list = (List) candidates;
92+
final List<Functions> list = (List<Functions>) candidates;
9593
final int count = list.size();
9694
for (int i = 0; i < count; i++) {
97-
final Function function = ((Functions) list.get(i)).getFunction(namespace, name, parameters);
95+
final Function function = list.get(i).getFunction(namespace, name, parameters);
9896
if (function != null) {
9997
return function;
10098
}
@@ -104,19 +102,19 @@ public Function getFunction(final String namespace, final String name, final Obj
104102
}
105103

106104
/**
107-
* Returns a set containing all namespaces used by the aggregated Functions.
108-
*
109-
* @return Set
105+
* Gets a set containing all namespaces used by the aggregated Functions.
106+
*
107+
* @return a set containing all namespaces used by the aggregated Functions.
110108
*/
111109
@Override
112110
public Set<String> getUsedNamespaces() {
113111
return functionCache().keySet();
114112
}
115113

116114
/**
117-
* Remove functions from the library.
118-
*
119-
* @param functions to remove
115+
* Removes functions from the library.
116+
*
117+
* @param functions to remove.
120118
*/
121119
public void removeFunctions(final Functions functions) {
122120
allFunctions.remove(functions);

0 commit comments

Comments
 (0)