Skip to content

Commit b4a809d

Browse files
committed
Eliminate redundant code.
1 parent 0c0959d commit b4a809d

File tree

4 files changed

+3
-74
lines changed

4 files changed

+3
-74
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![Maven Central](https://img.shields.io/maven-central/v/org.httprpc/httprpc.svg)](http://repo1.maven.org/maven2/org/httprpc/httprpc/)
33

44
# Introduction
5-
HTTP-RPC is an open-source framework for implementing RESTful and REST-like web services in Java. It is extremely lightweight and requires only a Java runtime environment and a servlet container. The entire framework is distributed as a single JAR file that is less than 85KB in size, making it an ideal choice for applications where a minimal footprint is desired.
5+
HTTP-RPC is an open-source framework for implementing RESTful and REST-like web services in Java. It is extremely lightweight and requires only a Java runtime environment and a servlet container. The entire framework is distributed as a single JAR file that is about 82KB in size, making it an ideal choice for applications where a minimal footprint is desired.
66

77
This guide introduces the HTTP-RPC framework and provides an overview of its key features.
88

@@ -14,7 +14,6 @@ This guide introduces the HTTP-RPC framework and provides an overview of its key
1414
* [Path Variables](#path-variables)
1515
* [Return Values](#return-values)
1616
* [Request and Repsonse Properties](#request-and-repsonse-properties)
17-
* [Authorization](#authorization)
1817
* [Exceptions](#exceptions)
1918
* [API Documentation](#api-documentation)
2019
* [JSONEncoder and JSONDecoder](#jsonencoder-and-jsondecoder)

httprpc/src/main/java/org/httprpc/WebService.java

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,10 @@
2727
import java.net.URL;
2828
import java.net.URLConnection;
2929
import java.net.URLStreamHandler;
30-
import java.time.LocalDate;
31-
import java.time.LocalDateTime;
32-
import java.time.LocalTime;
3330
import java.util.ArrayList;
3431
import java.util.Arrays;
3532
import java.util.Collections;
3633
import java.util.Comparator;
37-
import java.util.Date;
3834
import java.util.Enumeration;
3935
import java.util.HashMap;
4036
import java.util.LinkedList;
@@ -440,7 +436,7 @@ private static Object[] getArguments(Method method, Map<String, List<?>> paramet
440436
list = new ArrayList<>(values.size());
441437

442438
for (Object value : values) {
443-
list.add(getArgument(value, (Class<?>)elementType));
439+
list.add(BeanAdapter.adapt(value, elementType));
444440
}
445441
} else {
446442
list = Collections.emptyList();
@@ -455,7 +451,7 @@ private static Object[] getArguments(Method method, Map<String, List<?>> paramet
455451
value = null;
456452
}
457453

458-
argument = getArgument(value, type);
454+
argument = BeanAdapter.adapt(value, type);
459455
}
460456

461457
arguments[i] = argument;
@@ -464,70 +460,6 @@ private static Object[] getArguments(Method method, Map<String, List<?>> paramet
464460
return arguments;
465461
}
466462

467-
private static Object getArgument(Object value, Class<?> type) {
468-
if (type.isInstance(value)) {
469-
return value;
470-
} else if (type == Byte.TYPE || type == Byte.class) {
471-
if (value == null) {
472-
return (type == Byte.TYPE) ? Byte.valueOf((byte)0) : null;
473-
} else {
474-
return Byte.parseByte(value.toString());
475-
}
476-
} else if (type == Short.TYPE || type == Short.class) {
477-
if (value == null) {
478-
return (type == Short.TYPE) ? Short.valueOf((short)0) : null;
479-
} else {
480-
return Short.parseShort(value.toString());
481-
}
482-
} else if (type == Integer.TYPE || type == Integer.class) {
483-
if (value == null) {
484-
return (type == Integer.TYPE) ? Integer.valueOf(0) : null;
485-
} else {
486-
return Integer.parseInt(value.toString());
487-
}
488-
} else if (type == Long.TYPE || type == Long.class) {
489-
if (value == null) {
490-
return (type == Long.TYPE) ? Long.valueOf(0) : null;
491-
} else {
492-
return Long.parseLong(value.toString());
493-
}
494-
} else if (type == Float.TYPE || type == Float.class) {
495-
if (value == null) {
496-
return (type == Float.TYPE) ? Float.valueOf(0) : null;
497-
} else {
498-
return Float.parseFloat(value.toString());
499-
}
500-
} else if (type == Double.TYPE || type == Double.class) {
501-
if (value == null) {
502-
return (type == Double.TYPE) ? Double.valueOf(0) : null;
503-
} else {
504-
return Double.parseDouble(value.toString());
505-
}
506-
} else if (type == Boolean.TYPE) {
507-
if (value == null) {
508-
return Boolean.FALSE;
509-
} else {
510-
return Boolean.parseBoolean(value.toString());
511-
}
512-
} else if (value != null) {
513-
if (type == String.class) {
514-
return value.toString();
515-
} else if (type == Date.class) {
516-
return new Date(Long.parseLong(value.toString()));
517-
} else if (type == LocalDate.class) {
518-
return LocalDate.parse(value.toString());
519-
} else if (type == LocalTime.class) {
520-
return LocalTime.parse(value.toString());
521-
} else if (type == LocalDateTime.class) {
522-
return LocalDateTime.parse(value.toString());
523-
} else {
524-
throw new IllegalArgumentException();
525-
}
526-
} else {
527-
return null;
528-
}
529-
}
530-
531463
private static String getName(Parameter parameter) {
532464
RequestParameter requestParameter = parameter.getAnnotation(RequestParameter.class);
533465

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.lang.reflect.Proxy;
2121
import java.lang.reflect.Type;
2222
import java.lang.reflect.WildcardType;
23-
import java.net.MalformedURLException;
2423
import java.net.URL;
2524
import java.time.LocalDate;
2625
import java.time.LocalDateTime;

httprpc/src/test/java/org/httprpc/beans/TestInterface.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
package org.httprpc.beans;
1616

17-
import java.net.URL;
1817
import java.time.LocalDate;
1918
import java.time.LocalDateTime;
2019
import java.time.LocalTime;

0 commit comments

Comments
 (0)