switch case refactoring
Signed-off-by: chandresh pancholi <chandresh.pancholi@navi.com>
This commit is contained in:
@@ -33,27 +33,17 @@ public class FlexibleRolloutStrategy implements Strategy {
|
||||
}
|
||||
|
||||
private Optional<String> resolveStickiness(String stickiness, LitmusContext context) {
|
||||
switch (stickiness) {
|
||||
case "userId":
|
||||
return context.getUserId();
|
||||
case "sessionId":
|
||||
return context.getSessionId();
|
||||
case "deviceId":
|
||||
return context.getDeviceId();
|
||||
case "appVersionCode":
|
||||
return context.getAppVersionCode();
|
||||
case "osType":
|
||||
return context.getOsType();
|
||||
case "random":
|
||||
return Optional.of(randomGenerator.get());
|
||||
case "default":
|
||||
String value =
|
||||
context.getUserId()
|
||||
.orElse(context.getSessionId().orElse(this.randomGenerator.get()));
|
||||
return Optional.of(value);
|
||||
default:
|
||||
return context.getByName(stickiness);
|
||||
}
|
||||
return switch (stickiness) {
|
||||
case "userId" -> context.getUserId();
|
||||
case "sessionId" -> context.getSessionId();
|
||||
case "deviceId" -> context.getDeviceId();
|
||||
case "appVersionCode" -> context.getAppVersionCode();
|
||||
case "osType" -> context.getOsType();
|
||||
case "random" -> Optional.of(randomGenerator.get());
|
||||
case "default" -> Optional.of(context.getUserId()
|
||||
.orElse(context.getSessionId().orElse(this.randomGenerator.get())));
|
||||
default -> context.getByName(stickiness);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,29 +18,13 @@ public final class VariantUtil {
|
||||
return (override) -> {
|
||||
Optional<String> contextValue;
|
||||
switch (override.getContextName()) {
|
||||
case "userId":
|
||||
contextValue = context.getUserId();
|
||||
break;
|
||||
case "sessionId":
|
||||
contextValue = context.getSessionId();
|
||||
break;
|
||||
case "remoteAddress":
|
||||
contextValue = context.getRemoteAddress();
|
||||
break;
|
||||
case "appVersionCode":
|
||||
contextValue = context.getAppVersionCode();
|
||||
break;
|
||||
case "osType":
|
||||
contextValue = context.getOsType();
|
||||
break;
|
||||
case "deviceId":
|
||||
contextValue = context.getDeviceId();
|
||||
break;
|
||||
default:
|
||||
contextValue =
|
||||
Optional.ofNullable(
|
||||
context.getProperties().get(override.getContextName()));
|
||||
break;
|
||||
case "userId" -> contextValue = context.getUserId();
|
||||
case "sessionId" -> contextValue = context.getSessionId();
|
||||
case "remoteAddress" -> contextValue = context.getRemoteAddress();
|
||||
case "appVersionCode" -> contextValue = context.getAppVersionCode();
|
||||
case "osType" -> contextValue = context.getOsType();
|
||||
case "deviceId" -> contextValue = context.getDeviceId();
|
||||
default -> contextValue = Optional.ofNullable(context.getProperties().get(override.getContextName()));
|
||||
}
|
||||
return override.getValues().contains(contextValue.orElse(""));
|
||||
};
|
||||
|
||||
@@ -34,26 +34,17 @@ public class LitmusContext {
|
||||
|
||||
|
||||
public Optional<String> getByName(String contextName) {
|
||||
switch (contextName) {
|
||||
case "environment":
|
||||
return environment;
|
||||
case "appName":
|
||||
return appName;
|
||||
case "userId":
|
||||
return userId;
|
||||
case "sessionId":
|
||||
return sessionId;
|
||||
case "remoteAddress":
|
||||
return remoteAddress;
|
||||
case "appVersionCode":
|
||||
return appVersionCode;
|
||||
case "osType":
|
||||
return osType;
|
||||
case "deviceId":
|
||||
return deviceId;
|
||||
default:
|
||||
return Optional.ofNullable(properties.get(contextName));
|
||||
}
|
||||
return switch (contextName) {
|
||||
case "environment" -> environment;
|
||||
case "appName" -> appName;
|
||||
case "userId" -> userId;
|
||||
case "sessionId" -> sessionId;
|
||||
case "remoteAddress" -> remoteAddress;
|
||||
case "appVersionCode" -> appVersionCode;
|
||||
case "osType" -> osType;
|
||||
case "deviceId" -> deviceId;
|
||||
default -> Optional.ofNullable(properties.get(contextName));
|
||||
};
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
|
||||
Reference in New Issue
Block a user