Skip to content

Commit

Permalink
chore: various non-functional refactors (#1066)
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
  • Loading branch information
toddbaert authored Aug 26, 2024
1 parent ea59e7f commit 35d4cc2
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src/main/java/dev/openfeature/sdk/BooleanHook.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package dev.openfeature.sdk;

/**
* {@inheritDoc}
* An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic
* to the lifecycle of flag evaluation.
*
* @see Hook
*/
public interface BooleanHook extends Hook<Boolean> {

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/dev/openfeature/sdk/DoubleHook.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package dev.openfeature.sdk;

/**
* {@inheritDoc}
* An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic
* to the lifecycle of flag evaluation.
*
* @see Hook
*/
public interface DoubleHook extends Hook<Double> {

Expand Down
22 changes: 17 additions & 5 deletions src/main/java/dev/openfeature/sdk/ImmutableContext.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package dev.openfeature.sdk;

import lombok.ToString;
import lombok.experimental.Delegate;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import dev.openfeature.sdk.internal.ExcludeFromGeneratedCoverageReport;
import lombok.ToString;
import lombok.experimental.Delegate;

/**
* The EvaluationContext is a container for arbitrary contextual data
Expand All @@ -16,8 +17,8 @@
@SuppressWarnings("PMD.BeanMembersShouldSerialize")
public final class ImmutableContext implements EvaluationContext {

@Delegate
private final Structure structure;
@Delegate(excludes = DelegateExclusions.class)
private final ImmutableStructure structure;

/**
* Create an immutable context with an empty targeting_key and attributes provided.
Expand Down Expand Up @@ -84,4 +85,15 @@ public EvaluationContext merge(EvaluationContext overridingContext) {
return new ImmutableContext(
this.merge(ImmutableStructure::new, this.asMap(), overridingContext.asMap()));
}

@SuppressWarnings("all")
private static class DelegateExclusions {
@ExcludeFromGeneratedCoverageReport
public <T extends Structure> Map<String, Value> merge(Function<Map<String, Value>, Structure> newStructure,
Map<String, Value> base,
Map<String, Value> overriding) {

return null;
}
}
}
5 changes: 4 additions & 1 deletion src/main/java/dev/openfeature/sdk/IntegerHook.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package dev.openfeature.sdk;

/**
* {@inheritDoc}
* An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic
* to the lifecycle of flag evaluation.
*
* @see Hook
*/
public interface IntegerHook extends Hook<Integer> {

Expand Down
26 changes: 19 additions & 7 deletions src/main/java/dev/openfeature/sdk/MutableContext.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package dev.openfeature.sdk;

import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Delegate;

import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import dev.openfeature.sdk.internal.ExcludeFromGeneratedCoverageReport;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Delegate;

/**
* The EvaluationContext is a container for arbitrary contextual data
Expand All @@ -20,7 +21,8 @@
@SuppressWarnings("PMD.BeanMembersShouldSerialize")
public class MutableContext implements EvaluationContext {

@Delegate(excludes = HideDelegateAddMethods.class) private final MutableStructure structure;
@Delegate(excludes = DelegateExclusions.class)
private final MutableStructure structure;

public MutableContext() {
this(new HashMap<>());
Expand Down Expand Up @@ -124,11 +126,21 @@ public EvaluationContext merge(EvaluationContext overridingContext) {
/**
* Hidden class to tell Lombok not to copy these methods over via delegation.
*/
private static class HideDelegateAddMethods {
@SuppressWarnings("all")
private static class DelegateExclusions {

@ExcludeFromGeneratedCoverageReport
public <T extends Structure> Map<String, Value> merge(Function<Map<String, Value>, Structure> newStructure,
Map<String, Value> base,
Map<String, Value> overriding) {

return null;
}

public MutableStructure add(String ignoredKey, Boolean ignoredValue) {
return null;
}

public MutableStructure add(String ignoredKey, Double ignoredValue) {
return null;
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/dev/openfeature/sdk/OpenFeatureClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@
import lombok.extern.slf4j.Slf4j;

/**
* {@inheritDoc}
* OpenFeature Client implementation.
* You should not instantiate this or reference this class.
* Use the dev.openfeature.sdk.Client interface instead.
* @see Client
*
* @deprecated // TODO: eventually we will make this non-public. See issue #872
*/
@Slf4j
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.BeanMembersShouldSerialize",
"PMD.UnusedLocalVariable", "unchecked", "rawtypes" })
@Deprecated() // TODO: eventually we will make this non-public. See issue #872
public class OpenFeatureClient implements Client {

private final OpenFeatureAPI openfeatureApi;
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/dev/openfeature/sdk/StringHook.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package dev.openfeature.sdk;

/**
* {@inheritDoc}
* An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic
* to the lifecycle of flag evaluation.
*
* @see Hook
*/
public interface StringHook extends Hook<String> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.openfeature.sdk.internal;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.ElementType;

/**
* JaCoCo ignores coverage of methods annotated with any annotation with "generated" in the name.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ExcludeFromGeneratedCoverageReport {
}

0 comments on commit 35d4cc2

Please sign in to comment.