View Javadoc

1   package com.atlassian.vcache;
2   
3   import com.atlassian.annotations.Internal;
4   
5   import java.util.Optional;
6   
7   /**
8    * Contains utility methods used for settings.
9    *
10   * @since 1.0.0
11   */
12  @Internal
13  class SettingsUtils {
14      /**
15       * Returns the first {@link Optional} if it is present, otherwise returns the second {@link Optional}.
16       *
17       * @param first  the first {@link Optional} to check
18       * @param second the second {@link Optional}
19       * @param <T>    the contained type
20       * @return <tt>first</tt> if {@link Optional#isPresent()} is {@code true}, otherwise <tt>second</tt>
21       */
22      static <T> Optional<T> ifPresent(Optional<T> first, Optional<T> second) {
23          return first.isPresent() ? first : second;
24      }
25  }