Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 84bf56c

Browse files
committed
Added unset-methods to the Requirements-API. ConfigurationService ignores unset requirements now.
1 parent 796928e commit 84bf56c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/main/java/org/codeoverflow/chatoverflow/api/plugin/configuration/Requirement.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ public boolean isSet() {
7070
return value != null;
7171
}
7272

73+
/**
74+
* Unsets the requirement by inserting the value null
75+
*/
76+
void unsetValue() {
77+
value = null;
78+
}
79+
7380
/**
7481
* Returns if the requirement is optional
7582
*

src/main/java/org/codeoverflow/chatoverflow/api/plugin/configuration/Requirements.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,33 @@ private <T extends Serializable> Requirement<T> addRequirement(Map<String, Requi
6565
return requirement;
6666
}
6767

68+
/**
69+
* Returns a requirement of any type (input / output / parameter) with the given unique id.
70+
*
71+
* @param uniqueRequirementId the plugin unique requirement id
72+
* @return an optional encapsulating the requirement or none
73+
*/
6874
public Optional<? extends Requirement<? extends Serializable>> getRequirementById(String uniqueRequirementId) {
6975
return getAllEntries()
7076
.filter(entry -> entry.getKey().equals(uniqueRequirementId))
7177
.map(Map.Entry::getValue).findFirst();
7278
}
7379

80+
/**
81+
* Unsets the value of a requirement specified by the unique id.
82+
*
83+
* @param uniqueRequirementId the plugin unique requirement id
84+
* @return true, if a requirement with the given id exists
85+
*/
86+
public boolean unsetRequirementById(String uniqueRequirementId) {
87+
Optional<? extends Requirement<? extends Serializable>> requirement =
88+
getAllEntries().filter(entry -> entry.getKey().equals(uniqueRequirementId))
89+
.map(Map.Entry::getValue).findFirst();
90+
91+
requirement.ifPresent(Requirement::unsetValue);
92+
return requirement.isPresent();
93+
}
94+
7495
/**
7596
* Tests, if all non-optional requirements had been set (e.g. by the framework)
7697
*

0 commit comments

Comments
 (0)