Skip to content

Commit

Permalink
[#10776] Improve the EnumGetter.
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoo-jung committed Aug 20, 2024
1 parent 3ddc8da commit a93115f
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public E fromValueWithFallBack(
String value,
E defaultEnum
) {
E ele = fromValue(getter, value);
E ele = fromValueIgnoreCase(getter, value);
if (ele == null) {
return defaultEnum;
}
return ele;
}

public E fromValue(
public E fromValueIgnoreCase(
Function<E, String> getter,
String value
) {
Expand All @@ -56,12 +56,12 @@ public E fromValue(
return null;
}

public E fromCode(
Function<E, Integer> getter,
Integer code
public <V> E fromValue(
Function<E, V> getter,
V value
) {
for (E ele : set) {
if (getter.apply(ele).equals(code)) {
if (getter.apply(ele).equals(value)) {
return ele;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public PinotColumns getColumn() {
}

public static FilterByColumn fromValue(String column) {
return GETTER.fromValue((FilterByColumn x) -> x.getColumn().getName(), column);
return GETTER.fromValueIgnoreCase((FilterByColumn x) -> x.getColumn().getName(), column);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public String[] getGroupByColumns() {
}

public static GroupByAttributes fromValue(String name) {
return GETTER.fromValue(GroupByAttributes::getName, name);
return GETTER.fromValueIgnoreCase(GroupByAttributes::getName, name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import com.navercorp.pinpoint.common.server.util.EnumGetter;
import com.navercorp.pinpoint.exceptiontrace.common.pinot.PinotColumns;

import java.util.EnumSet;

/**
* @author intr3p1d
*/
Expand Down Expand Up @@ -48,6 +46,6 @@ public String getName() {
}

public static OrderByAttributes fromValue(String name) {
return GETTER.fromValue(OrderByAttributes::getName, name);
return GETTER.fromValueIgnoreCase(OrderByAttributes::getName, name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public String getAggregationFunctionName() {


public static AggregationFunction fromAggregationFunctionName(String functionName) {
return GETTER.fromValue(AggregationFunction::getAggregationFunctionName, functionName);
return GETTER.fromValueIgnoreCase(AggregationFunction::getAggregationFunctionName, functionName);
}

public static AggregationFunction fromCode(int code) {
return GETTER.fromCode(AggregationFunction::getCode, code);
return GETTER.fromValue(AggregationFunction::getCode, code);
}

public static List<String> getAggregationFunctionNameList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public String getChartName() {


public static ChartType fromChartName(String chartName) {
return GETTER.fromValue(ChartType::getChartName, chartName);
return GETTER.fromValueIgnoreCase(ChartType::getChartName, chartName);
}

public static List<String> getChartNameList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.navercorp.pinpoint.metric.web.util.TimePrecision;

import java.security.InvalidParameterException;
import java.util.EnumSet;
import java.util.concurrent.TimeUnit;

public class UriStatSummaryQueryParameter extends QueryParameter {
Expand Down Expand Up @@ -89,7 +88,7 @@ public String getName() {
}

public static OrderBy fromValue(String name) {
return GETTER.fromValue(OrderBy::getName, name);
return GETTER.fromValueIgnoreCase(OrderBy::getName, name);
}

@Override
Expand Down

0 comments on commit a93115f

Please sign in to comment.