Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In this PR, I removed some redundant code under common and adjusted some formats. #167

Merged
merged 6 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
public class BitSailException extends RuntimeException {
private static final long serialVersionUID = 1L;

private ErrorCode errorCode;
private String errorMessage;
private final ErrorCode errorCode;
private final String errorMessage;

public BitSailException(ErrorCode errorCode, String errorMessage) {
super(errorCode.toString() + " - " + errorMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,11 +857,11 @@ private boolean isPathMap(final String path) {
}

private int getIndex(final String index) {
return Integer.valueOf(index.replace("[", "").replace("]", ""));
return Integer.parseInt(index.replace("[", "").replace("]", ""));
}

private boolean isSuitForRoot(final Object object) {
return null != object && (object instanceof List || object instanceof Map);
return (object instanceof List || object instanceof Map);

}

Expand Down Expand Up @@ -916,7 +916,7 @@ private Map<String, String> flatten(Map<String, Object> in) {
}

private Map<String, String> flatten(Map.Entry<String, Object> in) {
if (!Map.class.isInstance(in.getValue())) {
if (!(in.getValue() instanceof Map)) {
return Collections.singletonMap(in.getKey(), in.getValue().toString());
}

Expand All @@ -930,6 +930,7 @@ private Map<String, String> flatten(Map.Entry<String, Object> in) {
}

private enum ConfigType {
//Basic data type enumeration
Boolean, Character, Double, Float, Integer, List, Long, Map, String
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ private static String getConfigDirectory() {
} else if (new File(RUNTIME_FILE_DIR).exists()) {
confDir = RUNTIME_FILE_DIR;
}
// else {
// throw BITSAILException.asBITSAILException(CommonErrorCode.CONFIG_ERROR, "No system configuration found.");
//
// }
return confDir;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ public static CloseableHttpResponse sendPost(String url, String jsonStr, Map<Str
}
StringEntity entity = new StringEntity(jsonStr, "UTF-8");
httpPost.setEntity(entity);
CloseableHttpResponse response = closeableHttpClient
return closeableHttpClient
.execute(httpPost);
return response;
}

public static WrappedResponse sendPost(String url, Map<String, String> headers, Map<String, Object> body, ContentType contentType) throws IOException {
Expand Down Expand Up @@ -227,8 +226,7 @@ public static WrappedResponse wrapAndClose(CloseableHttpResponse response) throw
int statusCode = response.getStatusLine().getStatusCode();
String responseString = EntityUtils.toString(response.getEntity(), "UTF-8");
EntityUtils.consume(response.getEntity());
WrappedResponse wrappedResponse = new WrappedResponse(statusCode, responseString);
return wrappedResponse;
return new WrappedResponse(statusCode, responseString);
} finally {
response.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ private static boolean equals(Object x, Object y) {
@Override
@SuppressWarnings("unchecked")
public boolean equals(Object other) {
return other instanceof Pair && equals(first, ((Pair) other).first) &&
equals(second, ((Pair) other).second);
return other instanceof Pair && equals(first, ((Pair<?, ?>) other).first) &&
equals(second, ((Pair<?, ?>) other).second);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ private static boolean declaresInterruptedEx(Method method) {
return false;
}

// TODO: replace with version in common.reflect if and when it's open-sourced
/**
*
* TODO: replace with version in common.reflect if and when it's open-sourced
*
*/
private static <T> T newProxy(
Class<T> interfaceType, InvocationHandler handler) {
Object object = Proxy.newProxyInstance(interfaceType.getClassLoader(),
Expand Down Expand Up @@ -164,7 +168,12 @@ public Object call() throws Exception {
return newProxy(interfaceType, handler);
}

// TODO: should this actually throw only ExecutionException?

/**
*
* TODO: should this actually throw only ExecutionException?
*
*/
@Override
public <T> T callWithTimeout(Callable<T> callable, long timeoutDuration,
TimeUnit timeoutUnit, boolean amInterruptible) throws Exception {
Expand Down