Skip to content

Commit f6313fa

Browse files
committed
Fix checkstyle issues (mostly adding javadoc)
1 parent f8bb31b commit f6313fa

15 files changed

+210
-89
lines changed

src/main/java/dev/openfeature/javasdk/Client.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public interface Client extends Features {
2222

2323
/**
2424
* Adds hooks for evaluation.
25-
*
2625
* Hooks are run in the order they're added in the before stage. They are run in reverse order for all other stages.
2726
*
2827
* @param hooks The hook to add.

src/main/java/dev/openfeature/javasdk/EvaluationContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ public EvaluationContext addDatetimeAttribute(String key, ZonedDateTime value) {
101101
return this;
102102
}
103103

104+
/**
105+
* Fetch date-time relevant key.
106+
* @param key feature key
107+
* @return date time object.
108+
* @throws java.time.format.DateTimeParseException if it's not a datetime
109+
*/
104110
public ZonedDateTime getDatetimeAttribute(String key) {
105111
String attr = getAttributeByType(key, FlagValueType.STRING);
106112
if (attr == null) {

src/main/java/dev/openfeature/javasdk/FeatureProvider.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,18 @@ default List<Hook> getProviderHooks() {
1414
return Lists.newArrayList();
1515
}
1616

17-
ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
18-
ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
19-
ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
20-
ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
21-
<T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options);
17+
ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx,
18+
FlagEvaluationOptions options);
19+
20+
ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx,
21+
FlagEvaluationOptions options);
22+
23+
ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx,
24+
FlagEvaluationOptions options);
25+
26+
ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx,
27+
FlagEvaluationOptions options);
28+
29+
<T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext,
30+
FlagEvaluationOptions options);
2231
}

src/main/java/dev/openfeature/javasdk/Features.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,67 @@
66
public interface Features {
77

88
Boolean getBooleanValue(String key, Boolean defaultValue);
9+
910
Boolean getBooleanValue(String key, Boolean defaultValue, EvaluationContext ctx);
11+
1012
Boolean getBooleanValue(String key, Boolean defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
1113

1214
FlagEvaluationDetails<Boolean> getBooleanDetails(String key, Boolean defaultValue);
15+
1316
FlagEvaluationDetails<Boolean> getBooleanDetails(String key, Boolean defaultValue, EvaluationContext ctx);
14-
FlagEvaluationDetails<Boolean> getBooleanDetails(String key, Boolean defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
17+
18+
FlagEvaluationDetails<Boolean> getBooleanDetails(String key, Boolean defaultValue, EvaluationContext ctx,
19+
FlagEvaluationOptions options);
1520

1621
String getStringValue(String key, String defaultValue);
22+
1723
String getStringValue(String key, String defaultValue, EvaluationContext ctx);
24+
1825
String getStringValue(String key, String defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
1926

2027
FlagEvaluationDetails<String> getStringDetails(String key, String defaultValue);
28+
2129
FlagEvaluationDetails<String> getStringDetails(String key, String defaultValue, EvaluationContext ctx);
22-
FlagEvaluationDetails<String> getStringDetails(String key, String defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
30+
31+
FlagEvaluationDetails<String> getStringDetails(String key, String defaultValue, EvaluationContext ctx,
32+
FlagEvaluationOptions options);
2333

2434
Integer getIntegerValue(String key, Integer defaultValue);
35+
2536
Integer getIntegerValue(String key, Integer defaultValue, EvaluationContext ctx);
37+
2638
Integer getIntegerValue(String key, Integer defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
2739

2840
FlagEvaluationDetails<Integer> getIntegerDetails(String key, Integer defaultValue);
41+
2942
FlagEvaluationDetails<Integer> getIntegerDetails(String key, Integer defaultValue, EvaluationContext ctx);
30-
FlagEvaluationDetails<Integer> getIntegerDetails(String key, Integer defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
43+
44+
FlagEvaluationDetails<Integer> getIntegerDetails(String key, Integer defaultValue, EvaluationContext ctx,
45+
FlagEvaluationOptions options);
3146

3247
Double getDoubleValue(String key, Double defaultValue);
48+
3349
Double getDoubleValue(String key, Double defaultValue, EvaluationContext ctx);
50+
3451
Double getDoubleValue(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
3552

3653
FlagEvaluationDetails<Double> getDoubleDetails(String key, Double defaultValue);
54+
3755
FlagEvaluationDetails<Double> getDoubleDetails(String key, Double defaultValue, EvaluationContext ctx);
38-
FlagEvaluationDetails<Double> getDoubleDetails(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
3956

57+
FlagEvaluationDetails<Double> getDoubleDetails(String key, Double defaultValue, EvaluationContext ctx,
58+
FlagEvaluationOptions options);
4059

4160
<T> T getObjectValue(String key, T defaultValue);
61+
4262
<T> T getObjectValue(String key, T defaultValue, EvaluationContext ctx);
63+
4364
<T> T getObjectValue(String key, T defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
4465

4566
<T> FlagEvaluationDetails<T> getObjectDetails(String key, T defaultValue);
67+
4668
<T> FlagEvaluationDetails<T> getObjectDetails(String key, T defaultValue, EvaluationContext ctx);
47-
<T> FlagEvaluationDetails<T> getObjectDetails(String key, T defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
4869

70+
<T> FlagEvaluationDetails<T> getObjectDetails(String key, T defaultValue, EvaluationContext ctx,
71+
FlagEvaluationOptions options);
4972
}

src/main/java/dev/openfeature/javasdk/FlagEvaluationDetails.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ public class FlagEvaluationDetails<T> implements BaseEvaluation<T> {
1717
private Reason reason;
1818
@Nullable private String errorCode;
1919

20+
/**
21+
* Generate detail payload from the provider response.
22+
* @param providerEval provider response
23+
* @param flagKey key for the flag being evaluated
24+
* @param <T> type of flag being returned
25+
* @return detail payload
26+
*/
2027
public static <T> FlagEvaluationDetails<T> from(ProviderEvaluation<T> providerEval, String flagKey) {
2128
return FlagEvaluationDetails.<T>builder()
2229
.flagKey(flagKey)

src/main/java/dev/openfeature/javasdk/Hook.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.openfeature.javasdk;
22

3-
import java.util.*;
3+
import java.util.Map;
4+
import java.util.Optional;
45

56
/**
67
* An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic
@@ -14,7 +15,8 @@ public interface Hook<T> {
1415
*
1516
* @param ctx Information about the particular flag evaluation
1617
* @param hints An immutable mapping of data for users to communicate to the hooks.
17-
* @return An optional {@link EvaluationContext}. If returned, it will be merged with the EvaluationContext instances from other hooks, the client and API.
18+
* @return An optional {@link EvaluationContext}. If returned, it will be merged with the EvaluationContext
19+
* instances from other hooks, the client and API.
1820
*/
1921
default Optional<EvaluationContext> before(HookContext<T> ctx, Map<String, Object> hints) {
2022
return Optional.empty();

src/main/java/dev/openfeature/javasdk/HookContext.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,19 @@ public class HookContext<T> {
1919
Metadata clientMetadata;
2020
Metadata providerMetadata;
2121

22-
public static <T> HookContext<T> from(String key, FlagValueType type, Metadata clientMetadata, Metadata providerMetadata, EvaluationContext ctx, T defaultValue) {
22+
/**
23+
* Builds a {@link HookContext} instances from request data.
24+
* @param key feature flag key
25+
* @param type flag value type
26+
* @param clientMetadata info on which client is calling
27+
* @param providerMetadata info on the provider
28+
* @param ctx Evaluation Context for the request
29+
* @param defaultValue Fallback value
30+
* @param <T> type that the flag is evaluating against
31+
* @return resulting context for hook
32+
*/
33+
public static <T> HookContext<T> from(String key, FlagValueType type, Metadata clientMetadata,
34+
Metadata providerMetadata, EvaluationContext ctx, T defaultValue) {
2335
return HookContext.<T>builder()
2436
.flagKey(key)
2537
.type(type)
Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,55 @@
11
package dev.openfeature.javasdk;
22

3-
import java.util.*;
4-
import java.util.function.*;
5-
import java.util.stream.Stream;
6-
73
import com.google.common.collect.Lists;
84
import lombok.RequiredArgsConstructor;
95
import lombok.extern.slf4j.Slf4j;
106

7+
import java.util.List;
8+
import java.util.Map;
9+
import java.util.Objects;
10+
import java.util.Optional;
11+
import java.util.function.Consumer;
12+
import java.util.stream.Stream;
13+
1114
@Slf4j
1215
@RequiredArgsConstructor
1316
@SuppressWarnings({"unchecked", "rawtypes"})
1417
class HookSupport {
1518

16-
public void errorHooks(FlagValueType flagValueType, HookContext hookCtx, Exception e, List<Hook> hooks, Map<String, Object> hints) {
19+
public void errorHooks(FlagValueType flagValueType, HookContext hookCtx, Exception e, List<Hook> hooks,
20+
Map<String, Object> hints) {
1721
executeHooks(flagValueType, hooks, "error", hook -> hook.error(hookCtx, e, hints));
1822
}
1923

20-
public void afterAllHooks(FlagValueType flagValueType, HookContext hookCtx, List<Hook> hooks, Map<String, Object> hints) {
24+
public void afterAllHooks(FlagValueType flagValueType, HookContext hookCtx, List<Hook> hooks,
25+
Map<String, Object> hints) {
2126
executeHooks(flagValueType, hooks, "finally", hook -> hook.finallyAfter(hookCtx, hints));
2227
}
2328

24-
public void afterHooks(FlagValueType flagValueType, HookContext hookContext, FlagEvaluationDetails details, List<Hook> hooks, Map<String, Object> hints) {
29+
public void afterHooks(FlagValueType flagValueType, HookContext hookContext, FlagEvaluationDetails details,
30+
List<Hook> hooks, Map<String, Object> hints) {
2531
executeHooksUnchecked(flagValueType, hooks, hook -> hook.after(hookContext, details, hints));
2632
}
2733

2834
private <T> void executeHooks(
29-
FlagValueType flagValueType, List<Hook> hooks,
30-
String hookMethod,
31-
Consumer<Hook<T>> hookCode
35+
FlagValueType flagValueType, List<Hook> hooks,
36+
String hookMethod,
37+
Consumer<Hook<T>> hookCode
3238
) {
3339
hooks
34-
.stream()
35-
.filter(hook -> hook.supportsFlagValueType(flagValueType))
36-
.forEach(hook -> executeChecked(hook, hookCode, hookMethod));
40+
.stream()
41+
.filter(hook -> hook.supportsFlagValueType(flagValueType))
42+
.forEach(hook -> executeChecked(hook, hookCode, hookMethod));
3743
}
3844

3945
private <T> void executeHooksUnchecked(
40-
FlagValueType flagValueType, List<Hook> hooks,
41-
Consumer<Hook<T>> hookCode
46+
FlagValueType flagValueType, List<Hook> hooks,
47+
Consumer<Hook<T>> hookCode
4248
) {
4349
hooks
44-
.stream()
45-
.filter(hook -> hook.supportsFlagValueType(flagValueType))
46-
.forEach(hookCode::accept);
50+
.stream()
51+
.filter(hook -> hook.supportsFlagValueType(flagValueType))
52+
.forEach(hookCode::accept);
4753
}
4854

4955
private <T> void executeChecked(Hook<T> hook, Consumer<Hook<T>> hookCode, String hookMethod) {
@@ -54,28 +60,31 @@ private <T> void executeChecked(Hook<T> hook, Consumer<Hook<T>> hookCode, String
5460
}
5561
}
5662

57-
public EvaluationContext beforeHooks(FlagValueType flagValueType, HookContext hookCtx, List<Hook> hooks, Map<String, Object> hints) {
63+
public EvaluationContext beforeHooks(FlagValueType flagValueType, HookContext hookCtx, List<Hook> hooks,
64+
Map<String, Object> hints) {
5865
Stream<EvaluationContext> result = callBeforeHooks(flagValueType, hookCtx, hooks, hints);
5966
return EvaluationContext.merge(hookCtx.getCtx(), collectContexts(result));
6067
}
6168

62-
private Stream<EvaluationContext> callBeforeHooks(FlagValueType flagValueType, HookContext hookCtx, List<Hook> hooks, Map<String, Object> hints) {
69+
private Stream<EvaluationContext> callBeforeHooks(FlagValueType flagValueType, HookContext hookCtx,
70+
List<Hook> hooks, Map<String, Object> hints) {
6371
// These traverse backwards from normal.
6472
return Lists
65-
.reverse(hooks)
66-
.stream()
67-
.filter(hook -> hook.supportsFlagValueType(flagValueType))
68-
.map(hook -> hook.before(hookCtx, hints))
69-
.filter(Objects::nonNull)
70-
.filter(Optional::isPresent)
71-
.map(Optional::get)
72-
.map(EvaluationContext.class::cast);
73+
.reverse(hooks)
74+
.stream()
75+
.filter(hook -> hook.supportsFlagValueType(flagValueType))
76+
.map(hook -> hook.before(hookCtx, hints))
77+
.filter(Objects::nonNull)
78+
.filter(Optional::isPresent)
79+
.map(Optional::get)
80+
.map(EvaluationContext.class::cast);
7381
}
7482

75-
//for whatever reason, an error `error: incompatible types: invalid method reference` is thrown on compilation with javac
83+
//for whatever reason, an error `error: incompatible types: invalid method reference` is thrown on compilation
84+
// with javac
7685
//when the reduce call is appended directly as stream call chain above. moving it to its own method works however...
7786
private EvaluationContext collectContexts(Stream<EvaluationContext> result) {
7887
return result
79-
.reduce(new EvaluationContext(), EvaluationContext::merge, EvaluationContext::merge);
88+
.reduce(new EvaluationContext(), EvaluationContext::merge, EvaluationContext::merge);
8089
}
8190
}

src/main/java/dev/openfeature/javasdk/Metadata.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dev.openfeature.javasdk;
22

33
/**
4-
* Holds identifying information about a given entity
4+
* Holds identifying information about a given entity.
55
*/
66
public interface Metadata {
77
String getName();

src/main/java/dev/openfeature/javasdk/NoOpProvider.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class NoOpProvider implements FeatureProvider {
99
public static final String PASSED_IN_DEFAULT = "Passed in default";
1010
@Getter
1111
private final String name = "No-op Provider";
12+
1213
@Override
1314
public Metadata getMetadata() {
1415
return new Metadata() {
@@ -20,7 +21,8 @@ public String getName() {
2021
}
2122

2223
@Override
23-
public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
24+
public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx,
25+
FlagEvaluationOptions options) {
2426
return ProviderEvaluation.<Boolean>builder()
2527
.value(defaultValue)
2628
.variant(PASSED_IN_DEFAULT)
@@ -29,7 +31,8 @@ public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defa
2931
}
3032

3133
@Override
32-
public ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
34+
public ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx,
35+
FlagEvaluationOptions options) {
3336
return ProviderEvaluation.<String>builder()
3437
.value(defaultValue)
3538
.variant(PASSED_IN_DEFAULT)
@@ -38,23 +41,29 @@ public ProviderEvaluation<String> getStringEvaluation(String key, String default
3841
}
3942

4043
@Override
41-
public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
44+
public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx,
45+
FlagEvaluationOptions options) {
4246
return ProviderEvaluation.<Integer>builder()
4347
.value(defaultValue)
4448
.variant(PASSED_IN_DEFAULT)
4549
.reason(Reason.DEFAULT)
4650
.build();
4751
}
52+
4853
@Override
49-
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
54+
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx,
55+
FlagEvaluationOptions options) {
5056
return ProviderEvaluation.<Double>builder()
5157
.value(defaultValue)
5258
.variant(PASSED_IN_DEFAULT)
5359
.reason(Reason.DEFAULT)
5460
.build();
5561
}
62+
5663
@Override
57-
public <T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options) {
64+
public <T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue,
65+
EvaluationContext invocationContext,
66+
FlagEvaluationOptions options) {
5867
return ProviderEvaluation.<T>builder()
5968
.value(defaultValue)
6069
.variant(PASSED_IN_DEFAULT)

0 commit comments

Comments
 (0)