Skip to content

Commit

Permalink
[java] Renaming enum members to match Java naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Oct 21, 2019
1 parent 3f799b8 commit e5f1248
Show file tree
Hide file tree
Showing 28 changed files with 319 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,31 @@
import java.util.Objects;

public enum AuthChallengeSource {
Server, Proxy;

public static AuthChallengeSource getAuthChallengeSourceEnum(String val) {
SERVER("Server"),
PROXY("Proxy");

private String value;

AuthChallengeSource(String value) {
this.value = value;
}

public static AuthChallengeSource fromString(String val) {
Objects.requireNonNull(val, "missing value to compare");
return Arrays.stream(AuthChallengeSource.values())
.filter(fr -> fr.name().equalsIgnoreCase(val))
.filter(fr -> fr.value.equalsIgnoreCase(val))
.findFirst()
.orElseThrow(
() -> new DevToolsException("Given value " + val + ", is not AuthChallengeSource"));
}

private static AuthChallengeSource fromJson(JsonInput input) {
String in = input.nextString();
return getAuthChallengeSourceEnum(in);
return fromString(in);
}

public String toString() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,31 @@
* display a popup dialog box.
*/
public enum FetchResponseEnum {
Default,
CancelAuth,
ProvideCredentials;
DEFAULT("Default"),
CANCELAUTH("CancelAuth"),
PROVIDECREDENTIALS("ProvideCredentials");

public static FetchResponseEnum getFetchResponseEnum(String val) {
private String value;

FetchResponseEnum(String value) {
this.value = value;
}

public static FetchResponseEnum fromString(String val) {
Objects.requireNonNull(val, "missing value to compare");
return Arrays.stream(FetchResponseEnum.values())
.filter(fr -> fr.name().equalsIgnoreCase(val))
.filter(fr -> fr.value.equalsIgnoreCase(val))
.findFirst()
.orElseThrow(
() -> new DevToolsException("Given value " + val + ", is not FetchResponseEnum"));
}

private static FetchResponseEnum fromJson(JsonInput input) {
String in = input.nextString();
return getFetchResponseEnum(in);
return fromString(in);
}

public String toString() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public RequestPattern(String urlPattern,
RequestStage requestStage) {
this.urlPattern = urlPattern;
this.resourceType = resourceType;
this.requestStage = (null == requestStage) ? RequestStage.Request : requestStage;
this.requestStage = (null == requestStage) ? RequestStage.REQUEST : requestStage;
}

private static RequestPattern fromJson(JsonInput input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,30 @@
import java.util.Objects;

public enum RequestStage {
Request,
Response;
REQUEST("Request"),
RESPONSE("Response");

public static RequestStage getRequestStageValue(String in) {
private String value;

RequestStage(String value) {
this.value = value;
}

public static RequestStage fromString(String in) {
Objects.requireNonNull(in, "missing value to compare");
return Arrays.stream(RequestStage.values())
.filter(rs -> rs.name().equalsIgnoreCase(in))
.filter(rs -> rs.value.equalsIgnoreCase(in))
.findFirst()
.orElseThrow(() -> new DevToolsException(
"Given value " + in + " is not found within RequestStage "));
}

private static RequestStage fromJson(JsonInput input) {
String in = input.nextString();
return getRequestStageValue(in);
return fromString(in);
}

public String toString() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static Command<Void> emulateNetworkConditions(boolean offline, double lat
params.put("uploadThroughput", uploadThroughput);

connectionType
.ifPresent(ConnectionType -> params.put("connectionType", connectionType.get().name()));
.ifPresent(ConnectionType -> params.put("connectionType", connectionType.get()));

return new Command<>(DOMAIN_NAME + ".emulateNetworkConditions", params.build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static AuthChallenge fromJson(JsonInput input) {
scheme = input.nextString();
break;
case "source":
source = Source.getSource(input.nextString());
source = Source.fromString(input.nextString());
break;
default:
input.skipValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,31 @@
*/
public enum BlockedReason {

other("other"),
csp("csp"),
mixedContent("mixed-content"),
origin("origin"),
inspector("inspector"),
subresourceFilter("subresource-filter"),
contentType("content-type"),
collapsedbyClient("collapsed-by-client");

private String reason;

BlockedReason(String reason) {
this.reason = reason;
}

public String getReason() {
return reason;
OTHER("other"),
CSP("csp"),
MIXED_CONTENT("mixed-content"),
ORIGIN("origin"),
INSPECTOR("inspector"),
SUBRESOURCE_FILTER("subresource-filter"),
CONTENT_TYPE("content-type"),
COLLAPSED_BY_CLIENT("collapsed-by-client");

private String value;

BlockedReason(String value) {
this.value = value;
}

public static BlockedReason fromString(String s) {
for (BlockedReason b : BlockedReason.values()) {
if (b.getReason().equalsIgnoreCase(s)) {
if (b.value.equalsIgnoreCase(s)) {
return b;
}
}
return null;
}

public String toString() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,26 @@
*/
public enum CertificateTransparencyCompliance {

Unknown("unknown"),
NotCompliant("not-compliant"),
Compliant("compliant");
UNKNOWN("unknown"),
NOT_COMPLIANT("not-compliant"),
COMPLIANT("compliant");

private String compliance;
private String value;

CertificateTransparencyCompliance(String compliance) {
this.compliance = compliance;
}

public String getCompliance() {
return compliance;
CertificateTransparencyCompliance(String value) {
this.value = value;
}

public static CertificateTransparencyCompliance fromString(String s) {
for (CertificateTransparencyCompliance ctp : CertificateTransparencyCompliance.values()) {
if (ctp.getCompliance().equalsIgnoreCase(s)) {
if (ctp.value.equalsIgnoreCase(s)) {
return ctp;
}
}
return null;
}

public String toString() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,23 @@
*/
public enum ConnectionType {

none,
cellular2g,
cellular3g,
cellular4g,
bluetooth,
ethernet,
wifi,
wimax,
other
NONE("none"),
CELLULAR2G("cellular2g"),
CELLULAR3G("cellular3g"),
CELLULAR4G("cellular4g"),
BLUETOOTH("bluetooth"),
ETHERNET("ethernet"),
WIFI("wifi"),
WIMAX("wimax"),
OTHER("other");

private String value;

ConnectionType(String value) {
this.value = value;
}

public String toString() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,28 @@
*/
public enum ErrorReason {

Failed,
Aborted,
TimedOut,
AccessDenied,
ConnectionClosed,
ConnectionReset,
ConnectionRefused,
ConnectionAborted,
ConnectionFailed,
NameNotResolved,
InternetDisconnected,
AddressUnreachable,
BlockedByClient,
BlockedByResponse
FAILED("Failed"),
ABORTED("Aborted"),
TIMEDOUT("TimedOut"),
ACCESSDENIED("AccessDenied"),
CONNECTIONCLOSED("ConnectionClosed"),
CONNECTIONRESET("ConnectionReset"),
CONNECTIONREFUSED("ConnectionRefused"),
CONNECTIONABORTED("ConnectionAborted"),
CONNECTIONFAILED("ConnectionFailed"),
NAMENOTRESOLVED("NameNotResolved"),
INTERNETDISCONNECTED("InternetDisconnected"),
ADDRESSUNREACHABLE("AddressUnreachable"),
BLOCKEDBYCLIENT("BlockedByClient"),
BLOCKEDBYRESPONSE("BlockedByResponse");

private String value;

ErrorReason(String value) {
this.value = value;
}

public String toString() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private static Initiator fromJson(JsonInput input) {
while (input.hasNext()) {
switch (input.nextName()) {
case "type":
initiatorType = InitiatorType.valueOf(input.nextString());
initiatorType = InitiatorType.fromString(input.nextString());
break;
case "stack":
stack = input.read(StackTrace.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,28 @@
/** Type of this initiator. */
public enum InitiatorType {

parser,
script,
preload,
SignedExchange,
other
PARSER("parser"),
SCRIPT("script"),
PRELOAD("preload"),
SIGNEDEXCHANGE("SignedExchange"),
OTHER("other");

private String value;

InitiatorType(String value) {
this.value = value;
}

public static InitiatorType fromString(String s) {
for (InitiatorType r : InitiatorType.values()) {
if (r.value.equalsIgnoreCase(s)) {
return r;
}
}
return null;
}

public String toString() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
* Request will intercept before the request is sent. Response will intercept after the response is received
*/
public enum InterceptionStage {
Request,
HeadersReceived

REQUEST("Request"),
HEADERSRECEIVED("HeadersReceived");

private String value;

InterceptionStage(String value) {
this.value = value;
}

public String toString() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private static LoadingFailed fromJson(JsonInput input) {
break;

case "type":
type = ResourceType.valueOf(input.nextString());
type = ResourceType.fromString(input.nextString());
break;

case "errorText":
Expand Down
Loading

0 comments on commit e5f1248

Please sign in to comment.