Skip to content

Commit 427ecea

Browse files
authored
improve javadoc (#4)
1 parent b8e5dfa commit 427ecea

File tree

4 files changed

+64
-7
lines changed

4 files changed

+64
-7
lines changed

src/main/java/io/github/cdimascio/dotenv/Dotenv.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,55 @@
55

66
public interface Dotenv {
77
enum EntriesFilter {
8+
/**
9+
* Filter matching only environment variables declared in the .env file
10+
*/
811
DECLARED_IN_ENV_FILE
912
}
1013

14+
/**
15+
* Configures a new {@link Dotenv} instance
16+
* @return a new {@link Dotenv} instance
17+
*/
1118
static DotenvBuilder configure() {
1219
return new DotenvBuilder();
1320
}
1421

22+
/**
23+
* Creates and loads a {@link Dotenv} instance with default options
24+
* @return a new {@link Dotenv} instance
25+
*/
1526
static Dotenv load() {
1627
return new DotenvBuilder().load();
1728
}
1829

30+
/**
31+
* Returns the set of environment variables with values
32+
* @return the set of {@link DotenvEntry}s for all environment variables
33+
*/
1934
Set<DotenvEntry> entries();
35+
36+
/**
37+
* Returns the set of {@link EntriesFilter}s matching the the filter
38+
* @param filter the filter e.g. {@link EntriesFilter}
39+
* @return the set of {@link DotenvEntry}s for environment variables matching the {@link EntriesFilter}
40+
*/
2041
Set<DotenvEntry> entries(EntriesFilter filter);
42+
43+
/**
44+
* Retrieves the value of the environment variable specified by key
45+
* @param key the environment variable
46+
* @return the value of the environment variable
47+
*/
2148
String get(String key);
49+
50+
/**
51+
* Retrieves the value of the environment variable specified by key.
52+
* If the environment variable specified by key does not exist, then
53+
* the defaut value is returned
54+
* @param key the environment variable
55+
* @param defaultValue the default value to return
56+
* @return the value of the environment variable or default value
57+
*/
2258
String get(String key, String defaultValue);
2359
}

src/main/java/io/github/cdimascio/dotenv/DotenvBuilder.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,44 @@ public class DotenvBuilder {
2020

2121
/**
2222
* Sets the directory containing the .env file
23-
* @param path The path
23+
* @param path the directory containing the .env file
24+
* @return this {@link DotenvBuilder}
2425
*/
2526
public DotenvBuilder directory(String path) {
2627
this.directoryPath = path;
2728
return this;
2829
}
2930
/**
3031
* Sets the name of the .env file. The default is .env
31-
* @param name The filename
32+
* @param name the filename
33+
* @return this {@link DotenvBuilder}
3234
*/
3335
public DotenvBuilder filename(String name) {
3436
filename = name;
3537
return this;
3638
}
3739

3840
/**
39-
* Do not throw an exception when .env is missing
41+
* Does not throw an exception when .env is missing
42+
* @return this {@link DotenvBuilder}
4043
*/
4144
public DotenvBuilder ignoreIfMissing() {
4245
throwIfMissing = false;
4346
return this;
4447
}
4548

4649
/**
47-
* Do not throw an exception when .env is malformed
50+
* Does not throw an exception when .env is malformed
51+
* @return this {@link DotenvBuilder}
4852
*/
4953
public DotenvBuilder ignoreIfMalformed() {
5054
throwIfMalformed = false;
5155
return this;
5256
}
5357

5458
/**
55-
* Adds environment variables into system properties
59+
* Sets each environment variable as system properties
60+
* @return this {@link DotenvBuilder}
5661
*/
5762
public DotenvBuilder systemProperties() {
5863
systemProperties = true;
@@ -61,8 +66,10 @@ public DotenvBuilder systemProperties() {
6166

6267
/**
6368
* Load the contents of .env into the virtual environment
69+
* @return a new {@link Dotenv} instance
70+
* @throws DotenvException when an error occurs
6471
*/
65-
public DotenvImpl load() throws DotenvException {
72+
public Dotenv load() throws DotenvException {
6673
DotenvParser reader = new DotenvParser(
6774
new DotenvReader(directoryPath, filename),
6875
throwIfMissing,
@@ -74,7 +81,7 @@ public DotenvImpl load() throws DotenvException {
7481
return new DotenvImpl(env);
7582
}
7683

77-
public static class DotenvImpl implements Dotenv {
84+
static class DotenvImpl implements Dotenv {
7885
private final Map<String, String> envVars;
7986
private final Set<DotenvEntry> set;
8087
private final Set<DotenvEntry> setInFile;

src/main/java/io/github/cdimascio/dotenv/DotenvEntry.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.github.cdimascio.dotenv;
22

3+
/**
4+
* A key value pair representing an environment variable and its value
5+
*/
36
public class DotenvEntry {
47
private final String key;
58
private final String value;
@@ -9,10 +12,18 @@ public DotenvEntry(String key, String value) {
912
this.value = value;
1013
}
1114

15+
/**
16+
* Returns the key for the {@link DotenvEntry}
17+
* @return the key for the {@link DotenvEntry}
18+
*/
1219
public String getKey() {
1320
return key;
1421
}
1522

23+
/**
24+
* Returns the value for the {@link DotenvEntry}
25+
* @return the value for the {@link DotenvEntry}
26+
*/
1627
public String getValue() {
1728
return value;
1829
}

src/main/java/io/github/cdimascio/dotenv/DotenvException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.github.cdimascio.dotenv;
22

3+
/**
4+
* A dotenv exception
5+
*/
36
public class DotenvException extends RuntimeException {
47
public DotenvException(String message) {
58
super(message);

0 commit comments

Comments
 (0)