Skip to content

Commit

Permalink
added Java doc
Browse files Browse the repository at this point in the history
Signed-off-by: Kaituo Li <[email protected]>
  • Loading branch information
kaituo committed Feb 8, 2024
1 parent 7bde55d commit d0f5754
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@

package org.apache.spark.sql.util

/**
* Trait defining an interface for fetching environment variables.
*/
trait EnvironmentProvider {
/**
* Retrieves the value of an environment variable.
*
* @param name The name of the environment variable.
* @param default The default value to return if the environment variable is not set.
* @return The value of the environment variable if it exists, otherwise the default value.
*/
def getEnvVar(name: String, default: String): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@

package org.apache.spark.sql.util

/**
* An implementation of `EnvironmentProvider` that fetches actual environment variables from the system.
*/
class RealEnvironment extends EnvironmentProvider {
/**
* Retrieves the value of an environment variable from the system or returns a default value if not present.
*
* @param name The name of the environment variable.
* @param default The default value to return if the environment variable is not set in the system.
* @return The value of the environment variable if it exists in the system, otherwise the default value.
*/
def getEnvVar(name: String, default: String): String = sys.env.getOrElse(name, default)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@

package org.apache.spark.sql.util

/**
* A mock implementation of `EnvironmentProvider` for use in tests, where environment variables can be predefined.
*
* @param inputMap A map representing the environment variables (name -> value).
*/
class MockEnvironment(inputMap: Map[String, String]) extends EnvironmentProvider {
/**
* Retrieves the value of an environment variable from the input map or returns a default value if not present.
*
* @param name The name of the environment variable.
* @param default The default value to return if the environment variable is not set in the input map.
* @return The value of the environment variable from the input map if it exists, otherwise the default value.
*/
def getEnvVar(name: String, default: String): String = inputMap.getOrElse(name, default)
}

0 comments on commit d0f5754

Please sign in to comment.