Skip to content

Commit 4138de6

Browse files
committed
Remove Java 8 usage to fix Android build
1 parent 47f29e1 commit 4138de6

File tree

4 files changed

+30
-28
lines changed

4 files changed

+30
-28
lines changed

src/AndroidClient/android/src/main/java/net/servicestack/client/sse/ServerEventsClient.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.io.UnsupportedEncodingException;
1919
import java.lang.reflect.Method;
2020
import java.lang.reflect.Modifier;
21-
import java.lang.reflect.Parameter;
2221
import java.net.HttpURLConnection;
2322
import java.net.URL;
2423
import java.net.URLEncoder;
@@ -221,9 +220,9 @@ public void execute(ServerEventsClient client, ServerEventMessage msg) {
221220
if ("equals".equals(mi.getName()))
222221
continue;
223222

224-
Parameter[] args = mi.getParameters();
223+
Class[] args = mi.getParameterTypes();
225224

226-
Class requestType = args[0].getType();
225+
Class requestType = args[0];
227226

228227
if (target.equals(requestType.getSimpleName())) {
229228
Object request = !Utils.isNullOrEmpty(msg.getJson())
@@ -706,7 +705,7 @@ public ServerEventUser apply(HashMap<String, String> map) {
706705
continue;
707706

708707
if (to.getMeta() == null)
709-
to.setMeta(new HashMap<>());
708+
to.setMeta(new HashMap<String,String>());
710709

711710
to.getMeta().put(entry.getKey(), entry.getValue());
712711
}

src/AndroidClient/android/src/main/java/net/servicestack/client/sse/SingletonInstanceResolver.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import java.util.concurrent.ConcurrentHashMap;
66
import java.util.concurrent.ConcurrentMap;
7-
import java.util.function.Function;
87

98
/**
109
* Created by mythz on 2/12/2017.
@@ -16,15 +15,18 @@ public class SingletonInstanceResolver implements IResolver {
1615

1716
@Override
1817
public Object TryResolve(Class cls) {
19-
return cache.computeIfAbsent(cls, new Function<Class, Object>() {
20-
@Override
21-
public Object apply(Class aClass) {
22-
try {
23-
return aClass.newInstance();
24-
} catch (Exception e) {
25-
throw new RuntimeException(e);
26-
}
18+
Object instance = cache.get(cls);
19+
20+
if (instance == null){
21+
try {
22+
Object newInstance = cls.newInstance();
23+
instance = (instance = cache.putIfAbsent(cls, newInstance)) == null
24+
? newInstance
25+
: instance;
26+
} catch (Exception e) {
27+
throw new RuntimeException(e);
2728
}
28-
});
29+
}
30+
return instance;
2931
}
3032
}

src/AndroidClient/client/src/main/java/net/servicestack/client/sse/ServerEventsClient.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.io.UnsupportedEncodingException;
1919
import java.lang.reflect.Method;
2020
import java.lang.reflect.Modifier;
21-
import java.lang.reflect.Parameter;
2221
import java.net.HttpURLConnection;
2322
import java.net.URL;
2423
import java.net.URLEncoder;
@@ -221,9 +220,9 @@ public void execute(ServerEventsClient client, ServerEventMessage msg) {
221220
if ("equals".equals(mi.getName()))
222221
continue;
223222

224-
Parameter[] args = mi.getParameters();
223+
Class[] args = mi.getParameterTypes();
225224

226-
Class requestType = args[0].getType();
225+
Class requestType = args[0];
227226

228227
if (target.equals(requestType.getSimpleName())) {
229228
Object request = !Utils.isNullOrEmpty(msg.getJson())
@@ -706,7 +705,7 @@ public ServerEventUser apply(HashMap<String, String> map) {
706705
continue;
707706

708707
if (to.getMeta() == null)
709-
to.setMeta(new HashMap<>());
708+
to.setMeta(new HashMap<String,String>());
710709

711710
to.getMeta().put(entry.getKey(), entry.getValue());
712711
}

src/AndroidClient/client/src/main/java/net/servicestack/client/sse/SingletonInstanceResolver.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import java.util.concurrent.ConcurrentHashMap;
66
import java.util.concurrent.ConcurrentMap;
7-
import java.util.function.Function;
87

98
/**
109
* Created by mythz on 2/12/2017.
@@ -16,15 +15,18 @@ public class SingletonInstanceResolver implements IResolver {
1615

1716
@Override
1817
public Object TryResolve(Class cls) {
19-
return cache.computeIfAbsent(cls, new Function<Class, Object>() {
20-
@Override
21-
public Object apply(Class aClass) {
22-
try {
23-
return aClass.newInstance();
24-
} catch (Exception e) {
25-
throw new RuntimeException(e);
26-
}
18+
Object instance = cache.get(cls);
19+
20+
if (instance == null){
21+
try {
22+
Object newInstance = cls.newInstance();
23+
instance = (instance = cache.putIfAbsent(cls, newInstance)) == null
24+
? newInstance
25+
: instance;
26+
} catch (Exception e) {
27+
throw new RuntimeException(e);
2728
}
28-
});
29+
}
30+
return instance;
2931
}
3032
}

0 commit comments

Comments
 (0)