-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e3ab81
commit 6bd3a05
Showing
1 changed file
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import com.electronwill.nightconfig.core.AbstractCommentedConfig; | ||
import com.electronwill.nightconfig.core.Config; | ||
import com.electronwill.nightconfig.core.SimpleConfig; | ||
import com.electronwill.nightconfig.core.UnmodifiableConfig; | ||
import java.util.function.Predicate; | ||
|
||
/** | ||
* A basic commented configuration. | ||
* | ||
* @author TheElectronWill | ||
*/ | ||
public final class SimpleCommentedConfig extends AbstractCommentedConfig { | ||
|
||
private final Predicate<Class<?>> supportPredicate; | ||
|
||
/** | ||
* Creates a SimpleCommentedConfig that supports the following types: | ||
* <ul> | ||
* <li>Integer, Long, Float and Double | ||
* <li>Boolean | ||
* <li>String | ||
* <li>List and all its implementations | ||
* <li>Config and all its implementations | ||
* </ul> | ||
*/ | ||
public SimpleCommentedConfig() { | ||
this.supportPredicate = SimpleConfig.BASIC_SUPPORT_PREDICATE; | ||
} | ||
|
||
/** | ||
* Creates a SimpleCommentedConfig that uses the specified Predicate to determines what types | ||
* it supports. | ||
* | ||
* @param supportPredicate the Predicate that returns true when the class it's given is | ||
* supported by the config | ||
*/ | ||
public SimpleCommentedConfig(Predicate<Class<?>> supportPredicate) { | ||
this.supportPredicate = supportPredicate; | ||
} | ||
|
||
/** | ||
* Creates a SimpleCommentedConfig by copying a config. The supportPredicate will be | ||
* {@link SimpleConfig#BASIC_SUPPORT_PREDICATE}. | ||
* | ||
* @param toCopy the config to copy | ||
*/ | ||
public SimpleCommentedConfig(UnmodifiableConfig toCopy) { | ||
this(toCopy, SimpleConfig.BASIC_SUPPORT_PREDICATE); | ||
} | ||
|
||
/** | ||
* Creates a SimpleConfig by copying a config. | ||
* | ||
* @param toCopy the config to copy | ||
* @param supportPredicate the Predicate that returns true when the class it's given is | ||
* supported by the config | ||
*/ | ||
public SimpleCommentedConfig(UnmodifiableConfig toCopy, Predicate<Class<?>> supportPredicate) { | ||
super(toCopy); | ||
this.supportPredicate = supportPredicate; | ||
} | ||
|
||
/** | ||
* Creates a SimpleCommentedConfig by copying a config. The SimpleConfig will supports the same | ||
* types as the specified config. | ||
* | ||
* @param toCopy the config to copy | ||
*/ | ||
public SimpleCommentedConfig(Config toCopy) { | ||
this(toCopy, toCopy::supportsType); | ||
} | ||
|
||
@Override | ||
public boolean supportsType(Class<?> type) { | ||
return supportPredicate.test(type); | ||
} | ||
|
||
@Override | ||
public AbstractCommentedConfig clone() { | ||
return new SimpleCommentedConfig(this); | ||
} | ||
|
||
@Override | ||
protected AbstractCommentedConfig createSubConfig() { | ||
return new SimpleCommentedConfig(); | ||
} | ||
} |