Skip to content
Closed
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 @@ -195,11 +195,9 @@ public static AbstractPredictor getCustomPredictor(DJLEndpoint endpoint) {
return new CustomNlpPredictor<Classifications>(endpoint);
} else if (WORD_EMBEDDING.getPath().equals(applicationPath)) {
return new CustomWordEmbeddingPredictor(endpoint);
} else if (TEXT_GENERATION.getPath().equals(applicationPath)) {
return new CustomNlpPredictor<String>(endpoint);
} else if (MACHINE_TRANSLATION.getPath().equals(applicationPath)) {
return new CustomNlpPredictor<String>(endpoint);
} else if (MULTIPLE_CHOICE.getPath().equals(applicationPath)) {
} else if (TEXT_GENERATION.getPath().equals(applicationPath)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is better.

|| MACHINE_TRANSLATION.getPath().equals(applicationPath)
|| MULTIPLE_CHOICE.getPath().equals(applicationPath)) {
return new CustomNlpPredictor<String>(endpoint);
} else if (TEXT_EMBEDDING.getPath().equals(applicationPath)) {
return new CustomNlpPredictor<NDArray>(endpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ public static JsonStructure parse(final String jsonString) {
if ('"' == c && (curToken.isEmpty() || curToken.charAt(curToken.length() - 1) != '\\')) {
inWord = !inWord;
}
if (!inWord && !doNotIncludeSymbols.contains(String.valueOf(c))) {
curToken.append(c);
} else if ('"' != c || (!curToken.isEmpty() && curToken.charAt(curToken.length() - 1) == '\\')) {
if ((!inWord && !doNotIncludeSymbols.contains(String.valueOf(c)))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it look better? I'm not convinced on this one ..

|| ('"' != c || (!curToken.isEmpty() && curToken.charAt(curToken.length() - 1) == '\\'))) {
curToken.append(c);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1096,11 +1096,7 @@ private static void removeAllSetterOrGetterMethods(List<MethodInfo> methods) {
Iterator<MethodInfo> it = methods.iterator();
while (it.hasNext()) {
MethodInfo info = it.next();
if (isGetter(info.getMethod())) {
// skip getters
it.remove();
} else if (isSetter(info.getMethod())) {
// skip setters
if (isGetter(info.getMethod()) || isSetter(info.getMethod())) {
it.remove();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,8 @@ void filterMethod(Method proposedMethod) {

boolean registeredMethodIsPublic = Modifier.isPublic(alreadyRegistered.getDeclaringClass().getModifiers());

if (overridden && !registeredMethodIsPublic) {
// Retain the overridden method from a public class
methods.set(i, proposedMethod);
return;
} else if (overridding) {
// Retain the override from a public class
if ((overridden && !registeredMethodIsPublic) || overridding) {
// Retain the overridden/overriding method from a public class
methods.set(i, proposedMethod);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,15 +494,12 @@ private void generateFixedLengthPositionMap(Class<?> clazz, Object obj, Map<Inte
padChar = padCharField;
}

if (align.contains("R")) {
if (align.contains("R") || align.contains("B")) {
temp.append(generatePaddingChars(padChar, fieldLength, result.length()));
temp.append(result);
} else if (align.contains("L")) {
temp.append(result);
temp.append(generatePaddingChars(padChar, fieldLength, result.length()));
} else if (align.contains("B")) {
temp.append(generatePaddingChars(padChar, fieldLength, result.length()));
temp.append(result);
} else {
throw new IllegalArgumentException(
"Alignment for the field: " + field.getName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ private void doRemove(
List<Interceptor<? extends Message>> interceptors, Set<String> needToBeKept,
PhaseInterceptor<? extends Message> p) {
// To support the old API
if (needToBeKept == null) {
getLogger().info("removing the interceptor {}", p);
interceptors.remove(p);
} else if (!needToBeKept.contains(p.getClass().getName())) {
if (needToBeKept == null || !needToBeKept.contains(p.getClass().getName())) {
getLogger().info("removing the interceptor {}", p);
interceptors.remove(p);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ private static void writeElement(
} else {
if ("xmlns".equals(name) && attrPrefix.isEmpty()) {
writer.writeNamespace("", attr.getNodeValue());
if (attr.getNodeValue().equals(ns)) {
declareNamespace = false;
} else if (StringUtils.isEmpty(attr.getNodeValue())
&& StringUtils.isEmpty(ns)) {
if (attr.getNodeValue().equals(ns)
|| (StringUtils.isEmpty(attr.getNodeValue())
&& StringUtils.isEmpty(ns))) {
declareNamespace = false;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ private static void writeElement(
} else {
if ("xmlns".equals(name) && attrPrefix.isEmpty()) {
writer.writeNamespace("", attr.getNodeValue());
if (attr.getNodeValue().equals(ns)) {
declareNamespace = false;
} else if (StringUtils.isEmpty(attr.getNodeValue())
&& StringUtils.isEmpty(ns)) {
if (attr.getNodeValue().equals(ns)
|| (StringUtils.isEmpty(attr.getNodeValue())
&& StringUtils.isEmpty(ns))) {
declareNamespace = false;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,22 +675,13 @@ protected HttpUriRequest createMethod(Exchange exchange) throws Exception {
}

private boolean isCreateNewURL(Exchange exchange) {
boolean create = false;
Message in = exchange.getIn();
if (in.getHeader(HttpConstants.REST_HTTP_URI) != null) {
create = true;
} else if (in.getHeader(HttpConstants.HTTP_URI) != null && !getEndpoint().isBridgeEndpoint()) {
create = true;
} else if (in.getHeader(HttpConstants.HTTP_PATH) != null) {
create = true;
} else if (in.getHeader(HttpConstants.REST_HTTP_QUERY) != null) {
create = true;
} else if (in.getHeader(HttpConstants.HTTP_RAW_QUERY) != null) {
create = true;
} else if (in.getHeader(HttpConstants.HTTP_QUERY) != null) {
create = true;
}
return create;
return in.getHeader(HttpConstants.REST_HTTP_URI) != null
|| (in.getHeader(HttpConstants.HTTP_URI) != null && !getEndpoint().isBridgeEndpoint())
|| in.getHeader(HttpConstants.HTTP_PATH) != null
|| in.getHeader(HttpConstants.REST_HTTP_QUERY) != null
|| in.getHeader(HttpConstants.HTTP_RAW_QUERY) != null
|| in.getHeader(HttpConstants.HTTP_QUERY) != null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,18 @@ private ProgramParameter[] getParameterList(Exchange exchange, AS400 iSeries)
if (input) {
if (param != null) {
AS400DataType typeConverter;
if (param instanceof CharSequence) {
param = param.toString();
typeConverter = new AS400Text(length, iSeries);
} else if (param instanceof char[]) {
param = new String((char[]) param);
typeConverter = new AS400Text(length, iSeries);
} else if (param instanceof Integer) {
if (param instanceof Integer) {
typeConverter = new AS400Bin4();
} else if (param instanceof Long) {
typeConverter = new AS400Bin8();
} else if (param instanceof byte[]) {
typeConverter = new AS400ByteArray(length);
} else {
param = param.toString(); // must be a String for AS400Text class
if (param instanceof char[]) {
param = new String((char[]) param);
} else {
param = param.toString();
}
typeConverter = new AS400Text(length, iSeries);
}
inputData = typeConverter.toBytes(param);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -917,14 +917,9 @@ protected static String getAlternativeBody(MailConfiguration configuration, Exch
* Is the given key a mime message recipient header (To, CC or BCC)
*/
private static boolean isRecipientHeader(String key) {
if (Message.RecipientType.TO.toString().equalsIgnoreCase(key)) {
return true;
} else if (Message.RecipientType.CC.toString().equalsIgnoreCase(key)) {
return true;
} else if (Message.RecipientType.BCC.toString().equalsIgnoreCase(key)) {
return true;
}
return false;
return Message.RecipientType.TO.toString().equalsIgnoreCase(key)
|| Message.RecipientType.CC.toString().equalsIgnoreCase(key)
|| Message.RecipientType.BCC.toString().equalsIgnoreCase(key);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,8 @@ boolean isJavaVersionSatisfied(int requiredVersion) {
if (dot != -1) {
version = version.substring(0, dot);
}
if (version.equalsIgnoreCase("16-ea")) {
return true;
} else if (Integer.parseInt(version) >= requiredVersion) {
if (version.equalsIgnoreCase("16-ea")
|| Integer.parseInt(version) >= requiredVersion) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public class SocketOutputStreamStub extends OutputStream {

@Override
public void write(int b) throws IOException {
if (failOnWrite) {
throw new IOException("Faking write failure");
} else if (writeFailOn != null && writeFailOn == b) {
if (failOnWrite || (writeFailOn != null && writeFailOn == b)) {
throw new IOException("Faking write failure");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ private String includedUrl(String url) {
if (inclusions != null && !inclusions.isEmpty()) {
for (String constraint : inclusions.keySet()) {
if (PatternHelper.matchPattern(url, constraint)) {
if (candidate == null) {
candidate = constraint;
} else if (constraint.length() > candidate.length()) {
// we want the constraint that has the longest context-path matching as its
// the most explicit for the target url
if (candidate == null || constraint.length() > candidate.length()) {
candidate = constraint;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import io.github.resilience4j.bulkhead.Bulkhead;
import io.github.resilience4j.bulkhead.BulkheadConfig;
import io.github.resilience4j.bulkhead.BulkheadFullException;
import io.github.resilience4j.bulkhead.BulkheadRegistry;
import io.github.resilience4j.circuitbreaker.CallNotPermittedException;
import io.github.resilience4j.circuitbreaker.CircuitBreaker;
Expand Down Expand Up @@ -732,16 +731,8 @@ public Exchange apply(Throwable throwable) {
exchange.setException(throwable);
}
return exchange;
} else if (throwable instanceof BulkheadFullException) {
// the circuit breaker bulkhead is full
exchange.setProperty(ExchangePropertyKey.CIRCUIT_BREAKER_RESPONSE_SUCCESSFUL_EXECUTION, false);
exchange.setProperty(ExchangePropertyKey.CIRCUIT_BREAKER_RESPONSE_FROM_FALLBACK, false);
exchange.setProperty(ExchangePropertyKey.CIRCUIT_BREAKER_RESPONSE_SHORT_CIRCUITED, true);
exchange.setProperty(ExchangePropertyKey.CIRCUIT_BREAKER_RESPONSE_REJECTED, true);
exchange.setException(throwable);
return exchange;
} else {
// other kind of exception
// the circuit breaker bulkhead is full, or other kind of exception
exchange.setProperty(ExchangePropertyKey.CIRCUIT_BREAKER_RESPONSE_SUCCESSFUL_EXECUTION, false);
exchange.setProperty(ExchangePropertyKey.CIRCUIT_BREAKER_RESPONSE_FROM_FALLBACK, false);
exchange.setProperty(ExchangePropertyKey.CIRCUIT_BREAKER_RESPONSE_SHORT_CIRCUITED, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,13 +593,8 @@ protected boolean isInputStreamNeeded(Object payload) {
return false;
}

if (payload instanceof Source) {
return false;
} else if (payload instanceof String) {
return false;
} else if (payload instanceof byte[]) {
return false;
} else if (payload instanceof Node) {
if (payload instanceof Source || payload instanceof String
|| payload instanceof byte[] || payload instanceof Node) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ public static class MyPredicate implements Predicate {
@Override
public boolean matches(Exchange exchange) {
String body = exchange.getIn().getBody(String.class);
if (body.contains("Camel")) {
return true;
} else if (body.startsWith("Secret")) {
return true;
}

return false;
return body.contains("Camel") || body.startsWith("Secret");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,16 @@ public static boolean hasParameter(String nextParam, Exchange exchange, Object b
Map<?, ?> headersMap = safeMap(exchange.getIn().getHeaders());
Map<?, ?> variablesMap = safeMap(exchange.getVariables());

if ((nextParam.startsWith("$simple{") || nextParam.startsWith("${")) && nextParam.endsWith("}")) {
return true;
} else if (bodyMap.containsKey(nextParam)) {
return true;
} else if (headersMap.containsKey(nextParam)) {
return true;
} else if (variablesMap.containsKey(nextParam)) {
if (isSimpleExpression(nextParam)) {
return true;
}
return bodyMap.containsKey(nextParam)
|| headersMap.containsKey(nextParam)
|| variablesMap.containsKey(nextParam);
}

return false;
private static boolean isSimpleExpression(String param) {
return (param.startsWith("$simple{") || param.startsWith("${")) && param.endsWith("}");
}

private static Map<?, ?> safeMap(Map<?, ?> map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,7 @@ Consumer doCreateConsumer(
boolean explicitOptions = restrict.contains("OPTIONS");
boolean cors = config.isEnableCORS();

if (cors) {
// allow HTTP Options as we want to handle CORS in rest-dsl
map.put("optionsEnabled", "true");
} else if (explicitOptions) {
// the rest-dsl is using OPTIONS
if (cors || explicitOptions) {
map.put("optionsEnabled", "true");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Comparator;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -337,39 +338,19 @@ private static String getGroup(HealthCheck check) {
* @param key the key
* @return true if reserved, false otherwise
*/
private static final Set<String> RESERVED_KEYS = Set.of(
HealthCheck.CHECK_ID, HealthCheck.CHECK_GROUP,
HealthCheck.CHECK_KIND, HealthCheck.CHECK_ENABLED,
HealthCheck.INVOCATION_COUNT, HealthCheck.INVOCATION_TIME,
HealthCheck.FAILURE_COUNT, HealthCheck.FAILURE_START_TIME,
HealthCheck.FAILURE_TIME, HealthCheck.FAILURE_ERROR_COUNT,
HealthCheck.SUCCESS_COUNT, HealthCheck.SUCCESS_START_TIME,
HealthCheck.SUCCESS_TIME);

public static boolean isReservedKey(String key) {
if (key == null) {
return false;
}

if (HealthCheck.CHECK_ID.equals(key)) {
return true;
} else if (HealthCheck.CHECK_GROUP.equals(key)) {
return true;
} else if (HealthCheck.CHECK_KIND.equals(key)) {
return true;
} else if (HealthCheck.CHECK_ENABLED.equals(key)) {
return true;
} else if (HealthCheck.INVOCATION_COUNT.equals(key)) {
return true;
} else if (HealthCheck.INVOCATION_TIME.equals(key)) {
return true;
} else if (HealthCheck.FAILURE_COUNT.equals(key)) {
return true;
} else if (HealthCheck.FAILURE_START_TIME.equals(key)) {
return true;
} else if (HealthCheck.FAILURE_TIME.equals(key)) {
return true;
} else if (HealthCheck.FAILURE_ERROR_COUNT.equals(key)) {
return true;
} else if (HealthCheck.SUCCESS_COUNT.equals(key)) {
return true;
} else if (HealthCheck.SUCCESS_START_TIME.equals(key)) {
return true;
} else if (HealthCheck.SUCCESS_TIME.equals(key)) {
return true;
}

return false;
return RESERVED_KEYS.contains(key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,8 @@ private StreamCache doCache(Object body, Exchange exchange) {
// try convert to stream cache
if (body != null) {
// fast skip some common types that should never be converted
if (body instanceof String) {
return null;
} else if (body instanceof byte[]) {
return null;
} else if (body instanceof Boolean) {
return null;
} else if (body instanceof Number) {
if (body instanceof String || body instanceof byte[]
|| body instanceof Boolean || body instanceof Number) {
return null;
}
Class<?> type = body.getClass();
Expand Down
Loading
Loading