@@ -569,10 +569,9 @@ interface CloseableResource {
569
569
*
570
570
* @param key the key; never {@code null}
571
571
* @param requiredType the required type of the value; never {@code null}
572
- * @param defaultValue the default value
572
+ * @param defaultValue the default value; never {@code null}
573
573
* @param <V> the value type
574
- * @return the value; potentially {@code null} if {@code defaultValue}
575
- * is {@code null}
574
+ * @return the value; never {@code null}
576
575
* @since 5.5
577
576
* @see #get(Object, Class)
578
577
*/
@@ -592,13 +591,13 @@ default <V> V getOrDefault(Object key, Class<V> requiredType, V defaultValue) {
592
591
* the type of object we wish to retrieve from the store.
593
592
*
594
593
* <pre style="code">
595
- * X x = store.getOrComputeIfAbsent (X.class, key -> new X(), X.class);
594
+ * X x = store.computeIfAbsent (X.class, key -> new X(), X.class);
596
595
* // Equivalent to:
597
- * // X x = store.getOrComputeIfAbsent (X.class);
596
+ * // X x = store.computeIfAbsent (X.class);
598
597
* </pre>
599
598
*
600
- * <p>See {@link #getOrComputeIfAbsent (Object, Function, Class)} for
601
- * further details.
599
+ * <p>See {@link #computeIfAbsent (Object, Function, Class)} for further
600
+ * details.
602
601
*
603
602
* <p>If {@code type} implements {@link CloseableResource} or
604
603
* {@link AutoCloseable} (unless the
@@ -610,14 +609,56 @@ default <V> V getOrDefault(Object key, Class<V> requiredType, V defaultValue) {
610
609
* @param <V> the key and value type
611
610
* @return the object; never {@code null}
612
611
* @since 5.1
613
- * @see #getOrComputeIfAbsent(Object, Function)
614
- * @see #getOrComputeIfAbsent(Object, Function, Class)
612
+ * @see #computeIfAbsent(Class)
613
+ * @see #computeIfAbsent(Object, Function)
614
+ * @see #computeIfAbsent(Object, Function, Class)
615
615
* @see CloseableResource
616
616
* @see AutoCloseable
617
+ *
618
+ * @deprecated Please use {@link #computeIfAbsent(Class)} instead.
617
619
*/
618
- @ API (status = STABLE , since = "5.1" )
619
- default <V > @ Nullable V getOrComputeIfAbsent (Class <V > type ) {
620
- return getOrComputeIfAbsent (type , ReflectionSupport ::newInstance , type );
620
+ @ Deprecated
621
+ @ API (status = DEPRECATED , since = "6.0" )
622
+ default <V > V getOrComputeIfAbsent (Class <V > type ) {
623
+ return computeIfAbsent (type );
624
+ }
625
+
626
+ /**
627
+ * Return the object of type {@code type} if it is present and not
628
+ * {@code null} in this {@code Store} (<em>keyed</em> by {@code type});
629
+ * otherwise, invoke the default constructor for {@code type} to
630
+ * generate the object, store it, and return it.
631
+ *
632
+ * <p>This method is a shortcut for the following, where {@code X} is
633
+ * the type of object we wish to retrieve from the store.
634
+ *
635
+ * <pre style="code">
636
+ * X x = store.computeIfAbsent(X.class, key -> new X(), X.class);
637
+ * // Equivalent to:
638
+ * // X x = store.computeIfAbsent(X.class);
639
+ * </pre>
640
+ *
641
+ * <p>See {@link #computeIfAbsent(Object, Function, Class)} for further
642
+ * details.
643
+ *
644
+ * <p>If {@code type} implements {@link CloseableResource} or
645
+ * {@link AutoCloseable} (unless the
646
+ * {@code junit.jupiter.extensions.store.close.autocloseable.enabled}
647
+ * configuration parameter is set to {@code false}), then the {@code close()}
648
+ * method will be invoked on the stored object when the store is closed.
649
+ *
650
+ * @param type the type of object to retrieve; never {@code null}
651
+ * @param <V> the key and value type
652
+ * @return the object; never {@code null}
653
+ * @since 6.0
654
+ * @see #computeIfAbsent(Object, Function)
655
+ * @see #computeIfAbsent(Object, Function, Class)
656
+ * @see CloseableResource
657
+ * @see AutoCloseable
658
+ */
659
+ @ API (status = MAINTAINED , since = "6.0" )
660
+ default <V > V computeIfAbsent (Class <V > type ) {
661
+ return computeIfAbsent (type , ReflectionSupport ::newInstance , type );
621
662
}
622
663
623
664
/**
@@ -631,7 +672,7 @@ default <V> V getOrDefault(Object key, Class<V> requiredType, V defaultValue) {
631
672
* the {@code key} as input), stored, and returned.
632
673
*
633
674
* <p>For greater type safety, consider using
634
- * {@link #getOrComputeIfAbsent (Object, Function, Class)} instead.
675
+ * {@link #computeIfAbsent (Object, Function, Class)} instead.
635
676
*
636
677
* <p>If the created value is an instance of {@link CloseableResource} or
637
678
* {@link AutoCloseable} (unless the
@@ -645,14 +686,56 @@ default <V> V getOrDefault(Object key, Class<V> requiredType, V defaultValue) {
645
686
* @param <K> the key type
646
687
* @param <V> the value type
647
688
* @return the value; potentially {@code null}
648
- * @see #getOrComputeIfAbsent(Class)
649
- * @see #getOrComputeIfAbsent(Object, Function, Class)
689
+ * @see #computeIfAbsent(Class)
690
+ * @see #computeIfAbsent(Object, Function)
691
+ * @see #computeIfAbsent(Object, Function, Class)
650
692
* @see CloseableResource
651
693
* @see AutoCloseable
694
+ *
695
+ * @deprecated Please use {@link #computeIfAbsent(Object, Function)}
696
+ * instead.
652
697
*/
698
+ @ Deprecated
699
+ @ API (status = DEPRECATED , since = "6.0" )
653
700
<K , V extends @ Nullable Object > @ Nullable Object getOrComputeIfAbsent (K key ,
654
701
Function <? super K , ? extends V > defaultCreator );
655
702
703
+ /**
704
+ * Return the value of the specified required type that is stored under
705
+ * the supplied {@code key}.
706
+ *
707
+ * <p>If no value is stored in the current {@link ExtensionContext}
708
+ * for the supplied {@code key}, ancestors of the context will be queried
709
+ * for a value with the same {@code key} in the {@code Namespace} used
710
+ * to create this store. If no value is found for the supplied {@code key}
711
+ * or the value is {@code null}, a new value will be computed by the
712
+ * {@code defaultCreator} (given the {@code key} as input), stored, and
713
+ * returned.
714
+ *
715
+ * <p>For greater type safety, consider using
716
+ * {@link #computeIfAbsent(Object, Function, Class)} instead.
717
+ *
718
+ * <p>If the created value is an instance of {@link CloseableResource} or
719
+ * {@link AutoCloseable} (unless the
720
+ * {@code junit.jupiter.extensions.store.close.autocloseable.enabled}
721
+ * configuration parameter is set to {@code false}), then the {@code close()}
722
+ * method will be invoked on the stored object when the store is closed.
723
+ *
724
+ * @param key the key; never {@code null}
725
+ * @param defaultCreator the function called with the supplied {@code key}
726
+ * to create a new value; never {@code null} and must not return
727
+ * {@code null}
728
+ * @param <K> the key type
729
+ * @param <V> the value type
730
+ * @return the value; never {@code null}
731
+ * @since 6.0
732
+ * @see #computeIfAbsent(Class)
733
+ * @see #computeIfAbsent(Object, Function, Class)
734
+ * @see CloseableResource
735
+ * @see AutoCloseable
736
+ */
737
+ <K , V > Object computeIfAbsent (K key , Function <? super K , ? extends V > defaultCreator );
738
+
656
739
/**
657
740
* Get the value of the specified required type that is stored under the
658
741
* supplied {@code key}.
@@ -664,7 +747,7 @@ default <V> V getOrDefault(Object key, Class<V> requiredType, V defaultValue) {
664
747
* a new value will be computed by the {@code defaultCreator} (given
665
748
* the {@code key} as input), stored, and returned.
666
749
*
667
- * <p>If {@code requiredType} implements {@link CloseableResource} or
750
+ * <p>If the created value implements {@link CloseableResource} or
668
751
* {@link AutoCloseable} (unless the
669
752
* {@code junit.jupiter.extensions.store.close.autocloseable.enabled}
670
753
* configuration parameter is set to {@code false}), then the {@code close()}
@@ -677,14 +760,50 @@ default <V> V getOrDefault(Object key, Class<V> requiredType, V defaultValue) {
677
760
* @param <K> the key type
678
761
* @param <V> the value type
679
762
* @return the value; potentially {@code null}
680
- * @see #getOrComputeIfAbsent(Class)
681
- * @see #getOrComputeIfAbsent(Object, Function)
763
+ * @see #computeIfAbsent(Class)
764
+ * @see #computeIfAbsent(Object, Function)
765
+ * @see #computeIfAbsent(Object, Function, Class)
682
766
* @see CloseableResource
683
767
* @see AutoCloseable
684
768
*/
769
+ @ Deprecated
770
+ @ API (status = DEPRECATED , since = "6.0" )
685
771
<K , V extends @ Nullable Object > @ Nullable V getOrComputeIfAbsent (K key ,
686
772
Function <? super K , ? extends V > defaultCreator , Class <V > requiredType );
687
773
774
+ /**
775
+ * Get the value of the specified required type that is stored under the
776
+ * supplied {@code key}.
777
+ *
778
+ * <p>If no value is stored in the current {@link ExtensionContext}
779
+ * for the supplied {@code key}, ancestors of the context will be queried
780
+ * for a value with the same {@code key} in the {@code Namespace} used
781
+ * to create this store. If no value is found for the supplied {@code key}
782
+ * or the value is {@code null}, a new value will be computed by the
783
+ * {@code defaultCreator} (given the {@code key} as input), stored, and
784
+ * returned.
785
+ *
786
+ * <p>If the created value is an instance of {@link CloseableResource} or
787
+ * {@link AutoCloseable} (unless the
788
+ * {@code junit.jupiter.extensions.store.close.autocloseable.enabled}
789
+ * configuration parameter is set to {@code false}), then the {@code close()}
790
+ * method will be invoked on the stored object when the store is closed.
791
+ *
792
+ * @param key the key; never {@code null}
793
+ * @param defaultCreator the function called with the supplied {@code key}
794
+ * to create a new value; never {@code null} and must not return
795
+ * {@code null}
796
+ * @param requiredType the required type of the value; never {@code null}
797
+ * @param <K> the key type
798
+ * @param <V> the value type
799
+ * @return the value; never {@code null}
800
+ * @see #computeIfAbsent(Class)
801
+ * @see #computeIfAbsent(Object, Function)
802
+ * @see CloseableResource
803
+ * @see AutoCloseable
804
+ */
805
+ <K , V > V computeIfAbsent (K key , Function <? super K , ? extends V > defaultCreator , Class <V > requiredType );
806
+
688
807
/**
689
808
* Store a {@code value} for later retrieval under the supplied {@code key}.
690
809
*
0 commit comments