Skip to content

Commit bdb6343

Browse files
committed
Support getting a value or invoking a supplier if the value is not set
1 parent 3ecd857 commit bdb6343

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

api/src/main/java/org/mapstruct/tools/gem/GemValue.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.ArrayList;
99
import java.util.List;
1010
import java.util.function.Function;
11+
import java.util.function.Supplier;
1112
import javax.lang.model.element.AnnotationMirror;
1213
import javax.lang.model.element.AnnotationValue;
1314
import javax.lang.model.element.AnnotationValueVisitor;
@@ -113,6 +114,16 @@ public T getValue() {
113114
return value;
114115
}
115116

117+
/**
118+
* Returns the value set by the user, if present, otherwise invoke other and return the result of that invocation.
119+
*
120+
* @param other a Supplier whose result is returned if no value is present
121+
* @return the value set by the user, if present, otherwise the result of {@code other.get()}
122+
*/
123+
public T getValueOrElseGet(Supplier<T> other) {
124+
return value != null ? value : other.get();
125+
}
126+
116127
/**
117128
* The default value, as declared in the annotation
118129
*

0 commit comments

Comments
 (0)